17

I am using grpc to send some pretty large messages (the parameters of a machine learning model over the network). The problem is that I am getting the following error when I make a grpc call:

grpc: received message larger than max (261268499 vs. 4194304)

As suggested in other posts I tried to increase the max message size on the channel and the grpc server, but I keep getting the same error. Any idea on how to get this to work?

My code for the server:

maxMsgLength = 1024 * 1024 * 1024
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
                     options=[('grpc.max_message_length', maxMsgLength),
                              ('grpc.max_send_message_length', maxMsgLength),
                              ('grpc.max_receive_message_length', maxMsgLength)])

The client:

maxMsgLength = 1024 * 1024 * 1024
channel = grpc.insecure_channel(ip_port, 
                                options=[('grpc.max_message_length', maxMsgLength),
                                         ('grpc.max_send_message_length', maxMsgLength),
                                         ('grpc.max_receive_message_length', maxMsgLength)])

Edit:

Not a solution, but maybe gives a little bit more insight into the problem. For some reason, if I set the max message size to 1024 * 1024 * 1024 it ends up defaulting to 4194304 as the error message implies. Not really sure why that happens. But anyways, I tried reducing the max message size to 1024 * 1024 * 200 and it shows the correct max message size in the error message (209715200). It seems like there is a problem where grpc is not setting the max message size properly. Not sure how to get around this though.

The maximum number I can use where the error message shows the proper max value is 2^28. If I put a max message size of 2^29 it defaults to 4194304.

1
  • why instead of sending all the parameters in a single message you don't send each parameter at a time in an individual message? Commented Jun 29 at 6:05

3 Answers 3

0

You can send your data in chunk using grpc streaming API as mentioned in the below example. Although, more details are needed for better clarity of your exact requirement.

Protobuf File

syntax = "proto3";

package pb.foo_service;

service FooService {
    rpc TestRpc(TestRequest) returns (stream TestResponse) {}
}

message TestRequest {}

message TestResponse {
  bytes data = 1;
}

Servicer

class FooService(pb_grpc.FooServiceServicer):

    def TestRpc(
        self,
        request: pb.TestRequest,
        context: grpc.ServicerContext
    ) -> Iterator[pb.TestResponse]:
        with open("test_file", 'rb') as content_file:
            content = content_file.read()
    yield my_generated_module_pb2.Response(data=content)
Sign up to request clarification or add additional context in comments.

1 Comment

But the question is different. Often you are not the one who implements the server :(
0

Try to set the options on insecure_channel of client:

channel = grpc.insecure_channel(ip_port, 
                                options=[('grpc.max_message_length', -1),
                                         ('grpc.max_send_message_length', -1),
                                         ('grpc.max_receive_message_length', -1)])

It's worked for me.

2 Comments

why -1 would work?
0

according to this GitHub thread there is a 4Mb ( 33 554 432 bits ) message limit on gRPC which could be related with the limts you encounter.

I would suggest to send each parameter on an individual gRPC message which would avoid the message limit and could be easier to maintain.

Comments

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.