TCP Retransmission Timeout Estimation
In questa pagina 6
Why an estimate is needed
TCP uses a retransmission timer, the retransmission timeout (RTO): if the ACK of a segment does not arrive within RTO the segment is considered lost and resent (TCP - Connection, Reliability and Flow ControlTCP is the connection-oriented, reliable transport protocol that turns IP's unreliable service into an ordered byte stream without errors or duplicates; the connection opens with a three-way handshake (SYN, SYN+ACK, ACK) and closes with FIN segments, bytes are numbered (sequence number = first byte of the segment, cumulative ACK = next byte expected), the sender may transmit min(rwnd, cwnd) unacknowledged bytes (rwnd, the receiver window in a 16-bit field, is flow control), errors are handled with checksum, ACKs, retransmission timeout and fast retransmit after three duplicate ACKs, and to fill the pipe the window must reach the bandwidth-delay product, with maximum throughput MSS times Wmax over RTT.TCP - Connection, Reliability and Flow Control →). The right value depends on the network and changes over time:
- RTO too small: it fires while the ACK is still coming, causing a spurious timeout that loads the network and, as seen in TCP Congestion ControlCongestion arises when fast links feed a slow one, router queues fill and packets are lost or delayed, possibly up to network collapse; TCP controls its congestion window cwnd using loss feedback (timeout or three duplicate ACKs): slow start doubles cwnd every RTT up to the threshold ssthresh, then congestion avoidance adds 1 MSS per RTT, and on a loss ssthresh becomes W/2; variants differ in reaction to three dupACKs: Tahoe restarts from cwnd=1, Reno uses fast recovery (ssthresh=cwnd/2, cwnd=ssthresh+3, +1 per further dupACK), NewReno handles partial ACKs and recovers several losses in one window, SACK acknowledges received blocks and resends only what is missing.TCP Congestion Control →, needlessly reduces the window;
- RTO too large: after a real loss the sender stays idle for long, losing throughput.
So RTO is estimated online from round-trip time (RTT) samples with two variables (as in RFC 6298): SRTT (smoothed RTT) and RTTVAR, called MAD (mean absolute deviation) in the course.
Measuring the RTT
A system clock ticks every seconds (the granularity). Only one RTT measurement is active at a time (one timer per session, not per packet). Example: the timer starts when packet 1 is sent and stops at after 3 ticks: . When packet 2 is sent the timer restarts; packets 3 and 4 are not timed since it is already running; it stops at : .
For more accurate measures the timestamp option is used: the sender writes the current time in each segment and the receiver echoes it in the ACK. It also distinguishes packets with the same sequence number when the 32-bit numbers wrap around, after seconds:
| bitrate | wraparound time |
|---|---|
| 1.5 Mbit/s | 6.4 hours |
| 10 Mbit/s | 57 minutes |
| 45 Mbit/s | 13 minutes |
| 100 Mbit/s | 6 minutes |
| 622 Mbit/s | 55 seconds |
| 1.2 Gbit/s | about 28 seconds |
At 10 Mbit/s: s min.
Smoothed average (Jacobson's algorithm)
With the -th sample, use an exponentially weighted moving average:
Formula (SRTT).
The new sample weighs , the previous estimate . Substituting repeatedly: so the sample steps back weighs (hence "exponential"); the initial value keeps weight , e.g. after 7 samples, which is why starting from underestimates strongly.
Example. ms, ms: ms.
Karn's algorithm
If a segment was retransmitted, an ACK cannot be attributed to the first, second, ... transmission, so cannot be computed correctly.
Rule (Karn). Ignore the RTT sample of a retransmitted segment (do not update SRTT). For the next packet use the last computed RTO, and resume estimation only after a transmission succeeds without retransmission. At each consecutive timeout the RTO doubles (exponential backoff) up to .
Example. ms, ms, ms. The segment sent at is not acknowledged within 120 ms: resend, RTO becomes 240 ms. An ACK arrives at ms: RTT (original) or (retransmission)? Unknown. If were used: , , : a wrong sample, SRTT drops just when the network proved slower. With Karn the sample is discarded, RTO stays 240 ms, and the first clean sample (say ) gives , , ms. Consecutive timeouts give (with ms: ms).
Variability: mean absolute deviation
The standard deviation is costly to compute online, so the mean absolute deviation (MAD) is used, again as a moving average:
Formula (MAD).
RFC 6298 calls it RTTVAR with coefficient .
Computing RTO
An older rule (RFC 739) was , which fires too early when variance is high. With RTT samples ms it times out spuriously at sample 2 () and sample 4 ().
Formula (RTO).
Why 4: for Gaussian RTT , so and the probability of exceeding it is : fewer than one spurious timeout per thousand samples (with about ). The minimum of 1 s (RFC 6298; in the course ) makes RTO much longer than the estimate for RTTs of a few milliseconds.
Numerical example: seven samples
Samples ms, starting from , , :
| RTO | ||||
|---|---|---|---|---|
| 1 | 30 | 3.75 | 7.5 | 33.75 |
| 2 | 80 | 13.28 | 24.69 | 112.03 |
| 3 | 40 | 16.62 | 25.20 | 117.40 |
| 4 | 130 | 30.79 | 47.24 | 219.76 |
| 5 | 50 | 33.19 | 40.23 | 194.12 |
| 6 | 70 | 37.79 | 39.38 | 195.30 |
| 7 | 90 | 44.32 | 42.58 | 214.65 |
First steps: ; ; ; . Starting from 0 underestimates: after seven samples ms versus a true mean of ms; two RTOs are below the next sample (, ): spurious timeouts.
RFC 6298. At the first measurement : , ; then for each sample update first and then , with . For the same samples:
| rtt | SRTT | RTTVAR | RTO | |
|---|---|---|---|---|
| 1 | 30 | 30.00 | 15.00 | 90.00 |
| 2 | 80 | 36.25 | 23.75 | 131.25 |
| 3 | 40 | 36.72 | 18.75 | 111.72 |
| 4 | 130 | 48.38 | 37.38 | 197.91 |
| 5 | 50 | 48.58 | 28.44 | 162.35 |
| 6 | 70 | 51.26 | 26.69 | 158.00 |
| 7 | 90 | 56.10 | 29.70 | 174.90 |
Initialising with the first sample avoids the slow start-up of the estimate.
MAD and standard deviation for Gaussian variables
For Gaussian with mean and standard deviation , let . Then since the integrand is even. Substituting , :
Property. .
Example. A path made of links with independent Gaussian RTT: means add, variances add. With ms: , ms, ms. With ms: ms, so s, the value used in Analytical Model of TCP Send RateThe analytical model gives the long-term send rate B (segments per second) of a TCP Reno flow as a function of the loss probability p, the RTT, the delayed-ACK parameter b and the timeout T0; time is divided into rounds of one RTT, the window cycle between two losses signalled by three duplicate ACKs (TDP) has mean window E[W] = (2-3b)/(3b) + sqrt(((3b-2)/(3b))^2 + 8(1-p)/(3bp)) and the rate is B = E[Y]/E[A], which for small p gives the square-root formula B = (1/RTT) sqrt(3/(2bp)) (about 1.22/(RTT sqrt p) for b=1 and 0.87/(RTT sqrt p) for b=2); timeouts add the probability Q that a loss ends in timeout, giving B = (E[Y] + Q E[R]) / (E[A] + Q E[Z_TO]), and a maximum window Wmax caps the rate at Wmax/RTT.Analytical Model of TCP Send Rate →.
Versione ripasso
- RTO too small: spurious retransmissions; too large: slow recovery. Estimated online from RTT samples (TCP - Connection, Reliability and Flow ControlTCP is the connection-oriented, reliable transport protocol that turns IP's unreliable service into an ordered byte stream without errors or duplicates; the connection opens with a three-way handshake (SYN, SYN+ACK, ACK) and closes with FIN segments, bytes are numbered (sequence number = first byte of the segment, cumulative ACK = next byte expected), the sender may transmit min(rwnd, cwnd) unacknowledged bytes (rwnd, the receiver window in a 16-bit field, is flow control), errors are handled with checksum, ACKs, retransmission timeout and fast retransmit after three duplicate ACKs, and to fill the pipe the window must reach the bandwidth-delay product, with maximum throughput MSS times Wmax over RTT.TCP - Connection, Reliability and Flow Control →). One RTT measurement at a time (one timer per connection); timestamp option for precise samples and wraparound (: min at Mbit/s).
, . , . , .
- , : ms. Weight of old sample steps back: ; start at 0 underestimates ( of the initial value remains after 7 samples).
- Why 4: Gaussian , so , spurious probability .
- Karn: ignore samples of retransmitted segments; RTO doubles at each consecutive timeout up to . Example , : , then ; a wrong sample would give .
- Samples (start at 0): RTO ; vs mean .
- RFC 6298: first sample : , ; ; for the same samples , .
- Path with ms: , , ms, s (Analytical Model of TCP Send RateThe analytical model gives the long-term send rate B (segments per second) of a TCP Reno flow as a function of the loss probability p, the RTT, the delayed-ACK parameter b and the timeout T0; time is divided into rounds of one RTT, the window cycle between two losses signalled by three duplicate ACKs (TDP) has mean window E[W] = (2-3b)/(3b) + sqrt(((3b-2)/(3b))^2 + 8(1-p)/(3bp)) and the rate is B = E[Y]/E[A], which for small p gives the square-root formula B = (1/RTT) sqrt(3/(2bp)) (about 1.22/(RTT sqrt p) for b=1 and 0.87/(RTT sqrt p) for b=2); timeouts add the probability Q that a loss ends in timeout, giving B = (E[Y] + Q E[R]) / (E[A] + Q E[Z_TO]), and a maximum window Wmax caps the rate at Wmax/RTT.Analytical Model of TCP Send Rate →).
- Typical errors: timing retransmitted segments; forgetting the 1 s minimum; using the standard deviation instead of MAD in the formula.