SpringBoot内置tomcat参数调优

1. 默认配置

可通过org.springframework.boot.autoconfigure.web.ServerProperties查看,其中包括属性tomcat、jetty、undertow三种服务器的设置,默认启用tomcat。

# tomcat 8
server:
  tomcat:
    max-connections: 10000 #最大连接数,默认为10000
    accept-count: 100 # 最大连接等待数,默认100 
    max-threads: 200  #最大工作线程数,默认200
    min-spare-threads: 10 #最小工作线程数,默认10

# tomcat 9
server:
  tomcat:
    max-connections: 8192
    accept-count: 100
    threads:
      max: 200
      min-spare: 10

详解:maxConnections、maxThreads、acceptCount

每一次HTTP请求到达Web服务器,Web服务器都会创建一个线程来处理该请求
min-spare-threads:
最小备用线程数,tomcat启动时的初始化的线程数,默认10。(适当增大一些,以便应对突然增长的访问量) max
-threads:
Tomcat可创建的最大工作线程数,默认200, 每一个线程处理一个请求,超过这个请求数后,客户端请求只能排队,等有线程释放才能处理。(4核8g内存,线程数800,一般是 核数*200 。操作系统做线程之间的切换调度是有系统开销的,所以不是越多越好。) accept-count:
当调用Web服务的HTTP请求数达到tomcat的最大线程数时,还有新的HTTP请求到来,这时tomcat会将该请求放在等待队列中,这个acceptCount就是指能够接受的最大等待数,默认100
如果等待队列也被放满了,这个时候再来新的请求就会被tomcat拒绝(connection refused),队列也做缓冲池用,但也不能无限长,不但消耗内存,而且出队入队也消耗CPU。 max
-connections:
这个参数是指在同一时间,tomcat能够接受的最大连接数一般这个值要大于(max-threads)+(accept-count)

 

2. Tomcat经验值

max-threads线程数的经验值为:
1核2g内存,线程数经验值200;
4核8g内存,线程数经验值800。

4核8g内存,建议值:

server:
  tomcat:
    max-connections: 10000 
    accept-count: 1000
    max-threads: 800 
    min-spare-threads: 100

 

 

参考博文: 

1. Springboot内置tomcat优化: https://blog.csdn.net/swadian2008/article/details/120314524

2. Springboot配置Tomcat运行参数,优化JVM提高系统稳定性: https://cloud.tencent.com/developer/news/422280

posted @ 2022-08-12 17:51  Sherlock先生  阅读(2301)  评论(0编辑  收藏  举报