`

Nagle's algorithm

 
阅读更多

Nagle's algorithm

From Wikipedia, the free encyclopedia
Jump to: navigation , search

Nagle's algorithm , named after John Nagle, is a means of improving the efficiency of TCP/IP networks by reducing the number of packets that need to be sent over the network.

Nagle's document, Congestion Control in IP/TCP Internetworks (RFC 896 ) describes what he called the "small packet problem", where an application repeatedly emits data in small chunks, frequently only 1 byte in size. Since TCP packets have a 40 byte header (20 bytes for TCP, 20 bytes for IPv4 ), this results in a 41 byte packet for 1 byte of useful information, a huge overhead. This situation often occurs in Telnet sessions, where most keypresses generate a single byte of data that is transmitted immediately. Worse, over slow links, many such packets can be in transit at the same time, potentially leading to congestion collapse .

Nagle's algorithm works by combining a number of small outgoing messages, and sending them all at once. Specifically, as long as there is a sent packet for which the sender has received no acknowledgment, the sender should keep buffering its output until it has a full packet's worth of output, so that output can be sent all at once.

Contents

Algorithm

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

where MSS = maximum segment size .

This algorithm interacts badly with TCP delayed acknowledgments , a feature introduced into TCP at roughly the same time in the early 1980s, but by a different group. With both algorithms enabled, applications that do two successive writes to a TCP connection, followed by a read that will not be fulfilled until after the data from the second write has reached the destination, experience a constant delay of up to 500 milliseconds, the "ACK delay". For this reason, TCP implementations usually provide applications with an interface to disable the Nagle algorithm. This is typically called the TCP_NODELAY option.

If possible an application should avoid consecutive small writes in the first place, so that Nagle's algorithm will not be triggered. The application should keep from sending small single writes and buffer up application writes then send (or with the help of writev() call).

"The user-level solution is to avoid write-write-read sequences on sockets. write-read-write-read is fine. write-write-write is fine. But write-write-read is a killer. So, if you can, buffer up your little writes to TCP and send them all at once. Using the standard UNIX I/O package and flushing write before each read usually works."[ 1]

The tinygram problem and silly window syndrome are sometimes confused. The tinygram problem occurs when the window is almost empty. Silly window syndrome occurs when the window is almost full.

Negative effect on non-small writes

The algorithm applies to data of any size. If the data in a single write spans 2n packets, the last packet will be withheld, waiting for the ACK for the previous packet.[ 2] In any request-response application protocols where request data can be larger than a packet, this can artificially impose a few hundred milliseconds latency between the requester and the responder, even if the requester has properly buffered the request data. Nagle's algorithm must be disabled by the requester in this case. If the response data can be larger than a packet, the responder must also disable Nagle's algorithm so the requester can promptly receive the whole response.

In general, since Nagle's algorithm is only a defense against careless applications, it will not benefit a carefully written application that takes proper care of buffering; the algorithm has either no effect, or negative effect on the application.

Interactions with real-time systems

Applications that expect real time responses can react poorly with Nagle's algorithm. Applications such as networked multiplayer video games expect that actions in the game are sent immediately, while the algorithm purposefully delays transmission, increasing bandwidth efficiency at the expense of latency . For this reason applications with low-bandwidth time-sensitive transmissions typically use TCP_NODELAY to bypass the Nagle delay.[ 3]

References

  1. ^ Boosting Socket Performance on Linux - Slashdot
  2. ^ http://www.stuartcheshire.org/papers/NagleDelayedAck/
  3. ^ Bug 17868 – Some Java applications are slow on remote X connections

External links

分享到:
评论

相关推荐

    Breakthrough InstaSPINFOC motor control technology is here!

    encoder (sensorless observer) algorithm, FAST™ (fl ux, angle, speed and torque), embedded in the read-only-memory (ROM) of Piccolo™ micro controllers. This enables premium solutions that improve ...

    扩展卡尔曼系统的目标跟踪研究.doc

    After multiple iterations, the EKF generates a filtered trajectory that closely follows the true motion of the target, providing estimations of both the distance and angle errors. The simulation ...

    Accurate 3-d posotion in indoor enviroment

    On the basis of that, an algorithm of multiangle intersection was established and in-depth discussed to solve transmitter’s spatial position and orientation. Experimental results show that, in an 8m...

    fft的源代码 经过检验

    - 若要支持非2的幂次个样本,可以采用Bluestein's algorithm或其他更通用的FFT方法。 - 若要提高性能,可以考虑使用多线程或GPU加速。 总之,这段代码提供了一个基础的基2 FFT实现,适用于理解FFT的基本原理和...

    Introduction to Algorithms Lecture Notes (MIT 6.006)

    This module covers various shortest path algorithms, including Dijkstra's algorithm. 6. **Dynamic Programming: Stock Market** - **Motivation**: Uses dynamic programming to analyze stock market ...

    park an autonomous vehicle

    To control the steering angle and longitudinal velocity of the vehicle during the parking maneuver, sinusoidal reference functions are used. To prevent collisions, the maneuver is carried out as a ...

    C++趣味小程序百例

    #include<algorithm> #include int main() { std::vector<int> scores; int score; while (scanf("%d", &score) != EOF) { scores.push_back(score); } std::sort(scores.begin(), scores.end()); int sum =...

    Graphics Gems (Vol.2)

    5. A Half-Angle Identity for Digital Computation: 381 The Joys of the Halved Tangent Alan W. Paeth 6. An Integer Square Root Algorithm C 387 Christopher J. Musial 7. Fast Approximation to the ...

    Computer Age Statistical Inference: Algorithms,Evidence,and Data Science.

    16.4 Least-Angle Regression 309 16.5 Fitting Generalized Lasso Models 313 16.6 Post-Selection Inference for the Lasso 317 16.7 Connections and Extensions 319 16.8 Notes and Details 321 17 Random ...

    Robust hand gesture recognition for robotic hand control

    The pre-processing is performed by developing an image-cropping algorithm that ensures only the area of interest is included in the segmented image. The segmented image is compared with a predefined ...

    C语言头文件大全C语言头文件大全

    除了上述C语言的标准头文件外,还提到了一些C++标准模板库(STL)中的头文件,如`<algorithm>`、`<vector>`等。这部分内容主要是为了支持更高级的数据结构和算法处理,将在另一篇文章中详细介绍。 通过以上解析,...

    最小体积约束的线性光谱解混算法 (2011年)

    为了评估算法性能,实验采用了光谱夹角距离 (Spectral Angle Distance, SAD)、光谱信息散度 (Spectral Information Divergence, SID)、丰度夹角距离 (Abundance Angle Distance, AAD) 和丰度信息散度 (Abundance ...

    信号与系统 MATLAB仿真及结果

    在信号处理和系统分析中,信号是指变化的物理量,而系统是指对信号进行处理和转换的设备或 algorithm。信号可以是连续的或离散的,系统也可以是线性的或非线性的。 二、时域图 时域图是指信号在时间域中的表现形式...

    天空角度游戏:天空角度游戏

    例如,Bresenham's Line Algorithm(布雷森汉姆线算法)可能用于绘制游戏中的直线,而A*寻路算法可以帮助游戏角色找到最短路径。 7. **游戏循环**:游戏通常包含一个主循环,不断地更新游戏状态、渲染画面并处理...

    雷达技术知识

    scan angle of LiDAR to return from a water surface. Return factor is greatest at low scan angles relative to the nadir region of scan. (Maslov, D. V. et. al. (2000). A Shore-based LiDAR for Coastal ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - ADD: In the text prcise mode (TFlexText.Precise=True) takes into account the rotation angle (TFlexText.Angle). - FIX: Removed FG_NEWTEXTROTATE directive (the TFlexText Precise mode should be used ...

Global site tag (gtag.js) - Google Analytics