How to do server-side backpressure?

163 views
Skip to first unread message

Lixin Wei

unread,
May 28, 2022, 11:54:11 AM5/28/22
to grpc.io
Hi everyone!

I just find that in C++, when using AsyncService, even if I don't request a new request, gRPC will still read data from the network. This caused a huge memory usage in my system.

Detailed Scenario:

I have a client that will send a lot of requests to the server.

On the server-side, I didn't request any requests. The server blocked in cq_->Next(&tag, &ok) but was kept consuming memory. Caused an OOM in my system.

So my question is how to prevent the server from reading data from the network when I don't request a new request? i.e. how to do server-side backpressure so I can save the memory??

Could anyone help me? thanks!

Lidi Zheng

unread,
Jun 2, 2022, 3:56:01 PM6/2/22
to grpc.io
Hi,

It helps to adopt streaming calls. gRPC C++ server will only cache 1 message and apply flow control on this stream. For an existing application, this could mean compacting multiple service methods into one.

If above is not possible, you can consider to tune channel args (https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h):

1. Limit the concurrent streams via `grpc.max_concurrent_streams`
2. Limit the per stream buffer size via `GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE
Reply all
Reply to author
Forward
0 new messages