最近在工作中做一个实时推送的需求(消息不需要持久化,允许少量丢失),便使用了Redis的发布订阅模式来开发。顺带温习了一下Redis的相关操作。
Springboot内置Tomcat配置参数调优
默认配置
SpringBoot中如果使用内嵌Tomcat,那么内嵌Tomcat的默认配置在ServerProperties中。本文档以SpringBoot 2.5.0为例说明
包名
org.springframework.boot:spring-boot-autoconfigure:2.5.0
类
org.springframework.boot.autoconfigure.web.ServerProperties
/**
* 最大的工作线程数,默认为200,只能最多有200个耗时(比如查数据库)操作同时进行,一般小型应用中,达不到200个并发耗时操作.(4核 * 8g内存,线程数800,一般是核数*200。操作系统做线程之间的切换调度是有系统开销的,所以不是越多越好。)
*/
private int max = 200;
/**
* 最小工作线程数,默认为10,即初始化时会创建10个线程用于处理请求。
*/
private int minSpare = 10;
/**
* Tomcat在给定时间(同一时间)能接受的最大连接数。
*/
private int maxConnections = 8192;
/**
* 当前连接数超过maxConnections时,还能接受的连接的数量(排队的数量)
*/
private int acceptCount = 100;
内嵌Tomcat使用的默认协议为NIO,配置在TomcatServletWebServerFactory类中,如下:
public class TomcatServletWebServerFactory extends AbstractServletWebServerFactory
implements ConfigurableTomcatWebServerFactory, ResourceLoaderAware {
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
private static final Set<Class<?>> NO_CLASSES = Collections.emptySet();
/**
* The class name of default protocol used.协议的默认配置
*/
public static final String DEFAULT_PROTOCOL = "org.apache.coyote.http11.Http11NioProtocol";
private File baseDirectory;
........
}
优化配置如下:
server:
tomcat:
uri-encoding: UTF-8
#最大链接数
max-connections: 8192
#最大等待队列长度
accept-count: 500
threads:
#最大线程数
max: 800
#最小线程数
min-spare: 100
connection-timeout: 30000
port: 8080
引用