Springboot-Tomcat配置解析
SpringBoot版本:2.2.2.RELEASE
server:
tomcat:
max-connections: 10000
max-threads: 200
accept-count: 100
min-spare-threads: 10
connection-timeout: 30s
max-connections
/**
* Maximum number of connections that the server accepts and processes at any
* given time. Once the limit has been reached, the operating system may still
* accept connections based on the "acceptCount" property.
*/
- tomcat可建立的最大连接数,超过则放入accept-count队列中。默认10000
accept-count
/**
* Maximum queue length for incoming connection requests when all possible request
* processing threads are in use.
*/
- 超过max-connections的连接请求放入队列
max-threads
/**
* Maximum amount of worker threads.
*/
- 最大工作线程数。默认200。
- BIO模式。一个线程处理一个连接
- NIO模式。一个线程处理多个连接
min-spare-threads
/**
* Minimum amount of worker threads.
*/
connection-timeout
/**
* Amount of time the connector will wait, after accepting a connection, for the
* request URI line to be presented.
*/
- 实际设置的是socket_timeout。socket调用read()方法阻塞不超过这个时间,否则报
java.net.SocketTimeoutException
。不设置时,默认为60000ms
总结:
- 线程并不是越多越好,需要考虑上下文切换CPU的消耗,CPU时间片分配变少
参考:
Spring Boot 默认支持的并发量