home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / rfc / 2000s / rfc2001.txt < prev    next >
Text File  |  1997-01-27  |  13KB  |  340 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                         W. Stevens
  8. Request for Comments: 2001                                          NOAO
  9. Category: Standards Track                                   January 1997
  10.  
  11.  
  12.                  TCP Slow Start, Congestion Avoidance,
  13.              Fast Retransmit, and Fast Recovery Algorithms
  14.  
  15. Status of this Memo
  16.  
  17.    This document specifies an Internet standards track protocol for the
  18.    Internet community, and requests discussion and suggestions for
  19.    improvements.  Please refer to the current edition of the "Internet
  20.    Official Protocol Standards" (STD 1) for the standardization state
  21.    and status of this protocol.  Distribution of this memo is unlimited.
  22.  
  23. Abstract
  24.  
  25.    Modern implementations of TCP contain four intertwined algorithms
  26.    that have never been fully documented as Internet standards:  slow
  27.    start, congestion avoidance, fast retransmit, and fast recovery.  [2]
  28.    and [3] provide some details on these algorithms, [4] provides
  29.    examples of the algorithms in action, and [5] provides the source
  30.    code for the 4.4BSD implementation.  RFC 1122 requires that a TCP
  31.    must implement slow start and congestion avoidance (Section 4.2.2.15
  32.    of [1]), citing [2] as the reference, but fast retransmit and fast
  33.    recovery were implemented after RFC 1122.  The purpose of this
  34.    document is to document these four algorithms for the Internet.
  35.  
  36. Acknowledgments
  37.  
  38.    Much of this memo is taken from "TCP/IP Illustrated, Volume 1:  The
  39.    Protocols" by W. Richard Stevens (Addison-Wesley, 1994) and "TCP/IP
  40.    Illustrated, Volume 2: The Implementation" by Gary R. Wright and W.
  41.    Richard Stevens (Addison-Wesley, 1995).  This material is used with
  42.    the permission of Addison-Wesley.  The four algorithms that are
  43.    described were developed by Van Jacobson.
  44.  
  45. 1.  Slow Start
  46.  
  47.    Old TCPs would start a connection with the sender injecting multiple
  48.    segments into the network, up to the window size advertised by the
  49.    receiver.  While this is OK when the two hosts are on the same LAN,
  50.    if there are routers and slower links between the sender and the
  51.    receiver, problems can arise.  Some intermediate router must queue
  52.    the packets, and it's possible for that router to run out of space.
  53.    [2] shows how this naive approach can reduce the throughput of a TCP
  54.    connection drastically.
  55.  
  56.  
  57.  
  58. Stevens                     Standards Track                     [Page 1]
  59.  
  60. RFC 2001                          TCP                       January 1997
  61.  
  62.  
  63.    The algorithm to avoid this is called slow start.  It operates by
  64.    observing that the rate at which new packets should be injected into
  65.    the network is the rate at which the acknowledgments are returned by
  66.    the other end.
  67.  
  68.    Slow start adds another window to the sender's TCP:  the congestion
  69.    window, called "cwnd".  When a new connection is established with a
  70.    host on another network, the congestion window is initialized to one
  71.    segment (i.e., the segment size announced by the other end, or the
  72.    default, typically 536 or 512).  Each time an ACK is received, the
  73.    congestion window is increased by one segment.  The sender can
  74.    transmit up to the minimum of the congestion window and the
  75.    advertised window.  The congestion window is flow control imposed by
  76.    the sender, while the advertised window is flow control imposed by
  77.    the receiver.  The former is based on the sender's assessment of
  78.    perceived network congestion; the latter is related to the amount of
  79.    available buffer space at the receiver for this connection.
  80.  
  81.    The sender starts by transmitting one segment and waiting for its
  82.    ACK.  When that ACK is received, the congestion window is incremented
  83.    from one to two, and two segments can be sent.  When each of those
  84.    two segments is acknowledged, the congestion window is increased to
  85.    four.  This provides an exponential growth, although it is not
  86.    exactly exponential because the receiver may delay its ACKs,
  87.    typically sending one ACK for every two segments that it receives.
  88.  
  89.    At some point the capacity of the internet can be reached, and an
  90.    intermediate router will start discarding packets.  This tells the
  91.    sender that its congestion window has gotten too large.
  92.  
  93.    Early implementations performed slow start only if the other end was
  94.    on a different network.  Current implementations always perform slow
  95.    start.
  96.  
  97. 2.  Congestion Avoidance
  98.  
  99.    Congestion can occur when data arrives on a big pipe (a fast LAN) and
  100.    gets sent out a smaller pipe (a slower WAN).  Congestion can also
  101.    occur when multiple input streams arrive at a router whose output
  102.    capacity is less than the sum of the inputs.  Congestion avoidance is
  103.    a way to deal with lost packets.  It is described in [2].
  104.  
  105.    The assumption of the algorithm is that packet loss caused by damage
  106.    is very small (much less than 1%), therefore the loss of a packet
  107.    signals congestion somewhere in the network between the source and
  108.    destination.  There are two indications of packet loss:  a timeout
  109.    occurring and the receipt of duplicate ACKs.
  110.  
  111.  
  112.  
  113.  
  114. Stevens                     Standards Track                     [Page 2]
  115.  
  116. RFC 2001                          TCP                       January 1997
  117.  
  118.  
  119.    Congestion avoidance and slow start are independent algorithms with
  120.    different objectives.  But when congestion occurs TCP must slow down
  121.    its transmission rate of packets into the network, and then invoke
  122.    slow start to get things going again.  In practice they are
  123.    implemented together.
  124.  
  125.    Congestion avoidance and slow start require that two variables be
  126.    maintained for each connection: a congestion window, cwnd, and a slow
  127.    start threshold size, ssthresh.  The combined algorithm operates as
  128.    follows:
  129.  
  130.    1.  Initialization for a given connection sets cwnd to one segment
  131.        and ssthresh to 65535 bytes.
  132.  
  133.    2.  The TCP output routine never sends more than the minimum of cwnd
  134.        and the receiver's advertised window.
  135.  
  136.    3.  When congestion occurs (indicated by a timeout or the reception
  137.        of duplicate ACKs), one-half of the current window size (the
  138.        minimum of cwnd and the receiver's advertised window, but at
  139.        least two segments) is saved in ssthresh.  Additionally, if the
  140.        congestion is indicated by a timeout, cwnd is set to one segment
  141.        (i.e., slow start).
  142.  
  143.    4.  When new data is acknowledged by the other end, increase cwnd,
  144.        but the way it increases depends on whether TCP is performing
  145.        slow start or congestion avoidance.
  146.  
  147.       If cwnd is less than or equal to ssthresh, TCP is in slow start;
  148.       otherwise TCP is performing congestion avoidance.  Slow start
  149.       continues until TCP is halfway to where it was when congestion
  150.       occurred (since it recorded half of the window size that caused
  151.       the problem in step 2), and then congestion avoidance takes over.
  152.  
  153.       Slow start has cwnd begin at one segment, and be incremented by
  154.       one segment every time an ACK is received.  As mentioned earlier,
  155.       this opens the window exponentially:  send one segment, then two,
  156.       then four, and so on.  Congestion avoidance dictates that cwnd be
  157.       incremented by segsize*segsize/cwnd each time an ACK is received,
  158.       where segsize is the segment size and cwnd is maintained in bytes.
  159.       This is a linear growth of cwnd, compared to slow start's
  160.       exponential growth.  The increase in cwnd should be at most one
  161.       segment each round-trip time (regardless how many ACKs are
  162.       received in that RTT), whereas slow start increments cwnd by the
  163.       number of ACKs received in a round-trip time.
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. Stevens                     Standards Track                     [Page 3]
  171.  
  172. RFC 2001                          TCP                       January 1997
  173.  
  174.  
  175.    Many implementations incorrectly add a small fraction of the segment
  176.    size (typically the segment size divided by 8) during congestion
  177.    avoidance.  This is wrong and should not be emulated in future
  178.    releases.
  179.  
  180. 3.  Fast Retransmit
  181.  
  182.    Modifications to the congestion avoidance algorithm were proposed in
  183.    1990 [3].  Before describing the change, realize that TCP may
  184.    generate an immediate acknowledgment (a duplicate ACK) when an out-
  185.    of-order segment is received (Section 4.2.2.21 of [1], with a note
  186.    that one reason for doing so was for the experimental fast-
  187.    retransmit algorithm).  This duplicate ACK should not be delayed.
  188.    The purpose of this duplicate ACK is to let the other end know that a
  189.    segment was received out of order, and to tell it what sequence
  190.    number is expected.
  191.  
  192.    Since TCP does not know whether a duplicate ACK is caused by a lost
  193.    segment or just a reordering of segments, it waits for a small number
  194.    of duplicate ACKs to be received.  It is assumed that if there is
  195.    just a reordering of the segments, there will be only one or two
  196.    duplicate ACKs before the reordered segment is processed, which will
  197.    then generate a new ACK.  If three or more duplicate ACKs are
  198.    received in a row, it is a strong indication that a segment has been
  199.    lost.  TCP then performs a retransmission of what appears to be the
  200.    missing segment, without waiting for a retransmission timer to
  201.    expire.
  202.  
  203. 4.  Fast Recovery
  204.  
  205.    After fast retransmit sends what appears to be the missing segment,
  206.    congestion avoidance, but not slow start is performed.  This is the
  207.    fast recovery algorithm.  It is an improvement that allows high
  208.    throughput under moderate congestion, especially for large windows.
  209.  
  210.    The reason for not performing slow start in this case is that the
  211.    receipt of the duplicate ACKs tells TCP more than just a packet has
  212.    been lost.  Since the receiver can only generate the duplicate ACK
  213.    when another segment is received, that segment has left the network
  214.    and is in the receiver's buffer.  That is, there is still data
  215.    flowing between the two ends, and TCP does not want to reduce the
  216.    flow abruptly by going into slow start.
  217.  
  218.    The fast retransmit and fast recovery algorithms are usually
  219.    implemented together as follows.
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226. Stevens                     Standards Track                     [Page 4]
  227.  
  228. RFC 2001                          TCP                       January 1997
  229.  
  230.  
  231.    1.  When the third duplicate ACK in a row is received, set ssthresh
  232.        to one-half the current congestion window, cwnd, but no less
  233.        than two segments.  Retransmit the missing segment.  Set cwnd to
  234.        ssthresh plus 3 times the segment size.  This inflates the
  235.        congestion window by the number of segments that have left the
  236.        network and which the other end has cached (3).
  237.  
  238.    2.  Each time another duplicate ACK arrives, increment cwnd by the
  239.        segment size.  This inflates the congestion window for the
  240.        additional segment that has left the network.  Transmit a
  241.        packet, if allowed by the new value of cwnd.
  242.  
  243.    3.  When the next ACK arrives that acknowledges new data, set cwnd
  244.        to ssthresh (the value set in step 1).  This ACK should be the
  245.        acknowledgment of the retransmission from step 1, one round-trip
  246.        time after the retransmission.  Additionally, this ACK should
  247.        acknowledge all the intermediate segments sent between the lost
  248.        packet and the receipt of the first duplicate ACK.  This step is
  249.        congestion avoidance, since TCP is down to one-half the rate it
  250.        was at when the packet was lost.
  251.  
  252.    The fast retransmit algorithm first appeared in the 4.3BSD Tahoe
  253.    release, and it was followed by slow start.  The fast recovery
  254.    algorithm appeared in the 4.3BSD Reno release.
  255.  
  256. 5.  Security Considerations
  257.  
  258.    Security considerations are not discussed in this memo.
  259.  
  260. 6.  References
  261.  
  262.    [1]  B. Braden, ed., "Requirements for Internet Hosts --
  263.         Communication Layers," RFC 1122, Oct. 1989.
  264.  
  265.    [2]  V. Jacobson, "Congestion Avoidance and Control," Computer
  266.         Communication Review, vol. 18, no. 4, pp. 314-329, Aug. 1988.
  267.         ftp://ftp.ee.lbl.gov/papers/congavoid.ps.Z.
  268.  
  269.    [3]  V. Jacobson, "Modified TCP Congestion Avoidance Algorithm,"
  270.         end2end-interest mailing list, April 30, 1990.
  271.         ftp://ftp.isi.edu/end2end/end2end-interest-1990.mail.
  272.  
  273.    [4]  W. R. Stevens, "TCP/IP Illustrated, Volume 1: The Protocols",
  274.         Addison-Wesley, 1994.
  275.  
  276.    [5]  G. R. Wright, W. R. Stevens, "TCP/IP Illustrated, Volume 2:
  277.         The Implementation", Addison-Wesley, 1995.
  278.  
  279.  
  280.  
  281.  
  282. Stevens                     Standards Track                     [Page 5]
  283.  
  284. RFC 2001                          TCP                       January 1997
  285.  
  286.  
  287. Author's  Address:
  288.  
  289.     W. Richard Stevens
  290.     1202 E. Paseo del Zorro
  291.     Tucson, AZ  85718
  292.  
  293.     Phone: 520-297-9416
  294.  
  295.     EMail: rstevens@noao.edu
  296.     Home Page: http://www.noao.edu/~rstevens
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. Stevens                     Standards Track                     [Page 6]
  339.  
  340.