Преглед изворни кода

tomcat容器变更为undertow

andyliu пре 7 месеци
родитељ
комит
0dbf8cabef

+ 9 - 0
pom.xml

@@ -52,6 +52,11 @@
 			<artifactId>spring-boot-starter-web</artifactId>
 			<exclusions>
 				<exclusion>
+					<groupId>org.springframework.boot</groupId>
+					<artifactId>spring-boot-starter-tomcat</artifactId>
+				</exclusion>
+
+				<exclusion>
 					<groupId>ch.qos.logback</groupId>
 					<artifactId>logback-classic</artifactId>
 				</exclusion>
@@ -63,6 +68,10 @@
 			</exclusions>
 		</dependency>
 
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-undertow</artifactId>
+		</dependency>
 
 		<!-- spring-security 和 jwt -->
 		<dependency>

+ 13 - 0
src/main/java/com/shkpr/service/proxycenter/ProxyCenterApplication.java

@@ -8,7 +8,11 @@ import com.shkpr.service.proxycenter.interfaces.sinks.LogPrintSink;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.server.WebServerFactoryCustomizer;
+import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
 import org.springframework.retry.annotation.EnableRetry;
+import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
 
@@ -49,4 +53,13 @@ public class ProxyCenterApplication {
 		LogPrintMgr.getInstance().initResWithDisruptor(/*GlobalData.getInstance().getCpuCores()*/2, 2, new LogPrintSink());//io型线程池=CPU Core*2;计算型线程池=CPU Core
 		SpringApplication.run(ProxyCenterApplication.class, args);
 	}
+
+	@Component
+	class GlobalWebServerFactoryCustomizer implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
+		@Override
+		public void customize(ConfigurableServletWebServerFactory factory) {
+			UndertowServletWebServerFactory factoryReal = (UndertowServletWebServerFactory)factory;
+			factoryReal.setPort(mNPort);
+		}
+	}
 }

+ 17 - 15
src/main/resources/application.properties

@@ -20,15 +20,23 @@ server.servlet.session.timeout=60s
 # 最大链接超时时间
 server.connection-timeout=60s
 
-#Tomcat配置================>
-# tomcat的URI编码
-server.tomcat.uri-encoding=UTF-8
-# 存放Tomcat的日志、Dump等文件的临时文件夹,默认为系统的tmp文件夹(如:C:\Users\Shanhy\AppData\Local\Temp)
-server.tomcat.basedir=./trilog/tomcattmp
-# Tomcat的Access日志开关(默认值false):
-server.tomcat.access-log-enabled=false
-# Tomcat的Access日志格式[common 或 combined],默认值common,注:若设置为空则日志文件内容为空
-server.tomcat.access-log-pattern=common
+# 是否打开 undertow 日志,默认为 false
+server.undertow.accesslog.enabled=false
+# 设置访问日志所在目录
+server.undertow.accesslog.dir=./trilog
+# 指定工作者线程的 I/0 线程数,默认为 2 或者 CPU 的个数
+server.undertow.io-threads=4
+# 指定工作者线程个数,默认为 I/O 线程个数的 8 倍
+server.undertow.worker-threads=400
+# 设置缓冲区大小
+server.undertow.buffer-size=1024
+# 使用直接内存
+server.undertow.direct-buffers=true
+#连接超时时间
+server.undertow.connection-timeout=60s
+#设置HTTP POST请求的最大内容大小,以适应可能的文件上传或大批量数据提交
+server.undertow.max-http-post-size=0
+
 
 ## Freemarker 配置
 ## 文件配置路径
@@ -51,12 +59,6 @@ global.machine.index=0
 global.service.index=5
 # 本服务的ID
 global.server.id=kpr.proxy.v100
-# tomcat同一时刻可接收的第三方最大并发连接数(Java NIO模式下默认是10000)
-global.max.tomcat.concurrent.request=10000
-# tomcat可启动的最大线程数(默认值为200),调优取值[200,1000],注:在shell脚本中根据当前配置动态计算
-global.max.tomcat.threads=400
-# tomcat启动的线程数达到最大时,接受排队的请求个数(默认值为100),调优取值[100,400],注:在shell脚本中根据当前配置动态计算
-global.max.tomcat.accept.queue=200
 
 #===================Redis配置文件路径====================
 #global.redis.config.path=./redis.properties