How to increase message size in grpc using python

16,643

Solution 1

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),
    ],
)

Solution 2

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)
    ])
Share:
16,643

Related videos on Youtube

Dumbo
Author by

Dumbo

Updated on September 15, 2022

Comments

  • Dumbo
    Dumbo over 1 year

    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
    Dumbo about 7 years
    maybe, but I still want to see if it is possible and what the performance penalty will be .
  • ospider
    ospider over 5 years
    There is no golden setting that fits all environments
  • ospider
    ospider over 5 years
    @duck maybe you only change the server or client? try change from both sides
  • Lei Yang
    Lei Yang almost 2 years
    is MAX_MESSAGE_LENGTH a python or grpc default value or customer defined value?