Tomcat线程数

本文探讨了Tomcat在高并发时线程池满的问题,解析了maxThreads、maxConnections、acceptCount和minSpareThreads等关键参数的含义。在特定情况下,如并发请求超过maxConnections,请求会进入队列,超出acceptCount则会被拒绝。线程池不会主动收缩,除非没有请求且线程超过minSpareThreads。此外,maxIdleTime参数决定闲置线程的关闭时间,但线程是否释放还受TPS影响。
摘要由CSDN通过智能技术生成

Tomcat每到凌晨会有一个高峰,峰值的并发达到了3000以上,最后的结果是Tomcat线程池满了,日志看很多请求超过了1s。

 <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="3000" minSpareThreads="800"/>

    <Connector executor="tomcatThreadPool" port="8084" protocol="org.apache.coyote.http11.Http11AprProtocol"
               connectionTimeout="60000"
               keepAliveTimeout="30000"
               maxKeepAliveRequests="8000"
               maxHttpHeaderSize="8192"
               URIEncoding="UTF-8"
               enableLookups="false"
               acceptCount="1000"
               disableUploadTimeout="true"
               redirectPort="8443" />

事后thread dump看其实真正处于RUNNABLE状态的线程很少,绝大部分线程都处于TIMED_WAITING状态:

于是大伙都开始纠结为什么线程会涨到3000,而且发现即使峰值过了线程数并不会降下来。

大量的Tomcat线程处于等待状态不会消耗CPU,但是会消耗一些JVM存储。

maxKeepAliveRequests:

The maximum number of HTTP requests which can be pipelined until the connection is closed by the server. Setting this attribute to 1 will disable HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. Setting this to -1 will allow an unlimited amount of pipelined or keep-alive HTTP requests. If not specified, this attribute is set to 100.

keepAliveTimeout:

The number of milliseconds this Connector will wait for another HTTP request before closing the connection. The default value is to use the value that has been set for the connectionTimeout attribute. Use a value of -1 to i

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值