聊聊tomcat的connection-timeout

本文主要研究一下tomcat的connection-timeout

ServerProperties.Tomcat

org/springframework/boot/autoconfigure/web/ServerProperties.java

	public static class Tomcat {/*** Access log configuration.*/private final Accesslog accesslog = new Accesslog();/*** Thread related configuration.*/private final Threads threads = new Threads();/*** Tomcat base directory. If not specified, a temporary directory is used.*/private File basedir;/*** Delay between the invocation of backgroundProcess methods. If a duration suffix* is not specified, seconds will be used.*/@DurationUnit(ChronoUnit.SECONDS)private Duration backgroundProcessorDelay = Duration.ofSeconds(10);/*** Maximum size of the form content in any HTTP post request.*/private DataSize maxHttpFormPostSize = DataSize.ofMegabytes(2);/*** Maximum amount of request body to swallow.*/private DataSize maxSwallowSize = DataSize.ofMegabytes(2);/*** Whether requests to the context root should be redirected by appending a / to* the path. When using SSL terminated at a proxy, this property should be set to* false.*/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 = 8192;/*** Maximum queue length for incoming connection requests when all possible request* processing threads are in use.*/private int acceptCount = 100;/*** Maximum number of idle processors that will be retained in the cache and reused* with a subsequent request. When set to -1 the cache will be unlimited with a* theoretical maximum size equal to the maximum number of connections.*/private int processorCache = 200;/*** Comma-separated list of additional patterns that match jars to ignore for TLD* scanning. The special '?' and '*' characters can be used in the pattern to* match one and only one character and zero or more characters respectively.*/private List<String> additionalTldSkipPatterns = new ArrayList<>();/*** Comma-separated list of additional unencoded characters that should be allowed* in URI paths. Only "< > [ \ ] ^ ` { | }" are allowed.*/private List<Character> relaxedPathChars = new ArrayList<>();/*** Comma-separated list of additional unencoded characters that should be allowed* in URI query strings. Only "< > [ \ ] ^ ` { | }" are allowed.*/private List<Character> relaxedQueryChars = new ArrayList<>();/*** Amount of time the connector will wait, after accepting a connection, for the* request URI line to be presented.*/private Duration connectionTimeout;/*** Static resource configuration.*/private final Resource resource = new Resource();/*** Modeler MBean Registry configuration.*/private final Mbeanregistry mbeanregistry = new Mbeanregistry();/*** Remote Ip Valve configuration.*/private final Remoteip remoteip = new Remoteip();//......}	

springboot的ServerProperties.Tomcat定義了connectionTimeout屬性,用于指定接受連接之后等待uri的時間

customizeConnectionTimeout

org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

	private void customizeConnectionTimeout(ConfigurableTomcatWebServerFactory factory, Duration connectionTimeout) {factory.addConnectorCustomizers((connector) -> {ProtocolHandler handler = connector.getProtocolHandler();if (handler instanceof AbstractProtocol) {AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;protocol.setConnectionTimeout((int) connectionTimeout.toMillis());}});}

customizeConnectionTimeout將connectionTimeout寫入到AbstractProtocol

AbstractProtocol

org/apache/coyote/AbstractProtocol.java

    public void setConnectionTimeout(int timeout) {endpoint.setConnectionTimeout(timeout);}

AbstractProtocol將timeout設置到endpoint

AbstractEndpoint

org/apache/tomcat/util/net/AbstractEndpoint.java

	public void setConnectionTimeout(int soTimeout) { socketProperties.setSoTimeout(soTimeout); }/*** Keepalive timeout, if not set the soTimeout is used.*/private Integer keepAliveTimeout = null;public int getKeepAliveTimeout() {if (keepAliveTimeout == null) {return getConnectionTimeout();} else {return keepAliveTimeout.intValue();}}

AbstractEndpoint將timeout設置到socketProperties的soTimeout,另外它的getKeepAliveTimeout方法在keepAliveTimeout為null的時候,使用的是getConnectionTimeout

Http11Processor

org/apache/coyote/http11/Http11Processor.java

    public SocketState service(SocketWrapperBase<?> socketWrapper)throws IOException {RequestInfo rp = request.getRequestProcessor();rp.setStage(org.apache.coyote.Constants.STAGE_PARSE);// Setting up the I/OsetSocketWrapper(socketWrapper);// FlagskeepAlive = true;openSocket = false;readComplete = true;boolean keptAlive = false;SendfileState sendfileState = SendfileState.DONE;while (!getErrorState().isError() && keepAlive && !isAsync() && upgradeToken == null &&sendfileState == SendfileState.DONE && !protocol.isPaused()) {// Parsing the request headertry {if (!inputBuffer.parseRequestLine(keptAlive, protocol.getConnectionTimeout(),protocol.getKeepAliveTimeout())) {if (inputBuffer.getParsingRequestLinePhase() == -1) {return SocketState.UPGRADING;} else if (handleIncompleteRequestLineRead()) {break;}}//......}//......}//......}          

Http11Processor的service方法在執行inputBuffer.parseRequestLine時傳入了keptAlive、protocol.getConnectionTimeout()、protocol.getKeepAliveTimeout()參數

小結

springboot提供了tomcat的connection-timeout參數配置,其配置的是socket timeout,不過springboot沒有提供對keepAliveTimeout的配置,它默認是null,讀取的是connection timeout的配置。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/164764.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/164764.shtml
英文地址,請注明出處:http://en.pswp.cn/news/164764.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

github批量倉庫克隆,git clone某個用戶的所有倉庫

利用github的api工具&#xff0c; 首先拿到用戶名為kevin的所有倉庫的url&#xff1a; curl "https://api.github.com/users/kevin/repos?per_page100&&page1" | grep -w clone_url >clone.txt過濾一下&#xff1a; grep -o https://[^"]* clone…

DM8單點_閃回查詢報錯flashback version has been out of date

問題描述 誤操作后&#xff0c;閃回查詢到某一時間點提示:“[-9801]:flashback version has been out of date.” SQL> SELECT * FROM PERSON_TYPE WHEN TIMESTAMP 2023-11-23 18:51:41; SELECT * FROM PERSON_TYPE WHEN TIMESTAMP 2023-11-23 18:51:41; [-9801]:flashbac…

redis運維(十九)redis 的擴展應用 lua(一)

一 redis 的擴展應用 lua redis如何保證原子操作 說明&#xff1a;引入lua腳本,核心解決原子性問題 ① redis為什么引入lua? lua腳本本身體積小,啟動速度快 ② redis引入lua的優勢 小結&#xff1a; 類似自定義redis命令 ③ redis中如何使用lua ④ EVAL 說明&#…

性能測試的指南:測試類型、性能測試步驟、最佳實踐等!

近期公司為了節省成本搞了一波機房遷移&#xff0c;整合了一些南美部署架構。有一些上google云和有些下阿里云等大的調整。 在做機房遷移項目當中就需要思考如何進行性能測試&#xff0c;這種大的機房遷移SRE&#xff08;運維&#xff09;會針對組件會做一些單組件的性能測試&a…

【深度學習】參數優化和訓練技巧

尋找合適的學習率(learning rate) 學習率是一個非常非常重要的超參數&#xff0c;這個參數呢&#xff0c;面對不同規模、不同batch-size、不同優化方式、不同數據集&#xff0c;其最合適的值都是不確定的&#xff0c;我們無法光憑經驗來準確地確定lr的值&#xff0c;我們唯一可…

6.2.SDP協議

那今天呢&#xff1f;我們來介紹一下sdp協議&#xff0c;那實際上呢&#xff1f;sdp協議非常的簡單。我們如果拿到一個stp的文檔去看的話&#xff0c;那你要分閱里邊的所有的內容會覺得很枯燥&#xff0c;但實際上呢&#xff0c;如果我們按照這張圖所展示的結構去看stp的話。你…

Javascript每天一道算法題(十四)——合并數組區間_中等

文章目錄 1、問題2、示例3、解決方法&#xff08;0&#xff09;方法0——雙指針&#xff08;錯誤思路&#xff09;&#xff08;1&#xff09;方法1——雙指針&#xff08;正確&#xff09; 總結 1、問題 以數組 intervals 表示若干個區間的集合&#xff0c;其中單個區間為 inte…

怎么讀一個網絡的代碼

1.網絡代碼怎么來的&#xff1f; 我想要實現一個功能&#xff0c;這個功能是輸入一張圖像&#xff0c;返回一個類別結果。 所以很明確就有三個部分&#xff0c;一個是接受圖像輸入&#xff0c;一個是處理圖像得到處理結果&#xff0c;一個是對處理結果判斷生成結果。 現在想要使…

rocketmq 發送時異常:system busy 和 broker busy 解決方案

之前寫的解決方案,都是基于測試環境測試的.到生產環境之后,正常使用沒有問題,生產環境壓測時,又出現了system busy異常(簡直崩潰).最后在rocketmq群里大佬指導下,終于解決(希望是徹底解決). 下面直接給出結果: 目前通過生產環境各種參數修改測試得出: broker busy異常: 可通…

Using PeopleCode in Application Engine Programs在應用引擎程序中使用PeopleCode

This section provides an overview of PeopleCode and Application Engine programs and discusses how to: 本節概述了PeopleCode和應用程序引擎程序&#xff0c;并討論了如何: Decide when to use PeopleCode.決定何時使用PeopleCode。Consider the program environment.考…

Java之《ATM自動取款機》(面向對象)

《JAVA編程基礎》項目說明 一、項目名稱&#xff1a; 基于JAVA控制臺版本銀行自動取款機 項目要求&#xff1a; 實現銀行自動取款機的以下基本操作功能&#xff1a;讀卡、取款、查詢。&#xff08;自動取款機中轉賬、修改密碼不作要求&#xff09; 具體要求&#xff1a; 讀卡…

基于SSM的校園奶茶點單管理系統

基于SSM的校園奶茶點單管理系統的設計與實現~ 開發語言&#xff1a;Java數據庫&#xff1a;MySQL技術&#xff1a;SpringMyBatisSpringMVC工具&#xff1a;IDEA/Ecilpse、Navicat、Maven 系統展示 主頁 奶茶列表 登錄界面 管理員界面 用戶界面 摘要 隨著社會的發展和科技的進…

ubuntu搭建phpmyadmin+wordpress

Ubuntu搭建phpmyadmin wordpress Linux系統設置&#xff1a;Ubuntu 22配置apache2搭建phpmyadmin配置Nginx環境&#xff0c;搭建wordpress Linux系統設置&#xff1a;Ubuntu 22 配置apache2 安裝apache2 sudo apt -y install apache2設置端口號為8080 sudo vim /etc/apache…

paddle detection 訓練參數

#####################################基礎配置##################################### # 檢測算法使用YOLOv3,backbone使用MobileNet_v1,數據集使用roadsign_voc的配置文件模板,本配置文件默認使用單卡,單卡的batch_size=1 # 檢測模型的名稱 architecture: YOLOv3 # 根據…

【CCF-PTA】第03屆Scratch第05題 -- 統計出現次數最多的字

統計出現次數最多的字 【題目描述】 我國自古流傳下來不少膾炙人口的詩歌&#xff0c;各具特色&#xff0c;別具一格。有些詩只用寥寥幾個字&#xff0c;就能描繪出生動的意境。 請找出以下詩篇中出現次數最多的字&#xff0c;如果有多個字出現次數相同&#xff0c;則答案為…

Java中基于SSM框架的數據保存方法與日期處理

? 一、詳解 在SSM框架中&#xff0c;保存數據通常涉及到服務層和數據訪問層。服務層處理業務邏輯&#xff0c;而數據訪問層負責與數據庫進行交互。 二、代碼 Override public void save(Student student) { Date date new Date(); SimpleDateFormat format new Sim…

什么是LLC電路?

LLC電路是由2個電感和1個電容構成的諧振電路&#xff0c;故稱之為LLC&#xff1b; LLC電路主要由三個元件組成&#xff1a;兩個電感分別為變壓器一次側漏感(Lr)和勵磁電感(Lm)&#xff0c;電容為變壓器一次側諧振電容(Cr)。這些元件構成了一個諧振回路&#xff0c;其中輸入電感…

【C/PTA】函數專項練習(四)

本文結合PTA專項練習帶領讀者掌握函數&#xff0c;刷題為主注釋為輔&#xff0c;在代碼中理解思路&#xff0c;其它不做過多敘述。 目錄 6-1 計算A[n]1/(1 A[n-1])6-2 遞歸實現順序輸出整數6-3 自然數的位數(遞歸版)6-4 分治法求解金塊問題6-5 漢諾塔6-6 重復顯示字符(遞歸版)…

字母異位詞分組

給你一個字符串數組&#xff0c;請你將 字母異位詞 組合在一起。可以按任意順序返回結果列表。 字母異位詞 是由重新排列源單詞的所有字母得到的一個新單詞。 示例 1: 輸入: strs [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”] 輸出: [[“bat”],[“nat”,“tan…

Android MemoryFile 共享內存

應用場景&#xff1a; 跨進程傳輸大數據&#xff0c;如文件、圖片等&#xff1b; 技術選型&#xff1a; 共享內存–MemoryFile&#xff1b; 優點&#xff1a; 1. 共享內存沒有傳輸大小限制&#xff0c;所以和應用總的分配內存一樣&#xff08;512MB&#xff09;&#xff1…