Salta al contenuto
Note per Studenti TCP Retransmission Timeout Estimation Report

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:

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 GG 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 ACK 2\text{ACK}\,2 after 3 ticks: RTT1=3G\text{RTT}_1=3G. When packet 2 is sent the timer restarts; packets 3 and 4 are not timed since it is already running; it stops at ACK 5\text{ACK}\,5: RTT2=2G\text{RTT}_2=2G.

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 232⋅8/C2^{32}\cdot8/C 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: 232⋅8/107=34362^{32}\cdot8/10^7=3436 s =57.3=57.3 min.

Smoothed average (Jacobson's algorithm)

With rtti\text{rtt}_i the ii-th sample, use an exponentially weighted moving average:

Formula (SRTT). SRTTi=(1−α) SRTTi−1+α⋅rtti,α=18.\text{SRTT}_i=(1-\alpha)\,\text{SRTT}_{i-1}+\alpha\cdot\text{rtt}_i,\qquad\alpha=\frac18.

The new sample weighs 1/81/8, the previous estimate 7/87/8. Substituting repeatedly: SRTTi=α∑k=0i−1(1−α)k rtti−k+(1−α)i SRTT0,\text{SRTT}_i=\alpha\sum_{k=0}^{i-1}(1-\alpha)^k\,\text{rtt}_{i-k}+(1-\alpha)^i\,\text{SRTT}_0, so the sample kk steps back weighs α(1−α)k\alpha(1-\alpha)^k (hence "exponential"); the initial value keeps weight (1−α)i(1-\alpha)^i, e.g. (7/8)7=0.393(7/8)^7=0.393 after 7 samples, which is why starting from SRTT0=0\text{SRTT}_0=0 underestimates strongly.

Example. SRTTi−1=80\text{SRTT}_{i-1}=80 ms, rtti=120\text{rtt}_i=120 ms: SRTTi=78⋅80+18⋅120=85\text{SRTT}_i=\tfrac78\cdot80+\tfrac18\cdot120=85 ms.

Karn's algorithm

If a segment was retransmitted, an ACK cannot be attributed to the first, second, ... transmission, so rtti\text{rtt}_i 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 64 T064\,T_0.

Example. SRTT=80\text{SRTT}=80 ms, MAD=10\text{MAD}=10 ms, RTO=80+4⋅10=120\text{RTO}=80+4\cdot10=120 ms. The segment sent at t=0t=0 is not acknowledged within 120 ms: resend, RTO becomes 240 ms. An ACK arrives at t=130t=130 ms: RTT 130130 (original) or 1010 (retransmission)? Unknown. If rtt=10\text{rtt}=10 were used: SRTT=78⋅80+18⋅10=71.25\text{SRTT}=\tfrac78\cdot80+\tfrac18\cdot10=71.25, MAD=0.75⋅10+0.25⋅∣10−80∣=25\text{MAD}=0.75\cdot10+0.25\cdot|10-80|=25, RTO=171.25\text{RTO}=171.25: 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 rtt=90\text{rtt}=90) gives SRTT=81.25\text{SRTT}=81.25, MAD=10\text{MAD}=10, RTO=121.25\text{RTO}=121.25 ms. Consecutive timeouts give T0,2T0,4T0,…,64 T0T_0,2T_0,4T_0,\dots,64\,T_0 (with T0=120T_0=120 ms: 120,240,…,7680120,240,\dots,7680 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). MADi=(1−ρ) MADi−1+ρ ∣rtti−SRTTi−1∣,ρ=14.\text{MAD}_i=(1-\rho)\,\text{MAD}_{i-1}+\rho\,\big|\text{rtt}_i-\text{SRTT}_{i-1}\big|,\qquad\rho=\frac14.

RFC 6298 calls it RTTVAR with coefficient β=1/4\beta=1/4.

Computing RTO

An older rule (RFC 739) was RTOi=2⋅RTTi−1\text{RTO}_i=2\cdot\text{RTT}_{i-1}, which fires too early when variance is high. With RTT samples 30,80,40,130,50,70,9030,80,40,130,50,70,90 ms it times out spuriously at sample 2 (80>6080>60) and sample 4 (130>80130>80).

Formula (RTO). RTOi=SRTTi+4⋅MADi,T0=max⁡{RTO, 1 s}.\text{RTO}_i=\text{SRTT}_i+4\cdot\text{MAD}_i,\qquad T_0=\max\{\text{RTO},\,1\text{ s}\}.

Why 4: for Gaussian RTT MAD≃0.797 σ\text{MAD}\simeq0.797\,\sigma, so SRTT+4 MAD≃SRTT+3.19 σ\text{SRTT}+4\,\text{MAD}\simeq\text{SRTT}+3.19\,\sigma and the probability of exceeding it is 1−Φ(3.19)≈0.00071-\Phi(3.19)\approx0.0007: fewer than one spurious timeout per thousand samples (with 2 MAD≃1.6σ2\,\text{MAD}\simeq1.6\sigma about 5.5%5.5\%). The minimum of 1 s (RFC 6298; in the course T0=max⁡{RTO,1 s}T_0=\max\{\text{RTO},1\text{ s}\}) makes RTO much longer than the estimate for RTTs of a few milliseconds.

