• <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

            低調做技術__歡迎移步我的獨立博客 codemaro.com 微博 kevinlynx

            tcp要點學習-數據發送一

            Author : Kevin Lynx

            1. 什么是delayed ack algorithm
               delayed ack algorithm也就是<TCP/IP詳解>中所謂的"經受時延的確認"(翻譯得真饒舌 = =||)。在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在收到每一個數據包時,都會發送一個ACK報文給對方,用以告訴對方"我接收到你剛才發送的數據了"。并
               且會在報文的確認號字段中標志希望接收到的數據包。

               但是,如你所想,如果為每一個接收到的報文都發送一個ACK報文,那將會增加網絡的負擔。于是,為了解決這個問題,delayed
               ack被提出。也就是說,實現了delayed ack的TCP,并不見得會對每一個接收到的數據包發送ACK確認報文。

               實際情況是,TCP延遲發送這個ACK。延遲多久?<TCP/IP詳解>中說的是200ms,在RFC1122中說的則是500ms。delayed ack有時候
               還會附加到數據報文段一起發送,如果在延遲時間內有報文段要發送的話,如果沒有,那么當延遲時間到時,就單獨發送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) 所謂的糊涂窗口綜合癥(別人都這樣翻譯的,似乎有點搞笑:D)
               b) 將ACK與將要發送的數據報文一起發送
               c) 一個ack確認多個報文段,如果這幾個報文段在延遲時間內到達

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

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

               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提供了關閉nagle算法的接口,你可以通過TCP_NODELAY選項決定是否開啟該算法。不過MSDN上建議不要關閉此算法。如果
               你發送的數據不至于很小的話(<40byte),我也不建議你關閉。

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

            評論

            # re: tcp要點學習-數據發送一[未登錄] 2012-06-06 16:42 春秋十二月

            交互式程序如telnet和rlogin是關閉nagle算法的典型應用  回復  更多評論   

            日韩欧美亚洲综合久久影院Ds | 精品久久久久久无码中文字幕| 久久福利青草精品资源站免费| 精品国产福利久久久| 久久精品成人欧美大片| 国产成人精品三上悠亚久久| 精品久久久久久| 九九精品久久久久久噜噜| 日本人妻丰满熟妇久久久久久| 久久免费精品视频| 亚洲乱码精品久久久久..| 国产精品久久久99| 久久综合给合久久国产免费| 久久97久久97精品免视看| 久久精品亚洲精品国产色婷| 九九久久精品无码专区| .精品久久久麻豆国产精品 | 99久久超碰中文字幕伊人| 大香网伊人久久综合网2020| 久久SE精品一区二区| 久久久久国产精品嫩草影院| 久久久无码精品亚洲日韩蜜臀浪潮| 精品久久人人爽天天玩人人妻| 久久久久久毛片免费播放| 亚洲精品WWW久久久久久 | 国产AⅤ精品一区二区三区久久| 亚洲中文字幕久久精品无码APP| 久久久久黑人强伦姧人妻| 国产欧美久久久精品| 九九久久自然熟的香蕉图片| 久久无码中文字幕东京热| 久久av高潮av无码av喷吹| 久久久中文字幕| 久久精品嫩草影院| 国产欧美久久久精品| 久久精品成人免费看| 成人资源影音先锋久久资源网| 久久99国产精品尤物| 97久久国产亚洲精品超碰热| 久久久久久亚洲Av无码精品专口| 亚洲中文精品久久久久久不卡|