web容器从undertow切换到tomcat,更好地支持虚拟线程

This commit is contained in:
dataprince 2024-01-14 08:54:22 +08:00
parent 9f4991f32f
commit a84a3c6049
7 changed files with 66 additions and 60 deletions

View File

@ -95,7 +95,7 @@ redisson:
--- # 监控中心客户端配置 --- # 监控中心客户端配置
spring.boot.admin.client: spring.boot.admin.client:
# 增加客户端开关 # 增加客户端开关
enabled: false enabled: true
url: http://localhost:9090/admin url: http://localhost:9090/admin
instance: instance:
service-host-type: IP service-host-type: IP
@ -106,7 +106,7 @@ spring.boot.admin.client:
powerjob: powerjob:
worker: worker:
# 如何开启调度中心请查看文档教程 # 如何开启调度中心请查看文档教程
enabled: false enabled: true
# 需要先在 powerjob 登录页执行应用注册后才能使用 # 需要先在 powerjob 登录页执行应用注册后才能使用
app-name: ruoyi-worker app-name: ruoyi-worker
# 28080 端口 随着主应用端口飘逸 避免集群冲突 # 28080 端口 随着主应用端口飘逸 避免集群冲突

View File

@ -33,20 +33,27 @@ server:
# 应用的访问路径 # 应用的访问路径
context-path: / context-path: /
# tomcat web容器配置
tomcat:
# tomcat的URI编码
uri-encoding: UTF-8
# 连接数满后的排队数默认为100
accept-count: 1000
# undertow web容器配置 # undertow web容器配置
undertow: # undertow:
# HTTP post内容的最大大小。当值为-1时默认值为大小是无限的 # # HTTP post内容的最大大小。当值为-1时默认值为大小是无限的
max-http-post-size: -1 # max-http-post-size: -1
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理 # # 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
# 每块buffer的空间大小,越小的空间被利用越充分 # # 每块buffer的空间大小,越小的空间被利用越充分
buffer-size: 512 # buffer-size: 512
# 是否分配的直接内存 # # 是否分配的直接内存
direct-buffers: true # direct-buffers: true
threads: # threads:
# 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 # # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
io: 8 # io: 8
# 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载 # # 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
worker: 256 # worker: 256
# 日志配置 # 日志配置
logging: logging:

View File

@ -45,18 +45,18 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<exclusions> <!-- <exclusions>-->
<exclusion> <!-- <exclusion>-->
<artifactId>spring-boot-starter-tomcat</artifactId> <!-- <artifactId>spring-boot-starter-tomcat</artifactId>-->
<groupId>org.springframework.boot</groupId> <!-- <groupId>org.springframework.boot</groupId>-->
</exclusion> <!-- </exclusion>-->
</exclusions> <!-- </exclusions>-->
</dependency> </dependency>
<!-- web 容器使用 undertow 性能更强 --> <!-- web 容器使用 undertow 性能更强 -->
<dependency> <!-- <dependency>-->
<groupId>org.springframework.boot</groupId> <!-- <groupId>org.springframework.boot</groupId>-->
<artifactId>spring-boot-starter-undertow</artifactId> <!-- <artifactId>spring-boot-starter-undertow</artifactId>-->
</dependency> <!-- </dependency>-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -1,8 +1,8 @@
package com.ruoyi.common.web.config; package com.ruoyi.common.web.config;
import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.SpringUtils;
import io.undertow.server.DefaultByteBufferPool; //import io.undertow.server.DefaultByteBufferPool;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo; //import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.server.WebServerFactoryCustomizer;
@ -14,7 +14,7 @@ import java.util.concurrent.Executors;
* *
* @author Lion Li * @author Lion Li
*/ */
@AutoConfiguration //@AutoConfiguration
public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> { public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
/** /**
@ -23,16 +23,16 @@ public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServle
@Override @Override
public void customize(UndertowServletWebServerFactory factory) { public void customize(UndertowServletWebServerFactory factory) {
// 默认不直接分配内存 如果项目中使用了 websocket 建议直接分配 // 默认不直接分配内存 如果项目中使用了 websocket 建议直接分配
factory.addDeploymentInfoCustomizers(deploymentInfo -> { // factory.addDeploymentInfoCustomizers(deploymentInfo -> {
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo(); // WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 512)); // webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 512));
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo); // deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
// 启用JAVA21虚拟线程 // // 启用JAVA21虚拟线程
if (SpringUtils.getProperty("spring.threads.virtual.enabled", Boolean.class, false)) { // if (SpringUtils.getProperty("spring.threads.virtual.enabled", Boolean.class, false)) {
deploymentInfo.setExecutor(Executors.newVirtualThreadPerTaskExecutor()); // deploymentInfo.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
} // }
//
}); // });
} }
} }

View File

@ -2,5 +2,4 @@ com.ruoyi.common.web.config.CaptchaConfig
com.ruoyi.common.web.config.FilterConfig com.ruoyi.common.web.config.FilterConfig
com.ruoyi.common.web.config.I18nConfig com.ruoyi.common.web.config.I18nConfig
com.ruoyi.common.web.config.ResourcesConfig com.ruoyi.common.web.config.ResourcesConfig
com.ruoyi.common.web.config.UndertowConfig
com.ruoyi.common.web.config.RepeatSubmitConfig com.ruoyi.common.web.config.RepeatSubmitConfig

View File

@ -16,20 +16,20 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<!-- 移除掉默认支持的 Tomcat --> <!-- &lt;!&ndash; 移除掉默认支持的 Tomcat &ndash;&gt;-->
<exclusions> <!-- <exclusions>-->
<exclusion> <!-- <exclusion>-->
<groupId>org.springframework.boot</groupId> <!-- <groupId>org.springframework.boot</groupId>-->
<artifactId>spring-boot-starter-tomcat</artifactId> <!-- <artifactId>spring-boot-starter-tomcat</artifactId>-->
</exclusion> <!-- </exclusion>-->
</exclusions> <!-- </exclusions>-->
</dependency> </dependency>
<!-- undertow --> <!-- &lt;!&ndash; undertow &ndash;&gt;-->
<dependency> <!-- <dependency>-->
<groupId>org.springframework.boot</groupId> <!-- <groupId>org.springframework.boot</groupId>-->
<artifactId>spring-boot-starter-undertow</artifactId> <!-- <artifactId>spring-boot-starter-undertow</artifactId>-->
</dependency> <!-- </dependency>-->
<!-- spring security 安全认证 --> <!-- spring security 安全认证 -->
<dependency> <dependency>

View File

@ -3,7 +3,7 @@ package com.ruoyi.monitor.admin.config;
import de.codecentric.boot.admin.server.config.EnableAdminServer; import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
import org.springframework.boot.task.TaskExecutorBuilder; //import org.springframework.boot.task.TaskExecutorBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -16,16 +16,16 @@ import java.util.concurrent.Executor;
* *
* @author Lion Li * @author Lion Li
*/ */
@Configuration //@Configuration
@EnableAdminServer //@EnableAdminServer
public class AdminServerConfig { public class AdminServerConfig {
@Lazy // @Lazy
@Bean(name = TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME) // @Bean(name = TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME)
@ConditionalOnMissingBean(Executor.class) // @ConditionalOnMissingBean(Executor.class)
public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) { // public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) {
return builder.build(); // return builder.build();
} // }
} }