How to increase message size in grpc using python

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


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

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