Tomcat 重要参数解释
# 默认队列长度
server.tomcat.accept-count=100
# 默认最大连接数
server.tomcat.max-connections=8192
# 默认最大工作线程数
server.tomcat.threads.max=200
# 默认最小工作线程数
server.tomcat.threads.min-spare=10
server.tomcat.threads.max
代表: tomcat 能够在同一时间处理的请求的最大数量。
server.tomcat.max-connections
代表: tomcat 能够在同一时间接受的最大请求数量.
官方释义:
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.
意思是:
服务器在任何给定时间接受和处理的最大连接数。一旦达到限制,操作系统仍然可以接受基于“acceptCount”属性的连接。
server.tomcat.accept-count
官方释义:
Maximum queue length for incoming connection requests when all possible request processing threads are in use.
意思是: 当所有可能的请求处理线程都在使用时,传入连接请求的最大队列长度。
测试
配置如下
# 默认队列长度
server.tomcat.accept-count=5
# 默认最大连接数
server.tomcat.max-connections=12
# 默认最大工作线程数
server.tomcat.threads.max=6
# 默认最小工作线程数
server.tomcat.threads.min-spare=3
测试代码:
请求如下:
一秒种20次请求, 看下请求的结果是什么?
可以看到执行后只有6个请求被处理了.
JMiter 界面上可以看到的是有3个请求是直接被拒绝了
过了 1 分钟, Jmiter 可以看到有6个请求已经成功返回
又过了1分钟, 可以看到Jmiter界面 看到有成功返回12个请求成功的,
再过1分钟, 可以看到剩下的5个请求也成功返回了
我们也可以看到控制台成功打印了数字17
也就是一共处理了17个请求.
结论:
tomcat 可以同时最大处理的请求数量由 server.tomcat.threads.max
控制
tomcat 能够同时接受的最大链接数量 = server.tomcat.max-connections
+ server.tomcat.accept-count
即最大链接数+最大队列等待数量.