Tomcat 8 NIO,它是如何工作的? [英] Tomcat 8 NIO,how it works?

查看:62
本文介绍了Tomcat 8 NIO,它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了简单的 Spring Boot MVC 应用程序并注意到(使用 JVisualVM)我的所有线程都有前缀 nio.这意味着 Tomcat 使用 java.nio 包.我们可以将以下参数添加到 Tomcat 配置中:maxThreads,maxConnections.据我所知,这意味着:例如我们有 maxThreads = 2 ,maxConnections = 10000,那么第一个线程的 Selector(来自 java.nio)可以处理 10000 并发请求,但根据 selectorKeys 和第二个线程的相同行为顺序执行每个请求.

I have created simple Spring Boot MVC application and noticed (using JVisualVM) that all my threads have prefix nio. That mean that Tomcat use java.nio package. We can add the following params to Tomcat configuration : maxThreads,maxConnections. As I know that mean: For example we have maxThreads = 2 , maxConnections = 10000, then Selector of first thread (from java.nio) can handle 10000 concurrent requests, but execute each sequentially according to selectorKeys and the same behavior for the second thread.

是否以这种方式工作,如果是,您通常如何为 maxConnections

Does it work in this way , if yes how do you usually choose the best option for maxConnections

提前致谢

(顺便说一句,我使用 Tomcat 8)

(BTW I use Tomcat 8 )

推荐答案

最大客户端连接数为 acceptCount + maxConnections.太低,请求可能会被不必要地拒绝.太高,如果吞吐量跟不上,客户端可能会饿死.

The maximum number of client connections is acceptCount + maxConnections. Too low and requests may be rejected unnecessarily. Too high and clients may be starved if throughput can't keep up.

acceptCount: - 默认为 100 - 这用作 ServerSocket.bind.操作系统的 TCP 堆栈最多将排队 acceptCount 挂起的套接字连接.这发生在 Tomcat 开始处理连接之前.

acceptCount: - 100 by default - This is used as the backlog parameter for ServerSocket.bind. The OS's TCP stack will queue at most acceptCount pending socket connections. This occurs before Tomcat starts processing the connection.

maxConnections: - 默认为 10,000 - Tomcat 允许在内部进行的最大连接数.

maxConnections: - 10,000 by default - The maximum number of connections that Tomcat allows to be in progress internally.

maxThreads: - 在 NIO 和 NIO2 下默认为 200 - 最大并发请求处理线程数.

maxThreads: - 200 by default under NIO and NIO2 - Maximum number of concurrent request processing threads.

目标是优化服务可用性和性能并有效利用资源.这些设置将取决于您的请求处理器的延迟和负载分布.

The goal is to optimize service availability and performance and utilize resources efficiently. The settings will depend on the latency and load distribution of your request processors.

根据目标,有许多不同的容量规划方法.一个简单的选择是将 maxThreads 增加到服务器无法在合理的时间内安全处理任何额外请求的程度.在这个饱和点,接受更多连接是不可取的,因为清除它们需要很长时间.因此,请考虑每个处理线程需要多少 CPU 时间和 RAM,以及可以同时安全运行的线程数.

There are many different approaches to capacity planning depending on the goals. A simple option is to increase maxThreads to the point where the server wouldn't be able to safely process any additional requests within a reasonable period of time. At this point of saturation, accepting more connections would be inadvisable since it would take too long to clear them out. So consider how much CPU time and RAM each processing thread requires and how many can safely run at the same time.

这篇关于Tomcat 8 NIO,它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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