java - 当我的accept-count=100000时,为什么会出现SocketTimeoutException?

标签 java performance spring-boot jmeter load-testing

我正在使用 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=10000max-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 个连接。

最佳答案

根据 Tomcat documentation

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 中的连接/响应超时即可,设置位于“高级”选项卡下:

enter image description here

关于java - 当我的accept-count=100000时,为什么会出现SocketTimeoutException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58551216/

相关文章:

java - 更新到 Android Studio Chipmunk 后单元测试未运行

java - 如何为tomcat webapps配置设置正确的windows路径

java - 服务器和线程模型

java - 迁移到 Spring Boot 2 后忽略自定义 ObjectMapper

java - 微服务架构中微服务之间如何共享java模型

java - 如何使用for循环计算字符串中空格分隔符的数量?

java - 如何将 JTextField 中的用户输入放入另一个方法中

python - 根据值对列表进行编号的更优雅的方法

performance - 找到到任何子串的最小汉明距离的最快方法?

java - 创建单元测试用例时无法将 @Autowired 与 @Mock 一起使用