SpringBoot內(nèi)置tomcat調(diào)優(yōu)測(cè)試優(yōu)化
問(wèn)題
怎么配置springBoot 內(nèi)置tomcat,才能使得自己的服務(wù)效率更高呢?
基礎(chǔ)配置
Spring Boot 能支持的最大并發(fā)量主要看其對(duì)Tomcat的設(shè)置,可以在配置文件中對(duì)其進(jìn)行更改。我們可以看到默認(rèn)設(shè)置中,Tomcat的最大線程數(shù)是200,最大連接數(shù)是10000。 這個(gè)不同SpringBoot 版本可能有所細(xì)微差別。本文測(cè)試基于Springboot 2.0.7.RELEASE
默認(rèn)配置
/** * 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;
測(cè)試步驟
通過(guò)我們查看源碼得知了(org.springframework.boot.autoconfigure.web.ServerProperties)springBoot 內(nèi)置tomcat 默認(rèn)配置,現(xiàn)在我們?yōu)榱嗽诒镜伢w現(xiàn)出效果,我們將配置參數(shù)有意調(diào)小配置如下進(jìn)行壓測(cè),同時(shí)將壓測(cè)接口中設(shè)置sleep(2000) 模擬線程沒(méi)有釋放。
tomcat:
#最小線程數(shù)
min-spare-threads: 5
#最大線程數(shù)
max-threads: 5
#最大鏈接數(shù)
max-connections: 5
#最大等待隊(duì)列長(zhǎng)度
accept-count: 1
該配置對(duì)應(yīng)壓測(cè)

通過(guò)壓測(cè)100并發(fā) 發(fā)現(xiàn)異常達(dá)到了85% 由于我們配置ReadTimeout 和ConnectTimeout 配置2秒 100個(gè)線程同時(shí)達(dá)到,處理最大線程才1,排隊(duì)也是1 導(dǎo)致一個(gè)是沒(méi)有線程處理請(qǐng)求導(dǎo)致超時(shí)一個(gè)是排不上隊(duì)別拒絕。當(dāng)我按照本機(jī)cup 合理配置后看看壓測(cè)情況。優(yōu)化配置如下:
tomcat:
#最小線程數(shù)
min-spare-threads: 100
#最大線程數(shù)
max-threads: 600
#最大鏈接數(shù)
max-connections: 10000
#最大等待隊(duì)列長(zhǎng)度
accept-count: 1000

如上圖 同樣是100并發(fā) 異常率為0 全部通過(guò),響應(yīng)時(shí)間也是減除sleep(2000) 大多數(shù)都是10毫秒內(nèi)。優(yōu)化效果可見(jiàn)顯著。
到此這篇關(guān)于SpringBoot內(nèi)置tomcat調(diào)優(yōu)測(cè)試優(yōu)化的文章就介紹到這了,更多相關(guān)SpringBoot內(nèi)置tomcat調(diào)優(yōu)測(cè)試內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringBoot內(nèi)置tomcat參數(shù)調(diào)優(yōu)的實(shí)現(xiàn)
- Springboot內(nèi)置Tomcat配置參數(shù)調(diào)優(yōu)方式
- springboot內(nèi)置的tomcat支持最大的并發(fā)量問(wèn)題
- springboot內(nèi)置tomcat調(diào)優(yōu)并發(fā)線程數(shù)解析
- SpringBoot內(nèi)置tomcat啟動(dòng)原理詳解
- Springboot內(nèi)置tomcat配置虛擬路徑過(guò)程解析
- springboot查看和修改內(nèi)置tomcat版本的方法步驟
相關(guān)文章
SpringBoot內(nèi)嵌Tomcat臨時(shí)目錄問(wèn)題及解決
這篇文章主要介紹了SpringBoot內(nèi)嵌Tomcat臨時(shí)目錄問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04
Java?Web項(xiàng)目中解決中文亂碼方法總結(jié)(三種最新方法)
這篇文章主要介紹了Java?Web項(xiàng)目中解決中文亂碼方法總結(jié),本文給大家分享三種最新解決方法,需要的朋友可以參考下2022-06-06
SpringBoot @ComponentScan掃描的局限性方式
文章總結(jié):SpringBoot的@ComponentScan注解在掃描組件時(shí)存在局限性,只能掃描指定的包及其子包,無(wú)法掃描@SpringBootApplication注解自動(dòng)配置的組件,使用@SpringBootApplication注解可以解決這一問(wèn)題,它集成了@Configuration、@EnableAutoConfiguration2025-01-01
如何在Maven項(xiàng)目中運(yùn)行JUnit5測(cè)試用例實(shí)現(xiàn)
這篇文章主要介紹了如何在Maven項(xiàng)目中運(yùn)行JUnit5測(cè)試用例實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04

