`

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

分享到:
评论

相关推荐

    Machine.Learning.Optimization.and.Big.Data

    Machine Learning, Optimization, and Big ... Establishment of Optimal Control Strategy of Building-Integrated Photovoltaic Blind Slat Angle by Considering Interior Illuminance and Electricity Generation

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

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

    Similarity Search- The Metric Space Approach

    3.5 Jaccard’s Coefficient 13 3.6 Hausdorff Distance 14 3.7 Time Complexity 14 4 Similarity Queries 15 4.1 Range Query 15 4.2 Nearest Neighbor Query 16 4.3 Reverse Nearest Neighbor Query 17 4.4 ...

    Optimization algorithm of near-eye light field displays based on human visual characteristics

    The number of layers and the resolution... First we employ the eye’s modulation transfer function (MTF) to acquire the limiting resolution angle. Then, due to the inverse relationship between the limiti

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

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

    Principles of Planar Near-Field Antenna Measurements

    2 Maxwell’s equations and electromagnetic wave propagation 13 2.1 Electric charge 13 2.2 The EM field 14 2.3 Accelerated charges 16 2.4 Maxwell’s equations 18 2.5 The electric and magnetic ...

    计算机视觉(英文版)

    1.1.2 Solid Angle 4 1.1.3 Radiance 6 1.2 Light at Surfaces 8 1.2.1 Simplifying Assumptions 9 1.2.2 The Bidirectional Reflectance Distribution Function 9 1.3 Important Special Cases 11 1.3.1 Radiosity ...

    雷达技术知识

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

    Convex Optimization

    8.3 Euclidean distance and angle problems . . . . . . . . . . . . . . . . . . 405 8.4 Extremal volume ellipsoids . . . . . . . . . . . . . . . . . . . . . . . . 410 8.5 Centering . . . . . . . . . . ....

    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