Tomcat默认请求数到底是多少!!!(本篇是以Tomcat8.5
作为参考)
有人认为是150,也有人认为是200,那么到底是多少呢,说这两种情况的人有没有什么依据呢,下面我们就来一探究竟。
探究一门技术,官网是最具有说服力的,那我们就先到官网看一下。
https://tomcat.apache.org/tomcat-8.5-doc/config/executor.html
在官网中有这么一段话:
-maxThreads :
(int) The max number of active threads in this pool, default is 200
在对Executor
的配置中有一个maxThreads
参数,该参数就是用来指定最大请求数,默认数是200;
https://tomcat.apache.org/tomcat-8.5-doc/config/http.html
在Connector
的配置中也有一个参数maxThreads
用来修改最大线程数。
-maxThreads :
The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled.` If not specified, this attribute is set to 200. `
If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool. Note that if an executor is configured any value set for this attribute will be recorded correctly but it will be reported (e.g. via JMX) as -1 to make clear that it is not used.
从官网的描述中可以获取到两部分的信息;
1)maxThreads
的默认值是200;
2)如果在connector
中配置了executor
的设置,那么将使用executor
中设置的maxThreads
的值;
从官网中已经清楚了,无论是executor
还是Connector
中对maxThreads
的默认数都是200;因为小编有个强迫症,特别是在看springboot
源码的时候,有时候发现官网跟源码中有个别时候居然出现不一致的现象,所以,小编决定再到Tomcat
源码中再深究一下。
在Executor
的实现类StandardThreadExecutor
中:
/**
* max number of threads
*/
protected int maxThreads = 200;
至此,我们就彻底清楚了,Tomcat
中默认的最大请求数为200。
这里还有一个问题,为什么有的人是认为是150呢,其实他们是看到了Tomcat
中server.xml
的配置,才想当然的以为是150了。
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true" >
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
certificateFile="conf/localhost-rsa-cert.pem"
certificateChainFile="conf/localhost-rsa-chain.pem"
type="RSA" />
SSLHostConfig>
Connector>
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
现在大家可以清楚了Tomcat
的默认最大请求数了吧,再也不会纠结到底是200还是150了。