Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase message size in grpc using python

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?

like image 744
Dumbo Avatar asked Mar 06 '17 15:03

Dumbo


People also ask

Is Python gRPC multithreaded?

gRPC Python wraps gRPC core, which uses multithreading for performance, and hence doesn't support fork() .

What is pb2 in gRPC?

The 2 in pb2 indicates that the generated code is following Protocol Buffers Python API version 2.

How big is gRPC?

gRPC uses per-message size limits to manage incoming and outgoing messages. By default, gRPC limits incoming messages to 4 MB. There is no limit on outgoing messages.

What is the maximum RPC message size gRPC will accept?

Problem statement: By default gRPC will accept RPC message up to four megabytes in size. If you need to send anything bigger, you will need to tweak some settings. There are two options which can be adjusted when creating a new server. This changes both the max incoming and outgoing message size to 1 gigabyte:

How do I work with gRPC in Python?

This tutorial provides a basic Python programmer’s introduction to working with gRPC. By walking through this example you’ll learn how to: Define a service in a .proto file. Generate server and client code using the protocol buffer compiler. Use the Python gRPC API to write a simple client and server for your service.

How to start a gRPC server from the client?

In the gRPC server file, there is a GetServerResponse () method which takes a stream of `Message` from the client and returns a stream of `Message` independent of each other. server () function is called from the main function and makes sure that the server is listening to all the time. We will run the bidirectional_server to start the server:

What can you do with gRPC?

With gRPC we can define our service once in a. proto file and generate clients and servers in any of gRPC’s supported languages, which in turn can be run in environments ranging from servers inside a large data center to your own tablet-all the complexity of communication between different languages and environments is handled for you by gRPC.


1 Answers

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),
    ],
)
like image 73
Dumbo Avatar answered Sep 30 '22 03:09

Dumbo