问题描述
我正在用Apache JMeter测试我的Spring Boot REST API服务器.
I'm testing my Spring Boot REST API server with Apache JMeter.
大多数连接时间"以10毫秒为单位,但是连接超时有时会发生.
Most of 'Connect Time' is in 10ms, but connection timed out occurs sometime.
JMeter的设置
- Thread
Number of Threads : 500
Ramp-Up Period : 50
- HTTP Request
Connect timeout : 20000ms
Response timeout : 40000ms
- Constant timer
Thread delay : 1000ms
CentOS7设置
open files (-n) 65535
max user processes (-u) 65535
Java执行设置
-Xmx8g -Xms4g -Xmn2g -XX:PermSize=512m -XX:SurvivorRatio=16
Spring Boot application.properties Tomcat设置
Spring Boot application.properties Tomcat settings
server.tomcat.connection-timeout=20000
server.tomcat.max-connections=100000
server.tomcat.threads.max=10000
server.tomcat.threads.min-spare=2500
server.tomcat.accept-count=10000
JMeter最多可以处理10,000〜20,000个请求,但此后会发生连接超时.
JMeter works normally up to 10,000~20,000 requests, but connection timeout occurs after that.
Starting standalone test @ Fri Apr 16 09:30:29 KST 2021 (1618533029412)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary + 1 in 00:00:03 = 0.4/s Avg: 1319 Min: 1319 Max: 1319 Err: 0 (0.00%) Active: 127 Started: 127 Finished: 0
summary + 8771 in 00:00:28 = 318.5/s Avg: 398 Min: 236 Max: 4191 Err: 0 (0.00%) Active: 500 Started: 500 Finished: 0
summary = 8772 in 00:00:30 = 290.3/s Avg: 398 Min: 236 Max: 4191 Err: 0 (0.00%)
summary + 9349 in 00:00:30 = 311.6/s Avg: 534 Min: 237 Max: 3582 Err: 0 (0.00%) Active: 500 Started: 500 Finished: 0
summary = 18121 in 00:01:00 = 300.9/s Avg: 468 Min: 236 Max: 4191 Err: 0 (0.00%)
summary + 5872 in 00:00:30 = 195.7/s Avg: 1494 Min: 235 Max: 20855 Err: 10 (0.17%) Active: 500 Started: 500 Finished: 0
summary = 23993 in 00:01:30 = 265.9/s Avg: 719 Min: 235 Max: 20855 Err: 10 (0.04%)
org.apache.http.conn.HttpHostConnectException: Connect to <IP Address>:<Port> [/112.220.184.107] failed: Connection timed out: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl$JMeterDefaultHttpClientConnectionOperator.connect(HTTPHC4Impl.java:336)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:843)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:574)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:67)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1231)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1220)
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:607)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 19 more
你能告诉我为什么会发生吗?
Can you tell me why it happens?
推荐答案
summary + 5872 in 00:00:30 = 195.7/s Avg: 1494 Min: 235 Max: 20855 Err: 10 (0.17%) Active: 500 Started: 500 Finished: 0
^^^^^^^
您的响应时间增加到20秒以上,因此Tomcat拒绝了该连接(很可能该设置是缓慢的HTTP攻击
Your response time increases above 20 seconds hence Tomcat rejects the connection (most probably the setting acts as the protection from slow HTTP attacks
要么将其设置为 -1
以禁用它,要么使用 profiler工具查看导致您的应用程序/tomcat端出现问题的原因.
either set it to -1
to disable it or use a profiler tool to see what is causing the problem on your application/tomcat end.
JMeter的命令行输出也无法完整说明问题,我建议您从.jtl结果文件中生成一些图表,例如随时间变化的响应时间,随时间变化的活动线程,每秒交易次数,等等,以便您可以关联各种性能指标.监视服务器端操作系统的运行状况指标(如CPU,RAM,网络,交换,磁盘使用以及JVM JMX指标)也是一个好主意,可以使用 JMeter PerfMon插件
Also JMeter command-line output doesn't tell the full story, I would recommend generating some charts from the .jtl results file like Response Times Over Time, Active Threads Over Time, Transactions per Second, etc. so you could correlate various performance metrics. It's also a good idea to monitor server-side operating system health metrics like CPU, RAM, Network, Swap, Disk usage as well as JVM JMX metrics, it can be done using i.e. JMeter PerfMon Plugin
这篇关于Spring Boot REST API服务器连接有时超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!