26

I am using grpc for message passing and am testing a simple server and client. When my message size goes over the limit, I get this error.

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with 
(StatusCode.INVALID_ARGUMENT,
 Received message larger than max (7309898 vs. 4194304))>

How do I increase the message size on the server and client side?

Dumbo
  • 1,068
  • 2
  • 12
  • 21

4 Answers4

38

Changing the message_length for both send and receive will do the trick.

channel = grpc.insecure_channel(
    'localhost:50051',
    options=[
        ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
        ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
    ],
)
jso
  • 484
  • 5
  • 13
Dumbo
  • 1,068
  • 2
  • 12
  • 21
16

I had this problem, I solved it by setting the 'grpc.max_send_message_length' and 'grpc.max_receive_message_length' on both the client and the server:

In client (Credit to @Dumbo for this code snippet):

channel = grpc.insecure_channel(
    'localhost:50051',
    options=[
        ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
        ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
    ],
)

In server:

server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), options = [
        ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
        ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH)
    ])
2

Adding to the existing answers, you can find a list of all key-value pair options in the github repo - see below

From the grpc-Glossary

channel_arguments A list of key-value pairs to configure the underlying gRPC Core channel or server object. Channel arguments are meant for advanced usages and contain experimental API (some may not labeled as experimental). Full list of available channel arguments and documentation can be found under the “grpc_arg_keys” section of “grpc_types.h” header file (https://github.com/grpc/grpc/blob/v1.43.x/include/grpc/impl/codegen/grpc_types.h). For example, if you want to disable TCP port reuse, you may construct channel arguments like: options = (('grpc.so_reuseport', 0),).

enter image description here

henrikh_
  • 81
  • 5
-6

You should not increase the message size.
It comes with a performance penalty.
In real situations one implements paging to split too large messages.

weismat
  • 7,195
  • 3
  • 43
  • 58