How to increase message size in grpc using python
Asked Answered
T

4

27

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?

Tameka answered 6/3, 2017 at 15:10 Comment(0)
T
40

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),
    ],
)
Tameka answered 7/3, 2017 at 18:19 Comment(2)
@duck maybe you only change the server or client? try change from both sidesDorindadorine
is MAX_MESSAGE_LENGTH a python or grpc default value or customer defined value?Transubstantiate
O
17

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)
    ])
Outdate answered 25/11, 2020 at 17:2 Comment(0)
C
3

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

Closing answered 11/2, 2022 at 10:7 Comment(0)
G
-7

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

Goldbrick answered 6/3, 2017 at 16:9 Comment(2)
maybe, but I still want to see if it is possible and what the performance penalty will be .Tameka
There is no golden setting that fits all environmentsDorindadorine

© 2022 - 2024 — McMap. All rights reserved.