Tomcat的最大并发数
日常应用中,单台Tomcat能支持最大的并发数是多少?
作为一个有经验的Java Web开发人员对这个问题应该有大概的印象,并会让问题再具体点,比如Tomcat版本,运行模式,并发请求允许的最大响应时间等,然后针对其中某个点搜索答案,而不应该低效的去直接搜这个答案。并且如果你没相关知识,很容易被网上的知识误导,因为很多都是很早之前配置的答案的转载。
以现在主要用的Tomcat8为例,想要完全掌握配置,最好还是去官网去浏览锁定自己想知道的相关问题的关键词。https://tomcat.apache.org/tomcat-8.5-doc/config/http.html
从上面配置也可以看出Tomcat8在操作系统没有装arp库支持时默认工作在NIO模式,默认支持的最大并发连接数是10000。
The maximum number of connections that the server will accept and process at any given time. When this number has been reached, the server will accept, but not process, one further connection. This additional connection be blocked until the number of connections being processed falls below maxConnections at which point the server will start accepting and processing new connections again. Note that once the limit has been reached, the operating system may still accept connections based on the
acceptCount
setting. The default value varies by connector type. For NIO and NIO2 the default is10000
. For APR/native, the default is8192
.Note that for APR/native on Windows, the configured value will be reduced to the highest multiple of 1024 that is less than or equal to maxConnections. This is done for performance reasons.
If set to a value of -1, the maxConnections feature is disabled and connections are not counted.
Sets the protocol to handle incoming traffic. The default value is
HTTP/1.1
which uses an auto-switching mechanism to select either a Java NIO based connector or an APR/native based connector. If thePATH
(Windows) orLD_LIBRARY_PATH
(on most unix systems) environment variables contain the Tomcat native library, and theAprLifecycleListener
that is used to initialize APR has itsuseAprConnector
attribute set totrue
, the APR/native connector will be used. If the native library cannot be found or the attribute is not configured, the Java NIO based connector will be used. Note that the APR/native connector has different settings for HTTPS than the Java connectors.
To use an explicit protocol rather than rely on the auto-switching mechanism described above, the following values may be used:org.apache.coyote.http11.Http11NioProtocol
- non blocking Java NIO connectororg.apache.coyote.http11.Http11Nio2Protocol
- non blocking Java NIO2 connectororg.apache.coyote.http11.Http11AprProtocol
- the APR/native connector.
Custom implementations may also be used.
Take a look at our Connector Comparison chart. The configuration for both Java connectors is identical, for http and https.
For more information on the APR connector and APR specific SSL settings please visit the APR documentation
注意这个值是Tomcat默认接受的并发连接数,是TCP连接层相关的参数。Tomcat在NIO模式时有一个线程专业接受请求连接,然后将其放到任务队列,然后有工作线程从任务t队列取出请求并并发处理(工作线程数通过maxThreads值控制,Tomcat默认是200),如果每个请求处理很快比如20ms,则工作线程1s内就能处理10000个请求,否则若请求处理很慢比如要几秒,则请求队列中的连接得到处理收到响应的时间也会变慢。
maxThreads、minSpareThreads是tomcat工作线程池的配置参数,maxThreads就相当于jdk线程池的maxPoolSize,而minSpareThreads就相当于jdk线程池的corePoolSize。
acceptCount、maxConnections是tcp层相关的参数。
tomcat有一个acceptor线程来accept socket连接,然后有工作线程来进行业务处理。对于client端的一个请求进来,流程是这样的:tcp的三次握手建立连接,建立连接的过程中,OS维护了半连接队列(syn队列)以及完全连接队列(accept队列),在第三次握手之后,server收到了client的ack,则进入establish的状态,然后该连接由syn队列移动到accept队列。tomcat的acceptor线程则负责从accept队列中取出该connection,接受该connection,然后交给工作线程去处理(
读取请求参数、处理逻辑、返回响应等等;如果该连接不是keep alived的话,则关闭该连接,然后该工作线程释放回线程池,如果是keep alived的话,则等待下一个数据包的到来直到keepAliveTimeout,然后关闭该连接释放回线程池
),然后自己接着去accept队列取connection(当当前socket连接超过maxConnections的时候,acceptor线程自己会阻塞等待,等连接降下去之后,才去处理accept队列的下一个连接
)。acceptCount指的就是这个accept队列的大小。https://segmentfault.com/a/1190000008064162
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
2017-04-14 2017第15周五
2016-04-14 2016第15周四
2014-04-14 2014第16周一
2013-04-14 2013年4月14日星期日