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和内存的利用率达到最高?

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

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

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

pstree -p 3660 | wc -l

--------------------------------------------------------------------------

这里引用网友Lovnx的回复,方便大家查找结果:

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

----------------------

分割线,今天看到了一篇CSDN涨粉秘诀,就是设置粉丝可见,默认点一下就可以了。相信看到这里的你已经成为我的粉丝了,哈哈,不过觉得内容不好,可以取关,或者给我留言建议,欢迎交流! 

更多推荐

Spring boot 中 Undertow 配置线程数