1.查看进程使用情况
ps -ef | grep java ----查看进程号,30589
netstat -anp | grep 30589---查看该进程的使用情况
pstree -p 30589 | wc -l ----查看线程数
top -H -----查看CPU使用情况
[root@iZbp1dtm752cu7uoi7cj5fZ ~]# top -H
top - 21:24:17 up 4 days, 1:57, 2 users, load average: 0.00, 0.01, 0.05
Threads: 152 total, 1 running, 151 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.7 us, 0.3 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1882084 total, 66580 free, 521380 used, 1294124 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 1184892 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 51620 3892 2616 S 0.3 0.2 0:37.90 systemd
14012 mysql 20 0 1186092 91228 9156 S 0.3 4.8 0:23.60 mysqld
30598 root 20 0 2461020 365748 13416 S 0.3 19.4 0:49.64 java
2.修改tomcat默认配置
/META-INF/spring-configuration-metadata.json 文件中
server.tomcat.accept-count:100 等待队列长度
server.tomcat.max-connections:10000 最大可被连接数
server.tomcat.max-threads:200 最大工作线程数
server.tomcat.min-spare-threads:10 最小工作线程数
默认配置下,连接超过10000拒绝连接
默认配置下,触发请求超过200+100后拒绝处理
4G 8核最佳配置为 server.tomcat.max-threads=800,server.tomcat.min-spare-threads=100
修改完后,重启,发现线程数量上升了,之前32
[root@iZbp1dtm752cu7uoi7cj5fZ ~]# pstree -p 4203 | wc -l 115
3.定制化内嵌tomcat配置
有些配置没有提供给application.properties配置,需要使用WebServerFactoryCustomizer
@Component public class WebServerConfiguration implements WebServerFactoryCustomizer{ @Override public void customize(ConfigurableWebServerFactory factory) { // 使用工厂类提供的接口定制我们的tomcat connector server.context.xml文件中配置 // TODO Auto-generated method stub ((TomcatServletWebServerFactory)factory).addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override public void customize(Connector connector) { Http11NioProtocol protocol = (Http11NioProtocol)connector.getProtocolHandler(); // 定制化KeepAliveTimeout,30秒内没有请求则服务自动断开KeepAlive连接 protocol.setKeepAliveTimeout(30000); // 当客户端发送超过10000个请求后断开KeepAlive连接 protocol.setMaxKeepAliveRequests(10000); } }); } }