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 缂撳啿绌洪棿

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊

  • 鍏跺疄绫讳技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 婊戝姩绐楀彛

锛?锛夊彂閫佹柟婊戝姩绐楀彛绀烘剰鍥撅細

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊

  • #1 宸叉敹鍒癆CK纭鐨勬暟鎹?/p>

  • #2 宸插彂閫佸埌鏈敹鍒癆CK纭鐨勬暟鎹?/p>

  • #3 鍦ㄧ獥鍙d腑鏈彂鍑虹殑锛堟帴鏀舵柟杩樻湁绌洪棿锛?/p>

  • #4 绐楀彛浠ュ鐨勬暟鎹紙鎺ユ敹鏂规病鏈夌┖闂达級

  • 鍏朵腑#2 + #3鐨勯粦妗嗗氨鏄?span>婊戝姩绐楀彛

锛?锛夊彂閫佹柟婊戝姩鍚庣殑婊戝姩绐楀彛绀烘剰鍥撅細

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊

  • 绾㈣壊鏄凡缁?span>鏂版敹鍒癆CK鐨勬暟鎹?/p>

  • 缁胯壊鏄?span>鏂板姞鍏ユ粦鍔ㄧ獥鍙?/strong>鐨勬暟鎹?/p>

锛?锛夋帴鏀剁鎺у埗鍙戦€佺鐨勫浘绀猴細

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊

锛?锛塟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>

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊

3.3 闃诲閬垮厤绠楁硶

  • 涓€鑸潵璇磗sthresh鐨勫€兼槸65535锛屽崟浣嶆槸瀛楄妭锛屽綋cwnd杈惧埌杩欎釜鍊兼椂鍚?/p>

  • 绠楁硶娴佺▼锛?/p>

    • 鏀跺埌涓€涓狝CK鏃讹紝cwnd = cwnd + 1/cwnd

    • 姣忚繃涓€涓猂TT鏃讹紝cwnd = cwnd + 1

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊

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>

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊

鍙傝€冿細https://coolshell.cn/articles/11609.html

https://www.cnblogs.com/linzhanfly/p/9969201.html

  

-娣卞叆鍘熺悊-  

   鐭ュ叾鐒跺苟鐭ュ叾鎵€浠ョ劧    

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊



以上是关于TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊的主要内容,如果未能解决你的问题,请参考以下文章

TypeScript浠庨浂鍒颁竴瀛︿範璁板綍锛堜笁锛氬嚱鏁帮級

python dlib瀛︿範锛堜簲锛夛細姣斿浜鸿劯

SuSE涓婅繍琛孧yCat锛堜簩锛夛細閰嶇疆鍗曠偣MyCat

銆怬racle Database銆慜racle RAC锛堜節锛夛細绠$悊宸ュ叿--crsctl & srvctl

HANA SQL Script瀛︿範锛?锛夛細Orchestration Logic

鏈哄櫒瀛︿範瀹炴垬锛?锛夛細鏀寔鍚戦噺鏈猴紙涓嬶級