TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊
Posted 娣卞叆鍘熺悊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊相关的知识,希望对你有一定的参考价值。
鐐瑰嚮馃憜钃濊壊鈥?nbsp;娣卞叆鍘熺悊鈥濓紝鍏虫敞骞垛€?/span>璁句负鏄熸爣鈥?/span>
鎶€鏈共璐э紝绗竴鏃堕棿鎺ㄩ€?/span>
1 RTT绠楁硶
1.1 姒傝堪
涓婁竴鑺傝浜嗛噸浼犳満鍒堕渶瑕佽缃竴涓噸浼犺秴鏃跺€硷紙RTO锛孯etransmission TimeOut锛夛紝RTO璁鹃暱浜嗭紝閲嶅彂澶參锛涜鐭簡锛屽彲鑳藉鑷村寘娌℃湁涓紝灏遍噸鍙戜簡锛屽彲鑳藉鑷撮洩宕╂晥搴旓紙閲嶅彂澶氾紝澶辫触澶氾紝澶辫触澶氾紝瀵艰嚧鏇村鐨勯噸鍙?..璇峰弬鑰冿細 鏆撮闂ㄤ簨浠讹級銆?/p>
閭d箞璇ュ€兼€庝箞璁剧疆锛?/p>
鐢变簬涓€寮€濮嬫棤娉曠‘瀹氳缃煇涓€硷紝鎵€浠ラ渶瑕佺▼搴忚嚜鍔ㄩ€傚簲锛屽姩鎬佸湴鍘昏缃?/p>
RTT锛孯ound Trip Time锛岃缃殑鍙傝€冨€间负鏁版嵁鎶ユ潵鍥炴墍闇€瑕佺殑鏃堕棿
1.2 缁忓吀绠楁硶
閲囨牱鏈€杩戝嚑娆$殑RTT
SRTT璁$畻锛圫moothed RTT锛夛細伪 (鍔犳潈绉诲姩骞冲潎)鍙栧€煎湪0.8 鍒?0.9涔嬮棿
$$
SRTT = ( 伪 * SRTT ) + ((1- 伪) * RTT)
$$璁$畻RTO锛歎BOUND涓烘渶澶TT锛堜笂闄愬€硷級锛孡BOUND涓烘渶灏廟TT锛堜笅闄愬€硷級锛屛?鍊间竴鑸湪1.3鍒?.0涔嬮棿
$$
RTO = min [ UBOUND, max [ LBOUND, (尾 * SRTT) ] ]
$$
1.3 Karn / Partridge 绠楁硶锛圫RTT绠楁硶鐨勪紭鍖栵級
缁忓吀绠楁硶鐨勯棶棰橈細
鍘熷 + 閲嶄紶 + ACK = 鎬绘椂闂翠綔涓篟TO锛岀畻闀夸簡锛堢壒娈婃儏鍐碉級
閲嶄紶 + ACK = 鎬绘椂闂翠綔涓篟TO锛岀畻鐭簡锛堢壒娈婃儏鍐碉級
璇ョ畻娉曠殑鏈€澶х壒鐐癸細蹇界暐閲嶄紶锛屼笉鎶婇噸浼犱綔涓洪噰鏍?/strong>
1.4 Jacobson / Karels 绠楁硶
蹇界暐閲嶄紶鐨勯棶棰橈細
鍦ㄦ煇涓€鏃堕棿锛岀綉缁滈棯鍔紝绐佺劧鍙樻參浜嗭紝浜х敓浜嗘瘮杈冨ぇ鐨勫欢鏃讹紝杩欎釜寤舵椂瀵艰嚧瑕侀噸浼犳墍鏈夌殑鍖咃紙RTO璁剧疆鐨勬瘮杈冨皬锛?/p>
浣嗘槸鐢变簬閲嶄紶涓嶄細閲嶆柊鏇存柊RTO锛屽鑷翠竴鐩翠涪鍖咃紝涓€鐩撮噸璇曚簡銆?/p>
SRTT绠楁硶浠ュ強浼樺寲閮介€冧笉鍑篟TT鏈変竴涓ぇ鐨勬尝鍔ㄧ殑璇濓紝寰堥毦琚彂鐜帮紝鎵€浠ラ渶瑕佺患鍚堣€冭檻銆?/p>
鍏紡锛?/p>
SRTT = SRTT + 伪 (RTT 鈥?SRTT) 鈥斺€?璁$畻骞虫粦RTT
DevRTT = (1-尾)DevRTT + 尾(|RTT-SRTT|) 鈥斺€旇绠楀钩婊慠TT鍜岀湡瀹炵殑宸窛锛堝姞鏉冪Щ鍔ㄥ钩鍧囷級
RTO= 碌 * SRTT + 鈭?*DevRTT 鈥斺€?绁炰竴鏍风殑鍏紡
# 鍦↙inux涓嬶紝伪 = 0.125锛屛?= 0.25锛?渭 = 1锛屸垈 = 4 鈥斺€?nobody knows why, it just work.
2 婊戝姩绐楀彛
2.1 姒傝堪
绗竴鑺傝杩嘥CP鍙潬鎬х殑淇濊瘉涔嬩竴灏辨槸娴侀噺鎺у埗锛團low Control锛?/strong>銆?/p>
TCP闇€瑕佺煡閬撶幇鍦ㄧ綉缁滅殑鏁版嵁澶勭悊閫熷害锛屾墠鑳芥洿濂介槻姝涪鍖咃紝鑰屾祦閲忔帶鍒跺氨鏄负浜嗘祴閲忕幇鍦ㄧ殑缃戠粶鏁版嵁澶勭悊閫熷害鐨勩€?/p>
TCP鎶ュご鏈変竴涓瓧娈碉細绐楀彛锛岃瀛楁鏄帴鏀剁鍛婄煡鍙戦€佺鑷繁鐨勭紦鍐茬┖闂达紝闃叉鍙戦€佺鍙戦€佸お蹇紦鍐插尯婧㈠嚭銆?/p>
2.2 缂撳啿绌洪棿
鍏跺疄绫讳技java鐨凬IO涓殑ByteBuffer
鍙戦€佺锛?/p>
LastByteWritten锛氫笂灞傚簲鐢ㄥ彲鍐欏叆鐨勪綅缃?/p>
LastByteSent锛氭鍦ㄥ彂閫佺殑浣嶇疆
LastByteAcked锛氬凡缁忔敹鍒癆CK鐨勪綅缃?/p>
LastByteAcked ~ LastByteSent鍖洪棿锛氳〃绀哄凡缁忓彂閫佷絾鏄湭鏀跺埌ACK鐨勬暟鎹?/p>
LastByteSent ~ LastByteWritten鍖洪棿锛氳〃绀烘湭鍙戦€佸嚭鍘荤殑鏁版嵁
鎺ユ敹绔?/strong>锛?/p>
LastByteRead锛歍CP缂撳啿鍖轰腑璇诲埌鐨勪綅缃?/p>
NextByteExpected锛氭敹鍒扮殑杩炵画鍖呯殑鏈€鍚庝竴涓綅缃?/p>
LastByteRcved锛氭敹鍒扮殑鍖呯殑鏈€鍚庝竴涓綅缃?/p>
NextByteExpected ~ LastByteRcved鍖洪棿锛氭湭鍒拌揪鐨勬暟鎹尯闂?/p>
LastByteRead ~ NextByteExpected鍖洪棿锛氬凡鏀跺埌鐨勬暟鎹尯闂?/p>
鎺ユ敹绔洖澶?/strong>锛?/p>
ACK涓細姹囨姤鑷繁鐨刉indow = MaxRcvBuffer 鈥?LastByteRcvd 鈥?1锛堝彧鍓╀笅杩欎箞澶氱殑绌洪棿鑳借鏂扮殑鏁版嵁锛?/p>
鍙戦€佹柟浼氭牴鎹獥鍙f潵鎺у埗鍙戦€佹暟鎹殑澶у皬锛屼互淇濊瘉鎺ユ敹鏂瑰彲浠ュ鐞?/p>
2.3 婊戝姩绐楀彛
锛?锛夊彂閫佹柟婊戝姩绐楀彛绀烘剰鍥撅細
#1 宸叉敹鍒癆CK纭鐨勬暟鎹?/p>
#2 宸插彂閫佸埌鏈敹鍒癆CK纭鐨勬暟鎹?/p>
#3 鍦ㄧ獥鍙d腑鏈彂鍑虹殑锛堟帴鏀舵柟杩樻湁绌洪棿锛?/p>
#4 绐楀彛浠ュ鐨勬暟鎹紙鎺ユ敹鏂规病鏈夌┖闂达級
鍏朵腑#2 + #3鐨勯粦妗嗗氨鏄?span>婊戝姩绐楀彛
锛?锛夊彂閫佹柟婊戝姩鍚庣殑婊戝姩绐楀彛绀烘剰鍥撅細
绾㈣壊鏄凡缁?span>鏂版敹鍒癆CK鐨勬暟鎹?/p>
缁胯壊鏄?span>鏂板姞鍏ユ粦鍔ㄧ獥鍙?/strong>鐨勬暟鎹?/p>
锛?锛夋帴鏀剁鎺у埗鍙戦€佺鐨勫浘绀猴細
锛?锛塟ero Window锛堝潥鎸佸畾鏃跺櫒瀹炵幇锛夛細
涓婂浘涓€涓鐞嗙紦鎱㈢殑Server灏咰lient鐨凾CP 婊戝姩绐楀彛缁欓檷鍒?.
闄嶅埌0涔嬪悗锛屽彂閫佺鍙戦€乑ero Window Probe鍖咃紙ZWP锛夌粰鎺ユ敹鏂癸紝璁╂帴鏀舵柟ACK瀹冪殑Window灏哄锛屼竴鑸彂閫?娆★紝姣忔30~60绉掋€?/p>
杩炵画3娆′负0锛屾湁浜汿CP Client灏嗗彂閫丷ST鎶婅繛鎺ユ柇寮€銆?/p>
锛?锛塖illy Window Syndrome锛堢硦娑傜獥鍙g患鍚堢棁锛?/h5>
鐢变簬澶勭悊缂撴參鐨凷erver鎶奣CP鎺ユ敹鏂圭殑婊戝姩绐楀彛涓嶆柇闄嶄綆锛屽鑷存粦鍔ㄧ獥鍙e緢灏戯紙濡傦細4涓瓧鑺傦級锛屾鏃跺彂閫佺浠嶇劧涔夋棤鍙嶉【鐨勫彂閫併€?/p>
MSS榛樿涓?36锛屾湁鏁堟暟鎹墠4涓瓧鑺傦紝甯﹀鍒╃敤鐜?%涓嶅埌锛岄€犳垚浜嗗法澶х殑娴垂銆?/p>
绐楀彛鏄负浜?span>鎺у埗浼犺緭杩囩▼涓殑閫熷害銆傝€孧SS鏄负浜?span>鎺у埗TCP鎶ユ枃娈靛ぇ灏?/strong>銆?/p>
MTU = MSS + TCP澶达紙20瀛楄妭锛?+IP澶达紙20瀛楄妭锛夈€?/p>
瑙e喅鏂规锛?/h5>
绛夊埌Window Size >= MSS 鎴栬€?Data Size >= MSS
鏀跺埌涔嬪墠鍙戦€佹暟鎹殑ACK鍖咃紝瀹冩墠浼氬彂閫佹暟鎹紝鍚﹁€呯户缁Н鏀掓暟鎹?/p>
闂鐢盧eceiver寮曡捣锛岄偅涔圧eceiver鏀跺埌鐨勬暟鎹鑷磜indow size(rwnd,receiver window)灏忎簬鏌愪釜鍊硷紝鍙互鐩存帴ack window size涓?缁橲ender锛岃繖鏍峰氨鎶妛indow鍏抽棴浜嗭紝涔熼樆姝ender鍐嶅彂鏁版嵁杩囨潵锛岀瓑鍒癛eceiver澶勭悊浜嗕竴浜涙暟鎹悗window size澶т簬绛変簬MSS鏃讹紝鎴栬€匯eceiver Buffer鏈変竴鑸负绌猴紙鍏蜂綋绛栫暐鏈夊緢澶氾級锛屽彲浠ユ妸window 鎵撳紑璁㏒ender鍙戦€佹暟鎹繃鏉ャ€?/p>
闂鐢盨ender寮曡捣锛屼娇鐢ㄥ欢鏃跺鐞嗭紝绂佹澶ч噺灏忓寘鍙戦€併€傦紙鎵撳紑涔嬪悗鏃犳硶浣跨敤telnet鎴栬€匰SH杩欑浜や簰鎬ф瘮杈冨己鐨勭▼搴?/strong>锛?/p>
3 闃诲澶勭悊
3.1 姒傝堪
鍓嶉潰璇磋繃缃戠粶娉㈠姩鏃讹紝TCP鎶ユ枃瓒呮椂锛屽紩璧烽噸浼狅紝浣嗘槸閲嶄紶瀵艰嚧缃戠粶璐熸媴鏇村ぇ锛屽彲鑳藉鑷寸綉缁滄洿鍔犵箒蹇欍€?/p>
鎵€浠CP涓嶄細杩欎箞鑷锛屽畠鍦ㄥ彂鐜伴樆濉炴椂锛屼細涓诲姩璁╄矾锛堝苟涓嶆槸鐩存帴鍋滄鍙戦€乀CP鎶ユ枃锛夈€?/p>
闃诲鎺у埗绠楁硶锛?/p>
鎱㈠惎鍔?/p>
闃诲閬垮厤
闃诲鍙戠敓鏃跺揩閫熼噸浼狅紙涓婁竴鑺傝杩囷級
蹇€熸仮澶?/p>
3.2 鎱㈠惎鍔ㄧ畻娉?/h4>
绋嬪簭鍒氬垰鍔犲叆缃戠粶鏃讹紝涓€鐐逛竴鐐规彁鍗囬€熷害銆?/p>
绠楁硶娴佺▼锛?/p>
杩炴帴寤哄ソ鐨勫紑濮嬪厛鍒濆鍖朿wnd = 1(绐楀彛)锛岃〃鏄庡彲浠ヤ紶涓€涓?span>MSS澶у皬鐨勬暟鎹?/p>
姣忓綋鏀跺埌涓€涓狝CK锛宑wnd++锛岀嚎鎬т笂鍗?/p>
姣忓綋杩囦簡涓€涓猂TT锛宑wnd = cwnd*2锛?鍛堟寚鏁颁笂鍗囥€?/p>
ssthresh锛坰low start threshold锛夛紝鏄竴涓笂闄愶紝褰揷wnd >= ssthresh鏃讹紝灏变細杩涘叆鈥滄嫢濉為伩鍏嶇畻娉曗€?/p>
鐢变簬澶勭悊缂撴參鐨凷erver鎶奣CP鎺ユ敹鏂圭殑婊戝姩绐楀彛涓嶆柇闄嶄綆锛屽鑷存粦鍔ㄧ獥鍙e緢灏戯紙濡傦細4涓瓧鑺傦級锛屾鏃跺彂閫佺浠嶇劧涔夋棤鍙嶉【鐨勫彂閫併€?/p>
MSS榛樿涓?36锛屾湁鏁堟暟鎹墠4涓瓧鑺傦紝甯﹀鍒╃敤鐜?%涓嶅埌锛岄€犳垚浜嗗法澶х殑娴垂銆?/p>
绐楀彛鏄负浜?span>鎺у埗浼犺緭杩囩▼涓殑閫熷害銆傝€孧SS鏄负浜?span>鎺у埗TCP鎶ユ枃娈靛ぇ灏?/strong>銆?/p>
MTU = MSS + TCP澶达紙20瀛楄妭锛?+IP澶达紙20瀛楄妭锛夈€?/p>
瑙e喅鏂规锛?/h5>
绛夊埌Window Size >= MSS 鎴栬€?Data Size >= MSS
鏀跺埌涔嬪墠鍙戦€佹暟鎹殑ACK鍖咃紝瀹冩墠浼氬彂閫佹暟鎹紝鍚﹁€呯户缁Н鏀掓暟鎹?/p>
闂鐢盧eceiver寮曡捣锛岄偅涔圧eceiver鏀跺埌鐨勬暟鎹鑷磜indow size(rwnd,receiver window)灏忎簬鏌愪釜鍊硷紝鍙互鐩存帴ack window size涓?缁橲ender锛岃繖鏍峰氨鎶妛indow鍏抽棴浜嗭紝涔熼樆姝ender鍐嶅彂鏁版嵁杩囨潵锛岀瓑鍒癛eceiver澶勭悊浜嗕竴浜涙暟鎹悗window size澶т簬绛変簬MSS鏃讹紝鎴栬€匯eceiver Buffer鏈変竴鑸负绌猴紙鍏蜂綋绛栫暐鏈夊緢澶氾級锛屽彲浠ユ妸window 鎵撳紑璁㏒ender鍙戦€佹暟鎹繃鏉ャ€?/p>
闂鐢盨ender寮曡捣锛屼娇鐢ㄥ欢鏃跺鐞嗭紝绂佹澶ч噺灏忓寘鍙戦€併€傦紙鎵撳紑涔嬪悗鏃犳硶浣跨敤telnet鎴栬€匰SH杩欑浜や簰鎬ф瘮杈冨己鐨勭▼搴?/strong>锛?/p>
鍓嶉潰璇磋繃缃戠粶娉㈠姩鏃讹紝TCP鎶ユ枃瓒呮椂锛屽紩璧烽噸浼狅紝浣嗘槸閲嶄紶瀵艰嚧缃戠粶璐熸媴鏇村ぇ锛屽彲鑳藉鑷寸綉缁滄洿鍔犵箒蹇欍€?/p>
鎵€浠CP涓嶄細杩欎箞鑷锛屽畠鍦ㄥ彂鐜伴樆濉炴椂锛屼細涓诲姩璁╄矾锛堝苟涓嶆槸鐩存帴鍋滄鍙戦€乀CP鎶ユ枃锛夈€?/p>
闃诲鎺у埗绠楁硶锛?/p>
鎱㈠惎鍔?/p>
闃诲閬垮厤
闃诲鍙戠敓鏃跺揩閫熼噸浼狅紙涓婁竴鑺傝杩囷級
蹇€熸仮澶?/p>
绋嬪簭鍒氬垰鍔犲叆缃戠粶鏃讹紝涓€鐐逛竴鐐规彁鍗囬€熷害銆?/p>
绠楁硶娴佺▼锛?/p>
杩炴帴寤哄ソ鐨勫紑濮嬪厛鍒濆鍖朿wnd = 1(绐楀彛)锛岃〃鏄庡彲浠ヤ紶涓€涓?span>MSS澶у皬鐨勬暟鎹?/p>
姣忓綋鏀跺埌涓€涓狝CK锛宑wnd++锛岀嚎鎬т笂鍗?/p>
姣忓綋杩囦簡涓€涓猂TT锛宑wnd = cwnd*2锛?鍛堟寚鏁颁笂鍗囥€?/p>
ssthresh锛坰low start threshold锛夛紝鏄竴涓笂闄愶紝褰揷wnd >= ssthresh鏃讹紝灏变細杩涘叆鈥滄嫢濉為伩鍏嶇畻娉曗€?/p>
3.3 闃诲閬垮厤绠楁硶
涓€鑸潵璇磗sthresh鐨勫€兼槸65535锛屽崟浣嶆槸瀛楄妭锛屽綋cwnd杈惧埌杩欎釜鍊兼椂鍚?/p>
绠楁硶娴佺▼锛?/p>
鏀跺埌涓€涓狝CK鏃讹紝cwnd = cwnd + 1/cwnd
姣忚繃涓€涓猂TT鏃讹紝cwnd = cwnd + 1
3.4 闃诲鐘舵€佹椂鐨勭畻娉?/h3>
褰撲涪鍖呯殑鏃跺€欙紝鏈変袱绉嶆儏鍐?/p>
绛夊埌RTO瓒呮椂锛岄噸浼犳暟鎹寘锛孴CP璁や负璇ユ儏鍐靛お绯熺硶浜?/p>
sshthreash = swnd / 2
cwnd 閲嶇疆涓?
杩涘叆鎱㈠惎鍔ㄧ畻娉?/strong>
蹇€熼噸浼犵畻娉曪紝鍗虫敹鍒?涓噸澶嶇殑ACK灏卞紑濮嬮噸浼狅紝鏃犻渶绛夊緟RTO瓒呮椂
cwnd = cwnd / 2
sshthresh = cwnd
杩涘叆蹇€熸仮澶嶇畻娉?/strong>鈥斺€擣ast Recovery
TCP Tahoe锛堜唬琛ㄧ増鏈級鐨勫疄鐜板拰RTO瓒呮椂涓€鏍枫€?/p>
TCP Reno鐨勫疄鐜帮細
3.5 蹇€熸仮澶嶇畻娉曪紙TCP Reno锛?/h3>
杩欓噷灏辫瑙CP Reno鐗堟湰鐨勫揩閫熸仮澶嶇畻娉曪紝鎯充簡瑙f洿澶氳鍙傝€冿細TCP 鐨勯偅浜涗簨鍎匡紙涓嬶級
绠楁硶娴佺▼锛?/p>
cwnd = sshthresh + 3 * MSS锛?鐨勬剰鎬濇槸纭鏈?涓暟鎹寘琚敹鍒颁簡锛?/p>
閲嶄紶Duplicated ACKs鎸囧畾鐨勬暟鎹寘
濡傛灉鍐嶆敹鍒?Duplicated ACKs锛岄偅涔坈wnd = cwnd +1
濡傛灉鏀跺埌浜嗘柊鐨凙ck锛岄偅涔堬紝cwnd = sshthresh 锛岀劧鍚庡氨杩涘叆浜嗘嫢濉為伩鍏嶇殑绠楁硶浜嗐€?/p>
缂虹偣锛氱敱浜?涓噸澶嶇殑ACKs锛屽苟涓嶄唬琛ㄥ彧涓簡涓€涓暟鎹寘锛涘鏋滀涪浜嗗涓暟鎹寘锛屽皢瀵艰嚧RTO銆?/p>
杩欓噷灏辫瑙CP Reno鐗堟湰鐨勫揩閫熸仮澶嶇畻娉曪紝鎯充簡瑙f洿澶氳鍙傝€冿細TCP 鐨勯偅浜涗簨鍎匡紙涓嬶級
绠楁硶娴佺▼锛?/p>
cwnd = sshthresh + 3 * MSS锛?鐨勬剰鎬濇槸纭鏈?涓暟鎹寘琚敹鍒颁簡锛?/p>
閲嶄紶Duplicated ACKs鎸囧畾鐨勬暟鎹寘
濡傛灉鍐嶆敹鍒?Duplicated ACKs锛岄偅涔坈wnd = cwnd +1
濡傛灉鏀跺埌浜嗘柊鐨凙ck锛岄偅涔堬紝cwnd = sshthresh 锛岀劧鍚庡氨杩涘叆浜嗘嫢濉為伩鍏嶇殑绠楁硶浜嗐€?/p>
缂虹偣锛氱敱浜?涓噸澶嶇殑ACKs锛屽苟涓嶄唬琛ㄥ彧涓簡涓€涓暟鎹寘锛涘鏋滀涪浜嗗涓暟鎹寘锛屽皢瀵艰嚧RTO銆?/p>
鍙傝€冿細https://coolshell.cn/articles/11609.html
https://www.cnblogs.com/linzhanfly/p/9969201.html
-娣卞叆鍘熺悊-
鐭ュ叾鐒跺苟鐭ュ叾鎵€浠ョ劧
以上是关于TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊的主要内容,如果未能解决你的问题,请参考以下文章
TypeScript浠庨浂鍒颁竴瀛︿範璁板綍锛堜笁锛氬嚱鏁帮級
SuSE涓婅繍琛孧yCat锛堜簩锛夛細閰嶇疆鍗曠偣MyCat
銆怬racle Database銆慜racle RAC锛堜節锛夛細绠$悊宸ュ叿--crsctl & srvctl