
使用 Tomcat 时应根据服务器的负载和客户端能接受的等待情可适当的调节 maxThreads, acceptCount, maxConnections 的值。这三个参数只有 maxThreads 是最容易理解,即 Tomcat 当前最大同时处理请求的数目,其他两个参数有些模糊。而搜索网络相关的解释发现一些相互矛盾的地方,本文将通过调整这几个值,实际体验它们对请求连接的影响。
在测试之前,先看看 Tomcat 官网的解释,你可能不信 AI 的胡说八道,官网仍然是最可信的。在关于 The HTTP Connector 一章中,找到它们三者之间的说明原文是
Each incoming, non-asynchronous request requires a thread for the duration of that request. If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the
maxThreads
attribute). If still more simultaneous requests are received, Tomcat will accept new connections until the current number of connections reachesmaxConnections
. Connections are queued inside the server socket created by the Connector until a thread becomes available to process the connection. OncemaxConnections
has been reached the operating system will queue further connections. The size of the operating system provided connection queue may be controlled by theacceptCount
attribute. If the operating system queue fills, further connection requests may be refused or may time out.
用 Google 翻译后 阅读全文 >>