- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > 編程語(yǔ)言 >
- SpringBoot內置tomcat調優(yōu)測試優(yōu)化
怎么配置springBoot 內置tomcat,才能使得自己的服務(wù)效率更高呢?
Spring Boot 能支持的最大并發(fā)量主要看其對Tomcat的設置,可以在配置文件中對其進(jìn)行更改。我們可以看到默認設置中,Tomcat的最大線(xiàn)程數是200,最大連接數是10000。 這個(gè)不同SpringBoot 版本可能有所細微差別。本文測試基于Springboot 2.0.7.RELEASE
/** * Maximum amount of worker threads. */ private int maxThreads = 200; /** * Minimum amount of worker threads. */ private int minSpareThreads = 10; /** * Maximum size in bytes of the HTTP post content. */ private int maxHttpPostSize = 2097152; /** * Maximum size in bytes of the HTTP message header. */ private int maxHttpHeaderSize = 0; /** * Whether requests to the context root should be redirected by appending a / to * the path. */ private Boolean redirectContextRoot = true; /** * Whether HTTP 1.1 and later location headers generated by a call to sendRedirect * will use relative or absolute redirects. */ private Boolean useRelativeRedirects; /** * Character encoding to use to decode the URI. */ private Charset uriEncoding = StandardCharsets.UTF_8; /** * Maximum number of connections that the server accepts and processes at any * given time. Once the limit has been reached, the operating system may still * accept connections based on the "acceptCount" property. */ private int maxConnections = 10000; /** * Maximum queue length for incoming connection requests when all possible request * processing threads are in use. */ private int acceptCount = 100;
通過(guò)我們查看源碼得知了(org.springframework.boot.autoconfigure.web.ServerProperties)springBoot 內置tomcat 默認配置,現在我們?yōu)榱嗽诒镜伢w現出效果,我們將配置參數有意調小配置如下進(jìn)行壓測,同時(shí)將壓測接口中設置sleep(2000) 模擬線(xiàn)程沒(méi)有釋放。
tomcat: #最小線(xiàn)程數 min-spare-threads: 5 #最大線(xiàn)程數 max-threads: 5 #最大鏈接數 max-connections: 5 #最大等待隊列長(cháng)度 accept-count: 1
該配置對應壓測
通過(guò)壓測100并發(fā) 發(fā)現異常達到了85% 由于我們配置ReadTimeout 和ConnectTimeout 配置2秒 100個(gè)線(xiàn)程同時(shí)達到,處理最大線(xiàn)程才1,排隊也是1 導致一個(gè)是沒(méi)有線(xiàn)程處理請求導致超時(shí)一個(gè)是排不上隊別拒絕。當我按照本機cup 合理配置后看看壓測情況。優(yōu)化配置如下:
tomcat: #最小線(xiàn)程數 min-spare-threads: 100 #最大線(xiàn)程數 max-threads: 600 #最大鏈接數 max-connections: 10000 #最大等待隊列長(cháng)度 accept-count: 1000
如上圖 同樣是100并發(fā) 異常率為0 全部通過(guò),響應時(shí)間也是減除sleep(2000) 大多數都是10毫秒內。優(yōu)化效果可見(jiàn)顯著(zhù)。
到此這篇關(guān)于SpringBoot內置tomcat調優(yōu)測試優(yōu)化的文章就介紹到這了,更多相關(guān)SpringBoot內置tomcat調優(yōu)測試內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站