Numerical example: seven samples

Samples 30,80,40,130,50,70,9030,80,40,130,50,70,90 ms, starting from SRTT0=MAD0=0\text{SRTT}_0=\text{MAD}_0=0, α=1/8\alpha=1/8, ρ=1/4\rho=1/4:

ii rtti\text{rtt}_i SRTTi\text{SRTT}_i MADi\text{MAD}_i 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: SRTT1=78⋅0+18⋅30=3.75\text{SRTT}_1=\tfrac78\cdot0+\tfrac18\cdot30=3.75; MAD1=0.25⋅∣30−0∣=7.5\text{MAD}_1=0.25\cdot|30-0|=7.5; SRTT2=78⋅3.75+18⋅80=13.28\text{SRTT}_2=\tfrac78\cdot3.75+\tfrac18\cdot80=13.28; MAD2=0.75⋅7.5+0.25⋅∣80−3.75∣=24.69\text{MAD}_2=0.75\cdot7.5+0.25\cdot|80-3.75|=24.69. Starting from 0 underestimates: after seven samples SRTT=44.3\text{SRTT}=44.3 ms versus a true mean of 7070 ms; two RTOs are below the next sample (33.75<8033.75<80, 117.4<130117.4<130): spurious timeouts.

RFC 6298. At the first measurement RR: SRTT=R\text{SRTT}=R, RTTVAR=R/2\text{RTTVAR}=R/2; then for each sample update first RTTVAR=(1−β)RTTVAR+β∣SRTT−R∣\text{RTTVAR}=(1-\beta)\text{RTTVAR}+\beta|\text{SRTT}-R| and then SRTT=(1−α)SRTT+αR\text{SRTT}=(1-\alpha)\text{SRTT}+\alpha R, with RTO=SRTT+max⁡{G,4 RTTVAR}\text{RTO}=\text{SRTT}+\max\{G,4\,\text{RTTVAR}\}. For the same samples:

ii 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 XX Gaussian with mean μ\mu and standard deviation σ\sigma, let Y=X−μY=X-\mu. Then MAD=E∣Y∣=2∫0+∞y 1σ2πe−y2/(2σ2)dy,\text{MAD}=E|Y|=2\int_0^{+\infty}y\,\frac1{\sigma\sqrt{2\pi}}e^{-y^2/(2\sigma^2)}dy, since the integrand is even. Substituting u=y2/(2σ2)u=y^2/(2\sigma^2), y dy=σ2duy\,dy=\sigma^2du: MAD=2σ2σ2π∫0+∞e−udu=2σ2π=σ2π.\text{MAD}=\frac{2\sigma^2}{\sigma\sqrt{2\pi}}\int_0^{+\infty}e^{-u}du=\frac{2\sigma}{\sqrt{2\pi}}=\sigma\sqrt{\frac2\pi}.

Property. MAD=σ2/π≈0.797 σ\text{MAD}=\sigma\sqrt{2/\pi}\approx0.797\,\sigma.

Example. A path made of links with independent Gaussian RTT: means add, variances add. With σn=0.1, 2, 1, 0.5\sigma_n=0.1,\,2,\,1,\,0.5 ms: σtot2=0.01+4+1+0.25=5.26\sigma^2_{\text{tot}}=0.01+4+1+0.25=5.26, σ=2.293\sigma=2.293 ms, MAD=0.7979⋅2.293=1.829\text{MAD}=0.7979\cdot2.293=1.829 ms. With RTT=27\text{RTT}=27 ms: RTO=27+4⋅1.829=34.3\text{RTO}=27+4\cdot1.829=34.3 ms, so T0=max⁡{34.3 ms,1 s}=1T_0=\max\{34.3\text{ ms},1\text{ s}\}=1 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

SRTTi=(1−α)SRTTi−1+α rtti\text{SRTT}_i=(1-\alpha)\text{SRTT}_{i-1}+\alpha\,\text{rtt}_i, α=1/8\alpha=1/8. MADi=(1−ρ)MADi−1+ρ ∣rtti−SRTTi−1∣\text{MAD}_i=(1-\rho)\text{MAD}_{i-1}+\rho\,|\text{rtt}_i-\text{SRTT}_{i-1}|, ρ=1/4\rho=1/4. RTO=SRTT+4 MAD\text{RTO}=\text{SRTT}+4\,\text{MAD}, T0=max⁡{RTO,1 s}T_0=\max\{\text{RTO},1\text{ s}\}.

Teoria collegata