Tomcat - maxThreads 与 maxConnections [英] Tomcat - maxThreads vs maxConnections
问题描述
在 Tomcat server.xml
中什么是 maxThreads
与 maxConnections
In Tomcat server.xml
what is maxThreads
versus maxConnections
我知道 maxConnections
是打开到服务器的连接数
I understand that maxConnections
is the number of connections open to the server
而maxThreads
为最大请求处理线程数
And maxThreads
is the maximum number of request processing threads
但是这两个配置参数如何协同工作,显然你不会将maxConnections
设置为1000和maxThreads
设置为10
But how the two configuration parameters working together, obviously you will not set maxConnections
to 1000 and maxThreads
to 10
这两个配置参数是什么关系?
What is the relationship between the two configuration parameters?
<Connector
port="8443"
protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="250"
SSLEnabled="true"
scheme="https" secure="true"
clientAuth="false"
sslProtocol="TLS"
connectiontimeout="20000"
/>
推荐答案
Tomcat可以工作在2种模式:
Tomcat can work in 2 modes:
- BIO – 阻塞 I/O(每个连接一个线程)
- NIO – 非阻塞 I/O(连接比线程多得多)
- BIO – blocking I/O (one thread per connection)
- NIO – non-blocking I/O (many more connections than threads)
Tomcat 7 是 默认为 BIO,尽管共识似乎是不要使用 Bio,因为 Nio 在各方面都更好".您可以使用 protocol
参数 在 server.xml
文件中.
Tomcat 7 is BIO by default, although consensus seems to be "don't use Bio because Nio is better in every way". You set this using the protocol
parameter in the server.xml
file.
- BIO 将是
HTTP/1.1
或org.apache.coyote.http11.Http11Protocol
- NIO 将是
org.apache.coyote.http11.Http11NioProtocol
如果您使用的是 BIO,那么我相信它们应该或多或少相同.
If you're using BIO then I believe they should be more or less the same.
如果您使用的是 NIO,那么实际上maxConnections=1000"和maxThreads=10"甚至可能是合理的.默认值为 maxConnections=10,000 和 maxThreads=200.使用 NIO,每个线程可以为任意数量的连接提供服务,来回切换但保留连接,因此您不需要进行所有通常的握手,这对于 HTTPS 特别耗时,但对于 HTTP 甚至是一个问题.您可以调整keepAlive"参数以保持连接更长时间,这应该会加快一切速度.
If you're using NIO then actually "maxConnections=1000" and "maxThreads=10" might even be reasonable. The defaults are maxConnections=10,000 and maxThreads=200. With NIO, each thread can serve any number of connections, switching back and forth but retaining the connection so you don't need to do all the usual handshaking which is especially time-consuming with HTTPS but even an issue with HTTP. You can adjust the "keepAlive" parameter to keep connections around for longer and this should speed everything up.
这篇关于Tomcat - maxThreads 与 maxConnections的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!