Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does gRPC server spin up a new thread for each request?

I tried profiling a gRPC java server. And i see the below set of thread pools majorly.

  • grpc-default-executor Threads : Created 1 for each incoming request.
  • grpc-default-worker-ELG Threads: May be to listen on the incoming gRPC requests & assign to the above "grpc-default-executor" thread.

Overall, is gRPC java server, Netty style or Jetty/Tomcat style? Or it can configured to run as both ways?

like image 326
Venkata Naresh Avatar asked Nov 27 '17 06:11

Venkata Naresh


People also ask

Is gRPC server multi threaded?

Multiple gRPC clients can be created from a channel, including different types of clients. A channel and clients created from the channel can safely be used by multiple threads. Clients created from the channel can make multiple simultaneous calls.

Is gRPC single threaded?

The gRPC C++ core (wrapped by APIs in C++, Python, etc) does not use dedicated threads for the network communication needs of RPCs; these are borrowed from applications or wrapped language implementations when they call into the library.

Are gRPC stubs thread safe?

grpc. Channel is marked with @ThreadSafe annotation. Stubs are also thread-safe, which is why reconfiguration creates a new stub.

Can gRPC server call client?

No, a server cannot invoke calls on the client. gRPC works with HTTP, and HTTP has not had such semantics in the past.


1 Answers

gRPC Java server is exposed closer to Jetty/Tomcat style, except that it is asynchronous. That is, in normal Servlets each request consumes a thread until it is complete. While newer Servlet versions let you detach from the dedicated thread and continue work asynchronously (freeing the thread for other use) that is more uncommon. In gRPC you are free to work in either style. Note that gRPC uses a cachedThreadPool by default to reuse threads; on server-side it's a good idea to replace the default executor with your own, generally fixed-size, pool via ServerBuilder.executor().

Internally gRPC Java uses the Netty-style. That means fully non-blocking. You may use ServerBuilder.directExecutor() to run on the Netty threads. Although in that case you may want to specify the NettyServerBuilder.bossEventLoopGroup(), workerEventLoopGroup(), and for compatibility channelType().

like image 76
Eric Anderson Avatar answered Oct 17 '22 21:10

Eric Anderson