UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2002-07-24 08:45 PM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: 2.17 - What exactly does the Nagle algorithm do?

Taken from the original FAQ.

6

It groups together as much data as it can between ACK's from the other end of the connection. I found this really confusing until Andrew Gierth ([email protected]) drew the following diagram, and explained:

This diagram is not intended to be complete, just to illustrate the point better...

Case 1: client writes 1 byte per write() call. The program on host B is tcpserver.c from the FAQ examples.

CLIENT                                  SERVER
APP             TCP                     TCP             APP
                [connection setup omitted]

 "h" --------->          [1 byte]
                    ------------------>
                                           -----------> "h"
                                   [ack delayed]
 "e" ---------> [Nagle alg.              .
                 now in effect]          .
 "l" ---------> [ditto]                  .
 "l" ---------> [ditto]                  .
 "o" ---------> [ditto]                  .
 "\n"---------> [ditto]                  .
                                         .
                                         .
                       [ack 1 byte]
                    <------------------
                [send queued
                data]
                        [5 bytes]
                    ------------------>
                                          ------------> "ello\n"
                                          <------------ "HELLO\n"
                   [6 bytes, ack 5 bytes]
                    <------------------
 "HELLO\n" <----
              [ack delayed]
                 .
                 .
                 .   [ack 6 bytes]
                    ------------------>

Total segments: 5. (If TCP_NODELAY was set, could have been up to 10.) Time for response: 2*RTT, plus ack delay.

Case 2: client writes all data with one write() call.

CLIENT                                  SERVER
APP             TCP                     TCP             APP
                [connection setup omitted]

 "hello\n" --->          [6 bytes]
                    ------------------>
                                          ------------> "hello\n"
                                          <------------ "HELLO\n"
                   [6 bytes, ack 6 bytes]
                    <------------------
 "HELLO\n" <----
            [ack delayed]
                 .
                 .
                 .   [ack 6 bytes]
                    ------------------>

Total segments: 3.

Time for response = RTT (therefore minimum possible).

Hope this makes things a bit clearer...

Note that in case 2, you don't want the implementation to gratuitously delay sending the data, since that would add straight onto the response time.

Offline

Board footer

Powered by FluxBB