Search code examples
c++grpc-c++

Reduce background threads in gRPC Server C++


I'm using gRPC v1.55.0 and I have run the hello world async server example using completion queue and it worked well. However the problem is that, only creating the server without make any request, 19 threads were created in background.

I have tried using grpc::ResourceQuota::SetMaxThreads and grpc::ServerBuilder::SetSyncServerOption, but nothing changed. ¿Is there any way of reduce this number of threads in background?


Solution

  • You are right, and it cannot be tuned very well at the moment. gRPC core/C++/Python are undergoing a transition of the low-level I/O and async execution implementations. You are likely seeing 16 "event_engine" threads, 2 executors, and a timer thread. In the very near future, we expect to have ~8 event_engine threads, and in the slightly more distant future, no executor threads. These are, however, implementation details that will continue to change.

    For what it's worth, gRPC is primarily tuned for performance, and the default thread count may change to better serve that goal. Now that there is a public EventEngine API to customize low-level async behavior, users can provide solutions that better fit their needs (e.g, different performance vs resource utilization tradeoffs).