Tomcat8.5性能优化

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的状态。

你可能感兴趣的:(Tomcat8.5性能优化)