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
分享到:
相关推荐
2. 替换成需要的版本:根据找到的当前各个模块的 Tomcat 配置,替换成需要的版本后,将配置内容添加到启动类所在的 pom.xml 中配置中即可。 3. 无启动项的模块无需修改:如果 common 模块中没有启动项,无需修改 ...
SpringBoot-2.7.6内置Tomcat启动以及DispatcherServlet装配过程,源码跟踪调试流程图
2. 独立Tomcat部署:对于生产环境,可能需要将SpringBoot应用部署到独立的Tomcat服务器上。这时我们需要将项目打包成WAR文件,然后将WAR文件复制到Tomcat的`webapps`目录下。Tomcat会自动解压并启动应用。这种方式更...
2. **修改 `server.xml` 文件**:编辑 Tomcat 的 `server.xml` 文件,在 `<Connector>` 元素中添加 SSL 相关配置。 ```xml maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth=...
SpringBoot引用外部Tomcat.pdfSpringBoot引用外部Tomcat.pdfSpringBoot引用外部Tomcat.pdfSpringBoot引用外部Tomcat.pdfSpringBoot引用外部Tomcat.pdf
本示例将向你展示如何将一个简单的SpringBoot应用部署到外部的Tomcat服务器上,这对于开发者来说是一项基本但至关重要的技能。让我们深入探讨这个过程。 首先,了解SpringBoot的核心特性:内置的Servlet容器。默认...
server.tomcat.connection-timeout=30000 # 连接超时时间,单位毫秒 server.tomcat.keep-alive-timeout=60000 # keep-alive超时时间,单位毫秒 ``` 在进行keepalive测试时,我们通常会使用像Jodd库这样的HTTP客户端...
本示例主要探讨如何在SpringBoot项目中整合JSP视图,并提供了两种不同的部署方式:内置Tomcat启动和外部Tomcat部署。这两种方式各有优缺点,适合不同场景的应用。 首先,让我们深入理解SpringBoot整合JSP的基本步骤...
SpringBoot启动内嵌容器,启动时自动加载tomcat原理,tomcat内嵌集成实现
2. 在`<properties>`标签内设置`<tomcat.version>`为你需要的版本。 3. 如果需要,覆盖`spring-boot-starter-parent`中定义的Tomcat版本。 4. 添加或更新`tomcat-juli`依赖确保版本匹配。 5. 如果遇到缺少jar包的...
在本教程中,我们将深入探讨如何在Tomcat服务器上部署一个结合了SpringBoot后端和Vue.js前端的应用。 首先,为了在Tomcat上部署SpringBoot+Vue项目,我们需要进行以下步骤: 1. **修改POM文件**: 在SpringBoot...
SpringBoot如何取消内置Tomcat启动并改用外接Tomcat SpringBoot框架默认情况下会将Tomcat作为内置容器,然而在某些情况下,我们需要取消内置Tomcat启动并改用外接Tomcat。那么,如何实现这一点呢?下面我们将通过...
毕设项目:网上时装购物商城系统(Springboot+tomcat+mysql+完整程序源码+数据库+完整文档+答辩ppt) 毕设项目:网上时装购物商城系统(Springboot+tomcat+mysql+完整程序源码+数据库+完整文档+答辩ppt) 毕设项目:...
毕设项目:图书个性化推荐系统的设计与实现(Springboot+Tomcat+mysql+完整源码+数据库+完整文档+答辩ppt 毕设项目:图书个性化推荐系统的设计与实现(Springboot+Tomcat+mysql+完整源码+数据库+完整文档+答辩ppt ...
相比较于传统的Spring,SpringBoot具有以下优点:部署简单,SpringBoot内置了Tomcat容器,可以将程序直接编译成一个jar,通过java-jar来运行。编码简单,SpringBoot只需要在pom文件中添加一个starter-web依赖,即可...
Springboot内置tomcat配置虚拟路径过程解析 Springboot框架提供了内置的tomcat服务器,可以通过配置虚拟路径来实现静态资源的访问。虚拟路径的配置可以在application.properties文件中进行设置。下面是Springboot...
2. 排除 SpringBoot 自带的 Tomcat 插件 3. 使用 SpringBootServletInitializer继承Application.java类 4. 使用 mvn clean package 命令或编辑器打包成 war 文件 5. 将 war 文件复制到 Tomcat 服务器的 webapps 目录...
"Spring Boot 项目与 Vue 一起部署到 Tomcat 服务器" 在本文中,我们将介绍如何将 Spring Boot 项目和 Vue 一起部署到 Tomcat 服务器中。这个过程需要我们对 Tomcat 服务器进行配置,以便能够正确地部署并运行我们...
毕设项目:基于SpringBoot+Vue+Tomcat+MySQL的在线拍卖管理系统(含源码+数据库+文档+答辩ppt).zip 毕设项目:基于SpringBoot+Vue+Tomcat+MySQL的在线拍卖管理系统(含源码+数据库+文档+答辩ppt).zip 毕设项目:...