6

I am trying come up with better ways to deal with the 4mb message size limit in grpc. I need a way to measure the size of the grpc response received on client side. When the response exceeds 4mb limit grpc shows a error message like:

could not greet: rpc error: code = ResourceExhausted desc = grpc: received message larger than max (74000087 vs. 4194304)

with "74000087" being the actual size of the response. How is this calculated? Is there a way to get this value?

I have gone through multiple articles on this topic but could find nothing? Can someone please help? Thanks.

My implementation is using golang

2 Answers 2

6

Computing message size

As per the proto docs,

func Size(m Message) int

Size returns the size in bytes of the wire-format encoding of m.

gRPC message size limits

Also, it might be useful in your case to consider setting grpc.MaxCallRecvMsgSize as a grpc.CallOption to manage limits.

Sign up to request clarification or add additional context in comments.

Comments

3

I figured out a way to do this. The solution is to encode the gRPC response into the byte stream, and then calculate the size using binary.Size()

func GetGRPCResponseSize(val interface{}, desc string) (int, error) {

    var buff bytes.Buffer
    enc := gob.NewEncoder(&buff)
    err := enc.Encode(val)
    if err != nil {
        log.Error("encode error:", err)
        return 0, err
    }
    return binary.Size(buff.Bytes()), nil
}

2 Comments

This is not a precise answer. You are just predicting what would be the compression, by doing a gob encoding offline. There is no guarantee that this would be the size of the network payload.
Is there any Java equivalent?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.