Java Tomcat - maxThreads 与 maxConnections
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24678661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat - maxThreads vs maxConnections
提问by JavaSheriff
In Tomcat server.xml
what is maxThreads
versus maxConnections
在 Tomcat 中,server.xml
什么是maxThreads
与maxConnections
I understand that maxConnections
is the number of connections open to the server
我知道这maxConnections
是对服务器开放的连接数
And maxThreads
is the maximum number of request processing threads
并且maxThreads
是最大请求处理线程数
But how the two configuration parameters working together, obviously you will not set maxConnections
to 1000 and maxThreads
to 10
但是这两个配置参数如何协同工作,显然你不会设置maxConnections
为1000和maxThreads
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"
/>
采纳答案by Tim Cooper
Tomcat can work in 2 modes:
Tomcat 可以在两种模式下工作:
- BIO–?blocking I/O (one thread per connection)
- NIO– non-blocking I/O(many more connections than threads)
- BIO–?blocking I/O(每个连接一个线程)
- NIO–非阻塞 I/O(连接比线程多得多)
Tomcat 7is 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
parameterin the server.xml
file.
Tomcat 7默认是BIO,尽管共识似乎是“不要使用 Bio,因为 Nio 在各方面都更好”。您可以使用文件中的protocol
参数进行设置server.xml
。
- BIO will be
HTTP/1.1
ororg.apache.coyote.http11.Http11Protocol
- NIO will be
org.apache.coyote.http11.Http11NioProtocol
- 生物将是
HTTP/1.1
或org.apache.coyote.http11.Http11Protocol
- 蔚来将
org.apache.coyote.http11.Http11NioProtocol
If you're using BIO then I believe they should be more or less the same.
如果您使用的是 BIO,那么我相信它们应该或多或少相同。
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.
如果您使用的是 NIO,那么实际上“maxConnections=1000”和“maxThreads=10”甚至可能是合理的。默认值为 maxConnections=10,000 和 maxThreads=200。使用 NIO,每个线程可以为任意数量的连接提供服务,来回切换但保留连接,因此您不需要进行所有通常的握手,这对于 HTTPS 特别耗时,但对于 HTTP 甚至是一个问题。您可以调整“keepAlive”参数以保持连接更长时间,这应该会加快一切速度。
回答by Swapnil
From Tomcat documentation, For blocking I/O (BIO), the default value of maxConnections
is the value of maxThreads
unless Executor(thread pool) is used in which case, the value of 'maxThreads' from Executor will be used instead. For Non-blocking IO, it doesn't seem to be dependent on maxThreads
.
来自Tomcat 文档,对于阻塞 I/O (BIO),除非使用Executor(线程池)maxConnections
,maxThreads
否则默认值为的值,在这种情况下,将使用 Executor 中的“maxThreads”值。对于非阻塞 IO,它似乎不依赖于.maxThreads