`
sillycat
  • 浏览: 2564583 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

SpringBoot2 and Tomcat Connection Timeout

 
阅读更多
SpringBoot2 and Tomcat Connection Timeout

First of all, in my friends’ project, they did not use last spring boot web-flux.
So we have application.properties as follow
server.port=50310
server.address=0.0.0.0
server.connection-timeout=-1
server.tomcat.connection-timeout=-1
-1 means never timeout I guess.
I have not tested for confirmation if the properties works or not, because when it has issue, it configure as 1, maybe means 1 minute or 1 second.
I put this EmbeddedTomcatConfig.java in my class path.
package com.sillycat.connectors.quickbooks.config;
import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;
@Component
public class EmbeddedTomcatConfig implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
    @Override
    public void customize(ConfigurableServletWebServerFactory factory) {
        ((TomcatServletWebServerFactory) factory).addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
                protocol.setMaxConnections(200);
                protocol.setMaxThreads(200);
                protocol.setSelectorTimeout(600000);
                protocol.setSessionTimeout(600000);
                protocol.setConnectionTimeout(600000);
            }
        });
    }
}
After that I use my apache ab tool to test the performance.
Install Apache ab Tool
> sudo apt-get install apache2-utils
Try my curl command
> curl -X GET "http://localhost:50300/api/account/v1" -H "company: cloudsnap"
Try with ab tool, 10 requests, 2 concurrent threads
> ab -t 10 -c 2 -l -H "company: cloudsnap" http://localhost:50300/api/account/v1
60 seconds, 2 users keep sending requests
> ab -t 60 -c 20 -l -H "company: cloudsnap" http://localhost:50300/api/account/min/v1

References:
https://stackoverflow.com/questions/31461444/how-do-i-configure-this-property-with-spring-boot-and-an-embedded-tomcat
https://stackoverflow.com/questions/839314/clientabortexception-java-net-socketexception-connection-reset-by-peer-socket
SpringBoot Configuration
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
https://juejin.im/post/5ae17c95518825670d72ce23
https://www.jianshu.com/p/5c66de185ac3
https://my.oschina.net/go4it/blog/1801604

分享到:
评论

相关推荐

    springboot-keepalive设置测试

    server.tomcat.connection-timeout=30000 # 连接超时时间,单位毫秒 server.tomcat.keep-alive-timeout=60000 # keep-alive超时时间,单位毫秒 ``` 在进行keepalive测试时,我们通常会使用像Jodd库这样的HTTP客户端...

    Springboot多连接池.zip.zip

    例如设置最大连接数`spring.datasource.hikari.maximum-pool-size`,初始化连接数`spring.datasource.hikari.minimum-idle`,以及连接超时时间`spring.datasource.hikari.connection-timeout`等。 2. Druid:这是一...

    java8源码-springboot-mybatis-demo01:springboot-mybatis-demo01

    java8 ...connection-timeout: 5000 #开发环境设置false(这样改动前段不需重启应用了),生产去掉该配置,使用默认的true thymeleaf: cache: false #request before '/static/**' will control with

    SpringBoot2.0 整合 Dubbo框架实现RPC服务远程调用方法

    connection-timeout: 5000ms spring: application: name: block-dubbo-provider dubbo: application: name: block-dubbo-provider registry: address: 127.0.0.1:2181 protocol: zookeeper protocol: name:...

    Spring Boot连接超时导致502错误的实战案例

    首先,让我们理解`server.tomcat.connection-timeout`配置项的作用。这个属性是Spring Boot中用于设置Tomcat容器等待请求完成的最大时间,单位是毫秒。如果在这个时间内请求没有完成,Tomcat会关闭连接并返回一个...

    java8源码-springboot-mybatis-demo02:springboot-mybatis-demo02

    java8 ...connection-timeout: 5000 #开发环境设置false(这样改动前段不需重启应用了),生产去掉该配置,使用默认的true thymeleaf: cache: false #request before '/static/**' will control with

    java8源码-springboot:弹簧靴

    java8 ...connection-timeout: 5000 #开发环境设置false(这样改动前段不需重启应用了),生产去掉该配置,使用默认的true thymeleaf: cache: false #request before '/static/**' will control with

    java基于UNIX域套接字(unix domain socket)连接redis

    timeout: 3000 password: your-password ``` 最后,需要注意的是,使用UNIX域套接字的安全性和权限问题。由于`.sock`文件是文件系统中的实体,因此需要确保只有授权的进程才能访问。通常,Redis服务器会以特定...

    spring cloud gateway配置Hystrix 熔断、限流、后台调用注意点.pdf

    connection-timeout: 20000 ``` 在上面的配置中,我们设置了服务的最大线程数为 500,并设置了线程最大空闲时间为 20000 毫秒。 熔断配置 熔断配置是指配置熔断器的行为,例如熔断器的触发条件、回退 URI 等。...

    第一个Spring Boot应用.docx

    connection-timeout: 3000 validation-timeout: 3000 max-lifetime: 60000 maximum-pool-size: 20 minimum-idle: 1 ``` 3. **环境变量与默认值**: 在配置文件中,你可以使用 `${VAR_NAME:default_value}` ...

Global site tag (gtag.js) - Google Analytics