Tomcat8.5性能优化

本文探讨了Tomcat 8.5的性能优化,重点关注了Spring Boot 2中默认的配置参数,如max-threads、accept-count和max-connections等,并引用了官方文档作为依据。此外,还解释了acceptorThreadCount和pollerThreadCount这两个Spring未提供的配置项,建议根据服务器的CPU核心数和业务需求进行调整。通过Java Mission Control可以验证设置是否生效。

tomcat性能优化的文章很多,但是有很多内容已经过时了。近期因为需要写spring cloud F版
的tomcat优化手册,故记录一下调查内容。
参考:https://tomcat.apache.org/tomcat-8.5-doc/config/http.html
(没有官方依据的优化都是耍流氓)

springBoot2默认提供的tomcat配置:(略去部分不重要的)
server.tomcat.basedir=/tomcat/log
server.tomcat.max-threads=222
server.tomcat.accept-count=100
server.tomcat.max-connections=10000
server.tomcat.max-swallow-size=10m
server.tomcat.accesslog.enabled=true
server.tomcat.min-spare-threads=20
server.tomcat.max-http-post-size=20m

额外解释部分(Spring未提供):

  • acceptorThreadCount

The number of threads to be used to accept connections. Increase this value on a multi CPU machine, although you would never really need more than 2. Also, with a lot of non keep alive connections, you might want to increase this value as well. Default value is 1.
我的理解是,推荐设置2或3(不能超过CPU核数)

  • pollerThreadCount
    (int)The number of threads to be used to run for the polling events. Default value is 1 per processor but not more than 2.
    When accepting a socket, the operating system holds a global lock. So the benefit of going above 2 threads diminishes rapidly. Having more than one thread is for system that need to accept connections very rapidly. However usually just increasing acceptCount will solve that problem. Increasing this value may also be beneficial when a large amount of send file operations are going on.
    我的理解是,非常频繁的传输大文件时,这个参数会比较有用。否则acceptCount 就够了。

  • Http11NioProtocol和Http11Nio2Protocol
    有人说是这两者没什么性能上的差异所以默认还是前者。

如何判断设置是否生效呢?可以运行Java Mission Control查看Tomcat这个MBean的状态。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值