Spring boot 中 Undertow 配置线程数

Spring boot 弃用tomcat 作为内嵌服务器,转用undertow

configurations {
compile.exclude module: “spring-boot-starter-tomcat”
}
compile “org.springframework.boot:spring-boot-starter-undertow:$springBootVersion”
但是undertow 有一些设置

server:
undertow:
io-threads: 4
worker-threads: ?


io-threads 好理解,根据CPU有几核,就填写几。但是worker-threads呢?网上的都写的,根据服务器负载来填。测试过,如果不填写,默认最少会初始化24个线程,最多60个线程。但是60个线程的时候,CPU和内存的占用对于4核8G的配置来说,也没有占用多少。难道是要挨个去尝试?试试多少个线程的时候,能把CPU和内存的利用率达到最高?

默认值:ioThreads = Math.max(你的机器核数, 2); workerThreads = ioThreads * 8; 后者要看服务器最大支持的文件句柄数量,设太大应用都会启动失败的,结合你应用承担的体量来设置。

PS:附线程查询:Linux最大线程数限制及当前线程数查询

查询当前某程序的线程或进程数

pstree -p

1
ps -e | grep java | awk ‘{print $1}’
| wc -l

pstree -p 3660 | wc -l

作者:imHou
来源:CSDN
原文:https://blog.csdn.net/lovehouye/article/details/79205885
版权声明:本文为博主原创文章,转载请附上博文链接!