我正在使用 JMeter 对我的 Spring Boot 服务器进行负载测试,并且已经
应用程序属性
server.tomcat.accept-count=100000
server.tomcat.max-threads=1000
应用程序.java
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Application.class, args);
ServerProperties serverProperties = context.getBean(org.springframework.boot.autoconfigure.web.ServerProperties.class);
Tomcat tomcat = serverProperties.getTomcat();
Logger.getLogger(Application.class.getName()).info("acceptCount = " + tomcat.getAcceptCount());
Logger.getLogger(Application.class.getName()).info("maxConnections = " + tomcat.getMaxConnections());
Logger.getLogger(Application.class.getName()).info("maxThreads = " + tomcat.getMaxThreads());
控制台
2019-10-24 20:22:31.174 INFO 57472 --- [ restartedMain] c.s.s.Application : acceptCount = 100000
2019-10-24 20:22:31.174 INFO 57472 --- [ restartedMain] c.s.s.Application : maxConnections = 10000
2019-10-24 20:22:31.175 INFO 57472 --- [ restartedMain] c.s.s.Application : maxThreads = 1000
loadtest.jmx
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">100</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">10000</stringProp>
<stringProp name="ThreadGroup.ramp_time">10</stringProp>
(10,000 个用户 x 100 个循环 = 100 万个请求)
在 JMeter 查看结果树
中,我看到错误:
Response code: Non HTTP response code: java.net.SocketTimeoutException
Response message: Non HTTP response message: Read timed out
摘要报告
显示,在错误导致测试停止之前,它已获取了多达 11,000 个样本。我不明白,因为接受计数为 100,000,在开始拒绝并导致 JMeter 获得 SocketTimeoutException 之前,它不应该接受队列中的 100,000 个连接吗?
我还尝试了 accept-count=10000
、max-connections=1000
,JMeter 最多获得 8000 个样本,最大时间 12000ms( 超时 30 秒) HTTP 请求
),并给出错误响应代码:非 HTTP 响应代码:org.apache.http.conn.HttpHostConnectException
响应消息:非 HTTP 响应消息:连接到 localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] 失败:连接被拒绝:连接
。在拒绝之前,它至少应该排队 10,000 个连接。
最佳答案
maxConnections
The maximum number of connections that the server will accept and process at any given time. When this number has been reached, the server will accept, but not process, one further connection. This additional connection be blocked until the number of connections being processed falls below maxConnections at which point the server will start accepting and processing new connections again. Note that once the limit has been reached, the operating system may still accept connections based on the acceptCount setting. The default value varies by connector type. For NIO and NIO2 the default is 10000. For APR/native, the default is 8192.
因此我的期望是服务器可以在 10k 并发连接上工作,并且上面的连接被放入队列中。如果这是您想要的行为 - 只需增加 JMeter 的 HTTP Request Defaults 中的连接/响应超时即可,设置位于“高级”选项卡下:
关于java - 当我的accept-count=100000时,为什么会出现SocketTimeoutException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58551216/