彻底弄懂Tomcat默认请求数到底是多少!!!

1 背景

Tomcat默认请求数到底是多少!!!(本篇是以Tomcat8.5作为参考)

有人认为是150,也有人认为是200,那么到底是多少呢,说这两种情况的人有没有什么依据呢,下面我们就来一探究竟。

探究一门技术,官网是最具有说服力的,那我们就先到官网看一下。

2 官网

2.1 Executor

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;

2.2 Connector

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源码中再深究一下。

3 源码

Executor的实现类StandardThreadExecutor中:

    /**
     * max number of threads
     */
    protected int maxThreads = 200;

至此,我们就彻底清楚了,Tomcat中默认的最大请求数为200。

4 解惑

​ 这里还有一个问题,为什么有的人是认为是150呢,其实他们是看到了Tomcatserver.xml的配置,才想当然的以为是150了。

<!--Connector -->
<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 -->
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
          maxThreads="150" minSpareThreads="4"/>

5 结语

现在大家可以清楚了Tomcat的默认最大请求数了吧,再也不会纠结到底是200还是150了。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值