编程语言
首页 > 编程语言> > java – Spring netFlux在使用Netty与Tomcat时的不同之处

java – Spring netFlux在使用Netty与Tomcat时的不同之处

作者:互联网

我正在学习春天的webflux,我读过以下系列文章(first,second,third)

在第三条中,我面对以下案文:

Remember the same application code runs on Tomcat, Jetty or Netty.
Currently, the Tomcat and Jetty support is provided on top of Servlet
3.1 asynchronous processing, so it is limited to one request per thread. When the same code runs on the Netty server platform that
constraint is lifted, and the server can dispatch requests
sympathetically to the web client. As long as the client doesn’t
block, everyone is happy. Performance metrics for the netty server and
client probably show similar characteristics, but the Netty server is
not restricted to processing a single request per thread, so it
doesn’t use a large thread pool and we might expect to see some
differences in resource utilization. We will come back to that later
in another article in this series.

首先,我没有在系列中看到更新的文章,尽管它是在2016年编写的.很明显,tomcat默认有100个线程来处理请求,一个线程同时处理一个请求但是我没有理解短语它限于每个线程一个请求这是什么意思?

另外我想知道Netty如何为这个具体案例工作(我想了解与Tomcat的区别).它可以处理每个线程2个请求吗?

解决方法:

使用Servlet 2.5时,Servlet容器会向线程分配请求,直到该请求得到完全处理.

使用Servlet 3.0异步处理时,服务器可以在应用程序处理请求时在单独的线程池中调度请求处理.但是,当涉及到I / O时,工作总是发生在服务器线程上,并且总是阻塞.这意味着“慢客户端”可以独占服务器线程,因为在读取/写入具有较差网络连接的客户端时,服务器被阻止.

使用Servlet 3.1,允许异步I / O,在这种情况下,“一个请求/线程”模型不再存在.在任何时候,可以在由服务器管理的不同线程上调度位请求处理.

Servlet 3.1容器通过Servlet API提供所有这些可能性.应用程序可以利用异步处理或非阻塞I / O.在非阻塞I / O的情况下,范式的变化很重要,使用起来非常具有挑战性.

使用Spring WebFlux – Tomcat,Jetty和Netty没有完全相同的运行时模型,但它们都支持反应式背压和非阻塞I / O.

标签:spring-webflux,java,tomcat,nonblocking,netty
来源: https://codeday.me/bug/20190926/1820492.html