在排查問題的過程中發現Connector對象有一個靜態代碼塊:
static {replacements.put("acceptCount", "backlog");replacements.put("connectionLinger", "soLinger");replacements.put("connectionTimeout", "soTimeout");replacements.put("rootFile", "rootfile");}
其中backlog在linux里可以通過man listen > listen.txt導出看到:
The backlog argument defines the maximum length to which the queue ofpending connections for sockfd may grow. If a connection requestarrives when the queue is full, the client may receive an error with anindication of ECONNREFUSED or, if the underlying protocol supportsretransmission, the request may be ignored so that a later reattempt atconnection succeeds
TCP連接過程中有三個結構分別用于保存:每一個客戶端的連接,握手成功的連接,正在握手中但尚未成功的連接。內核為任何一個給定的監聽套接口維護兩個隊列:1、未完成連接隊列(incomplete connection queue),每個這樣的SYN分節對應其中一項:已由某個客戶發出并到達服務器,而服務器正在等待完成相應的TCP三路握手過程。這些套接口處于SYN_RCVD狀態;2、已完成連接隊列(completed connection queue),每個已完成TCP三路握手過程的客戶對應其中一項。這些套接口處于ESTABLISHED狀態。
Now it specifies the queue length for completely establishedsockets waiting to be accepted, instead of the number of incompleteconnection requests. The maximum length of the queue for incompletesockets can be set using /proc/sys/net/ipv4/tcp_max_syn_backlog. Whensyncookies are enabled there is no logical maximum length and this set‐ting is ignored. See tcp(7) for more information.If the backlog argument is greater than the value in/proc/sys/net/core/somaxconn, then it is silently truncated to thatvalue; the default value in this file is 128. In kernels before2.4.25, this limit was a hard coded value, SOMAXCONN, with the value128.
backlog是調用listen方法時傳入的參數,指定可以握手成功的最大連接數量,但是對于linux如果這個值大于/proc/sys/net/core/somaxconn設置的值,將會取somaxconn的值替代它。所以要注意,somaxconn值如果設置的不夠大,Tomcat配置中的連接數值是不會起作用的,可以通過sysctl -w net.core.somaxconn=***來修改這個值;對應的/proc/sys/net/ipv4/tcp_max_syn_backlog設置的是最大未完成連接隊列的值,但是這個值會在/proc/sys/net/ipv4/tcp_syncookies是1的時候失效。具體實現過程可參考:http://blog.csdn.net/raintungli/article/details/37913765
soLinger用于指定socket在關閉TCP連接時如何操作。內核缺省close操作是立即返回,如果有數據殘留在套接口緩沖區中則系統將試著將這些數據發送給對方。自定義了這項設置可以選擇是緩沖區數據全部丟棄立即關閉、發送完或超時再關閉或延遲指定時間后關閉。參考:http://blog.csdn.net/factor2000/article/details/3929816
soTimeout用于指定數據超時時間,單位是毫秒,就是說在連續的數據傳輸過程中,兩個包之間可接受的最大間隔的時間,如果設置為0則認為不限制間隔時間。
rootfile由于和我的問題關系不大,所以暫時沒有細看,會在整理容器的時候看看。應該是指根文件系統,參考:http://www.eeskill.com/article/index/id/1358.html
==========================================================
咱最近用的github:https://github.com/saaavsaaa
微信公眾號:
?
?