1. 程式人生 > >Spring boot 中 Undertow 配置執行緒數

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和記憶體的利用率達到最高?

PS:附執行緒查詢:Linux最大執行緒數限制及當前執行緒數查詢

查詢當前某程式的執行緒或程序數

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

pstree -p 3660 | wc -l