SpringBoot內(nèi)置tomcat調(diào)優(yōu)測(cè)試優(yōu)化
問題
怎么配置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è)試步驟
通過我們查看源碼得知了(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) 模擬線程沒有釋放。
tomcat: #最小線程數(shù) min-spare-threads: 5 #最大線程數(shù) max-threads: 5 #最大鏈接數(shù) max-connections: 5 #最大等待隊(duì)列長(zhǎng)度 accept-count: 1
該配置對(duì)應(yīng)壓測(cè)
通過壓測(cè)100并發(fā) 發(fā)現(xiàn)異常達(dá)到了85% 由于我們配置ReadTimeout 和ConnectTimeout 配置2秒 100個(gè)線程同時(shí)達(dá)到,處理最大線程才1,排隊(duì)也是1 導(dǎo)致一個(gè)是沒有線程處理請(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 全部通過,響應(yīng)時(shí)間也是減除sleep(2000) 大多數(shù)都是10毫秒內(nèi)。優(yōu)化效果可見顯著。
到此這篇關(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)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺談使用java實(shí)現(xiàn)阿里云消息隊(duì)列簡(jiǎn)單封裝
這篇文章主要介紹了淺談使用java實(shí)現(xiàn)阿里云消息隊(duì)列簡(jiǎn)單封裝,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03MyBatis中基于別名typeAliases的設(shè)置
這篇文章主要介紹了MyBatis中基于別名typeAliases的設(shè)置,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07spring的構(gòu)造函數(shù)注入屬性@ConstructorBinding用法
這篇文章主要介紹了關(guān)于spring的構(gòu)造函數(shù)注入屬性@ConstructorBinding用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12JAVA數(shù)據(jù)結(jié)構(gòu)之漢諾塔代碼實(shí)例
這篇文章主要介紹了JAVA數(shù)據(jù)結(jié)構(gòu)之漢諾塔,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04EasyExcel實(shí)現(xiàn)導(dǎo)入+各種數(shù)據(jù)校驗(yàn)功能
這篇文章主要介紹了EasyExcel實(shí)現(xiàn)導(dǎo)入+各種數(shù)據(jù)校驗(yàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-05-05淺談Java內(nèi)部類——靜態(tài)內(nèi)部類
這篇文章主要介紹了Java靜態(tài)內(nèi)部類的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)Java內(nèi)部類的相關(guān)知識(shí),感興趣的朋友可以了解下2020-08-08