gRPC服务器是否为每个请求启动一个新线程? [英] Does gRPC server spin up a new thread for each request?

查看:1815
本文介绍了gRPC服务器是否为每个请求启动一个新线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试对gRPC Java服务器进行性能分析.而且我主要看到以下线程池集.

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

  • grpc-default-executor线程:为每个传入请求创建1个.
  • grpc-default-worker-ELG线程:可能是侦听传入的gRPC请求&分配给上述"grpc-default-executor"线程.

总体而言,gRPC是Java服务器,Netty样式还是Jetty/Tomcat样式?还是可以配置为同时运行?

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

推荐答案

gRPC Java服务器暴露于Jetty/Tomcat风格,但它是异步的.也就是说,在普通的Servlet中,每个请求都会消耗一个线程,直到完成为止.虽然较新的Servlet版本使您可以从专用线程中分离出来,然后继续异步工作(释放线程以供其他使用),这种情况并不常见.在gRPC中,您可以自由使用任何一种样式.请注意,默认情况下,gRPC使用cachedThreadPool重用线程.在服务器端,最好通过ServerBuilder.executor()用您自己的(通常为固定大小的)池替换默认执行程序.

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().

内部,gRPC Java使用Netty样式.这意味着完全不阻塞.您可以使用ServerBuilder.directExecutor()在Netty线程上运行.尽管在这种情况下,您可能需要指定NettyServerBuilder.bossEventLoopGroup()workerEventLoopGroup()和兼容性channelType().

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().

这篇关于gRPC服务器是否为每个请求启动一个新线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