spring boot rest api服务器连接超时

gudnpqoy  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(468)

我正在用ApacheJMeter测试我的SpringBootRESTAPI服务器。
大多数“连接时间”在10毫秒内,但有时会发生连接超时。
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设置

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在10000~20000个请求下正常工作,但之后会发生连接超时。

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





你能告诉我为什么会这样吗?

hvvq6cgz

hvvq6cgz1#

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攻击的作用)
要么把它设成 -1 禁用它或使用探查器工具查看是什么导致应用程序/tomcat端出现问题。
另外,jmeter命令行输出并不能说明全部情况,我建议从.jtl结果文件生成一些图表,如随时间变化的响应时间、随时间变化的活动线程、每秒事务数等,这样就可以关联各种性能指标。监视服务器端操作系统的健康指标(如cpu、ram、网络、交换、磁盘使用情况)以及jvmjmx指标也是一个好主意,可以使用jmeter perfmon plugin来完成

相关问题