• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            loop_in_codes

            低調(diào)做技術(shù)__歡迎移步我的獨(dú)立博客 codemaro.com 微博 kevinlynx

            tcp要點(diǎn)學(xué)習(xí)-數(shù)據(jù)發(fā)送一

            Author : Kevin Lynx

            1. 什么是delayed ack algorithm
               delayed ack algorithm也就是<TCP/IP詳解>中所謂的"經(jīng)受時(shí)延的確認(rèn)"(翻譯得真饒舌 = =||)。在RFC1122中提到delayed ack
               的概念:
              

              "
                  A host that is receiving a stream of TCP data segments can
                  increase efficiency 
            in both the Internet and the hosts by
                  sending fewer than one ACK (acknowledgment) segment per data
                  segment received; 
            this is known as a "delayed ACK" [TCP:5].
                
            "


               我在之前提到過,TCP在收到每一個(gè)數(shù)據(jù)包時(shí),都會(huì)發(fā)送一個(gè)ACK報(bào)文給對(duì)方,用以告訴對(duì)方"我接收到你剛才發(fā)送的數(shù)據(jù)了"。并
               且會(huì)在報(bào)文的確認(rèn)號(hào)字段中標(biāo)志希望接收到的數(shù)據(jù)包。

               但是,如你所想,如果為每一個(gè)接收到的報(bào)文都發(fā)送一個(gè)ACK報(bào)文,那將會(huì)增加網(wǎng)絡(luò)的負(fù)擔(dān)。于是,為了解決這個(gè)問題,delayed
               ack被提出。也就是說,實(shí)現(xiàn)了delayed ack的TCP,并不見得會(huì)對(duì)每一個(gè)接收到的數(shù)據(jù)包發(fā)送ACK確認(rèn)報(bào)文。

               實(shí)際情況是,TCP延遲發(fā)送這個(gè)ACK。延遲多久?<TCP/IP詳解>中說的是200ms,在RFC1122中說的則是500ms。delayed ack有時(shí)候
               還會(huì)附加到數(shù)據(jù)報(bào)文段一起發(fā)送,如果在延遲時(shí)間內(nèi)有報(bào)文段要發(fā)送的話,如果沒有,那么當(dāng)延遲時(shí)間到時(shí),就單獨(dú)發(fā)送ACK。

               在另一份文檔中,作者講到delayed ack的好處:
               a) to avoid the silly window syndrome;
               b) to allow ACKs to piggyback on a reply frame if one is ready to go when the stack decides to do the ACK;
               c) to allow the stack to send one ACK for several frames, if those frames arrive within the delay period.

               a) 所謂的糊涂窗口綜合癥(別人都這樣翻譯的,似乎有點(diǎn)搞笑:D)
               b) 將ACK與將要發(fā)送的數(shù)據(jù)報(bào)文一起發(fā)送
               c) 一個(gè)ack確認(rèn)多個(gè)報(bào)文段,如果這幾個(gè)報(bào)文段在延遲時(shí)間內(nèi)到達(dá)

            2. 什么是Nagle algoritm ?
               簡(jiǎn)而言之,nagle算法主要目的是減少網(wǎng)絡(luò)流量,當(dāng)你發(fā)送的數(shù)據(jù)包太小時(shí),TCP并不立即發(fā)送該數(shù)據(jù)包,而是緩存起來直到數(shù)據(jù)包
               到達(dá)一定大小后才發(fā)送。(improving the efficiency of TCP/IP networks by reducing the number of packets that need to
               be sent over the network.)

               關(guān)于這個(gè)算法,我覺得wikipedia上講的比較好。具體點(diǎn)說,當(dāng)上層提交數(shù)據(jù)給TCP時(shí),TCP覺得你的數(shù)據(jù)太小了(套用一般的例子,
               如果你要發(fā)送1一個(gè)字節(jié)的數(shù)據(jù),當(dāng)附加上TCP和IP頭后,數(shù)據(jù)包通常就會(huì)增加到41字節(jié),那么這顯然是低效的),就緩存你的數(shù)據(jù),
               當(dāng)數(shù)據(jù)緩存到一定長度后,如果之前發(fā)送的數(shù)據(jù)得到了ACK確認(rèn)且接收方有足夠空間容納數(shù)據(jù),就發(fā)送這些數(shù)據(jù),否則繼續(xù)等待。

               wikipedia上給了一段nagle的偽代碼:

            if there is new data to send
                 
            if the window size >= MSS and available data is >= MSS
                   send complete MSS segment now
                 
            else
                   
            if there is unconfirmed data still in the pipe
                     enqueue data 
            in the buffer until an acknowledge is received
                   
            else
                     send data immediately
                   end 
            if
                 end 
            if
               end 
            if 

               
               TCP socket提供了關(guān)閉nagle算法的接口,你可以通過TCP_NODELAY選項(xiàng)決定是否開啟該算法。不過MSDN上建議不要關(guān)閉此算法。如果
               你發(fā)送的數(shù)據(jù)不至于很小的話(<40byte),我也不建議你關(guān)閉。

            posted on 2008-05-22 15:42 Kevin Lynx 閱讀(3141) 評(píng)論(1)  編輯 收藏 引用 所屬分類: network

            評(píng)論

            # re: tcp要點(diǎn)學(xué)習(xí)-數(shù)據(jù)發(fā)送一[未登錄] 2012-06-06 16:42 春秋十二月

            交互式程序如telnet和rlogin是關(guān)閉nagle算法的典型應(yīng)用  回復(fù)  更多評(píng)論   

            久久国产精品99久久久久久老狼 | 中文字幕成人精品久久不卡 | 青青热久久综合网伊人| 久久精品亚洲精品国产色婷| 国产69精品久久久久9999| 欧美午夜A∨大片久久| 久久99国产精品尤物| 国产精品狼人久久久久影院| 亚洲国产精品无码久久| 精品99久久aaa一级毛片| 亚洲精品美女久久777777| yellow中文字幕久久网| 亚洲精品无码久久久久去q | 久久精品国产精品国产精品污| 国产99久久久久久免费看| 一本一本久久a久久综合精品蜜桃 一本一道久久综合狠狠老 | 久久美女人爽女人爽| 波多野结衣久久精品| 亚洲精品高清久久| 精品综合久久久久久888蜜芽| 久久久青草青青国产亚洲免观| 久久99毛片免费观看不卡| 久久精品国产99国产精品导航 | 久久婷婷五月综合成人D啪| 久久九色综合九色99伊人| 91精品国产高清91久久久久久| 亚洲国产成人乱码精品女人久久久不卡 | 日产精品99久久久久久| 欧美精品乱码99久久蜜桃| 久久久久99精品成人片三人毛片 | 综合人妻久久一区二区精品| 久久久99精品成人片中文字幕| 久久成人影院精品777| 精品熟女少妇av免费久久| 亚洲va国产va天堂va久久| 午夜不卡久久精品无码免费| 少妇无套内谢久久久久| 精品久久久久成人码免费动漫| 2021国产精品久久精品| 久久久久久国产精品美女| 久久精品国产清自在天天线|