2 · TCP RTT estimation and timeout ★
Slides 3-48 → 3-50, 3-51 → 3-52 · HW4 P32, P33 · Sample midterm 1.4
Why the timeout is hard to pick (3-48)
- Timeout must be longer than the RTT, but the RTT varies.
- Too short: premature timeout and unnecessary retransmissions.
- Too long: slow reaction to segment loss.
- SampleRTT: measured time from a segment's transmission until its ACK arrives. TCP takes one sample at a time, not one per segment.
- SampleRTT varies, so TCP wants a smoother estimate that averages several recent samples, not just the current one.
EstimatedRTT: an EWMA (3-49)
EstimatedRTT = (1 − α)·EstimatedRTT + α·SampleRTT typical α = 0.125 = 1/8
- Exponential weighted moving average (EWMA): the influence of a past sample decreases exponentially fast.
- Why an EWMA: one odd sample (a queueing spike) moves the estimate only by α of the difference. Recent samples still count more than old ones, so the estimate tracks real changes.
- With α = 0.125: new estimate = 7/8 old + 1/8 new sample.
- Weight of a sample k steps back = α(1 − α)k.
DevRTT and TimeoutInterval (3-50)
DevRTT = (1 − β)·DevRTT + β·|SampleRTT − EstimatedRTT| typical β = 0.25
TimeoutInterval = EstimatedRTT + 4·DevRTT
(estimated RTT) ("safety margin")
- DevRTT: an EWMA of how far SampleRTT strays from EstimatedRTT.
- Why a safety margin: if the timeout were just EstimatedRTT, about half the ACKs would arrive "late" and trigger premature retransmissions. Large variation → larger margin. Steady RTT → DevRTT shrinks and the timeout hugs EstimatedRTT.
- Order used here: update EstimatedRTT first, then compute DevRTT with the new EstimatedRTT, then the timeout. This follows the slide order. (RFC 6298 updates DevRTT first with the old estimate; follow whatever your instructor uses and state it.)
- Initial value of TimeoutInterval in the textbook is 1 second.
Karn's rule: ignore retransmissions (3-48, HW4 P33, sample 1.4)
Q (HW4 P33): In Section 3.5.3 we discussed TCP's estimation of RTT.
- Why do you think TCP avoids measuring the SampleRTT for retransmitted segments?
Q (sample midterm 1.4):
- Does TCP use the retransmitted packet to measure the round-trip time? Why?
- Rule: never take a SampleRTT from a retransmitted segment.
- Why: ambiguity. When the ACK comes back, the sender can't tell whether it answers the original or the retransmission.
- P33 story: P1 is sent, its timer expires, the copy P2 is sent. An ACK for P1 arrives shortly after P2 goes out. If the sender times from P2, it records a SampleRTT that is far too small. Timing from P1 when the ACK was really for P2 gives one that is too large.
- Sample 1.4 answer: No. TCP does not use the retransmitted packet to measure RTT, because the ACK can't be matched to a specific transmission, so the sample could be wrong.
Timer events in the sender (3-51, 3-52)
- Data from app: create a segment with seq # = byte-stream number of its first byte. Start the timer if not already running. The timer is for the oldest unACKed segment, expiration = TimeoutInterval.
- Timeout: retransmit the segment that caused the timeout (smallest unACKed seq #) and restart the timer.
- ACK received for previously unACKed data: update SendBase. Start the timer if unACKed segments remain.
- Timer doubling (textbook 3.5.4): on each timeout, TCP sets the next TimeoutInterval to twice the previous value instead of recomputing it. This gives limited congestion relief.
- Back to normal: when the timer restarts after new data from the app or a new ACK, TimeoutInterval comes from EstimatedRTT and DevRTT again.
How to solve: RTT and timeout updates
- Write down α (0.125), β (0.25), and the starting EstimatedRTT and DevRTT.
- EstimatedRTT ← 0.875·EstimatedRTT + 0.125·SampleRTT.
- DevRTT ← 0.75·DevRTT + 0.25·|SampleRTT − EstimatedRTT| (new EstimatedRTT).
- TimeoutInterval = EstimatedRTT + 4·DevRTT.
- Carry the new EstimatedRTT and DevRTT to the next sample. Skip any sample from a retransmitted segment.
Worked example: EstimatedRTT = 100 ms, DevRTT = 5 ms. Samples arrive: 120, 80, 110 ms.
Sample 1: SampleRTT = 120
Est = 0.875·100 + 0.125·120 = 87.5 + 15 = 102.5
Dev = 0.75·5 + 0.25·|120 − 102.5|
= 3.75 + 0.25·17.5 = 3.75 + 4.375 = 8.125
TO = 102.5 + 4·8.125 = 102.5 + 32.5 = 135 ms
Sample 2: SampleRTT = 80
Est = 0.875·102.5 + 0.125·80 = 89.6875 + 10 = 99.6875
Dev = 0.75·8.125 + 0.25·|80 − 99.6875|
= 6.09375 + 0.25·19.6875 = 6.09375 + 4.921875 = 11.015625
TO = 99.6875 + 4·11.015625 = 99.6875 + 44.0625 = 143.75 ms
Sample 3: SampleRTT = 110
Est = 0.875·99.6875 + 0.125·110 = 87.2265625 + 13.75 = 100.9765625
Dev = 0.75·11.015625 + 0.25·|110 − 100.9765625|
= 8.26171875 + 0.25·9.0234375 = 8.26171875 + 2.255859375 = 10.517578125
TO = 100.9765625 + 4·10.517578125 = 100.9765625 + 42.0703125 ≈ 143.05 ms
| Sample | SampleRTT | EstimatedRTT | DevRTT | TimeoutInterval |
|---|---|---|---|---|
| start | – | 100 | 5 | 120 |
| 1 | 120 | 102.5 | 8.125 | 135 |
| 2 | 80 | 99.69 | 11.02 | 143.75 |
| 3 | 110 | 100.98 | 10.52 | 143.05 |
The estimate barely moves (100 → 101) while the swings push DevRTT up, so the timeout grows from 120 to about 143 ms.
How to solve: expand the EWMA (HW4 P32)
- Write the recursion with α = x. SampleRTT1 is the most recent, SampleRTTn the oldest.
- Substitute the previous estimate into itself repeatedly.
- The oldest sample acts as the starting estimate, so it gets weight (1 − x)n−1 with no extra x.
Q (HW4 P32): Consider TCP's procedure for estimating RTT, with α = 0.1. Let SampleRTT1 be the most recent sample RTT, SampleRTT2 the next most recent, and so on.
- (a) For a given TCP connection, four ACKs have returned with sample RTTs SampleRTT4, SampleRTT3, SampleRTT2 and SampleRTT1. Express EstimatedRTT in terms of the four sample RTTs.
- (b) Generalize your formula for n sample RTTs.
(a) EstimatedRTT(4) = x·S1 + (1−x)[ x·S2 + (1−x)[ x·S3 + (1−x)·S4 ] ]
= x·S1 + (1−x)x·S2 + (1−x)²x·S3 + (1−x)³·S4
with x = 0.1:
= 0.1·S1 + 0.09·S2 + 0.081·S3 + 0.729·S4
check: 0.1 + 0.09 + 0.081 + 0.729 = 1 ✓
$$\text{(b)}\quad \text{EstimatedRTT}(n) = x\sum_{j=1}^{n-1}(1-x)^{j-1}\,\text{SampleRTT}_j \;+\; (1-x)^{n-1}\,\text{SampleRTT}_n$$
Matches the official solution. As n grows, (1 − x)n−1 → 0, so the oldest sample fades out. That is the "exponentially decreasing influence" on 3-49.
Traps
• α goes on the new sample, (1 − α) on the old estimate. Swapping them makes the estimate jump to each sample.
• Absolute value in DevRTT. Deviation is never negative.
• The timeout uses 4·DevRTT, not 4·EstimatedRTT and not 2·DevRTT.
• Carry the updated values into the next sample. Don't restart from the original numbers.
• State which EstimatedRTT you used in DevRTT (new, per the slide order).
• P32: the oldest sample has weight (1 − x)n−1, with no factor of x.
• Skip samples from retransmitted segments (Karn). After a timeout the interval doubles; it isn't recomputed from the formula.
• α goes on the new sample, (1 − α) on the old estimate. Swapping them makes the estimate jump to each sample.
• Absolute value in DevRTT. Deviation is never negative.
• The timeout uses 4·DevRTT, not 4·EstimatedRTT and not 2·DevRTT.
• Carry the updated values into the next sample. Don't restart from the original numbers.
• State which EstimatedRTT you used in DevRTT (new, per the slide order).
• P32: the oldest sample has weight (1 − x)n−1, with no factor of x.
• Skip samples from retransmitted segments (Karn). After a timeout the interval doubles; it isn't recomputed from the formula.
Quick check
1. What are α and β typically, and what is the timeout formula?
α = 0.125, β = 0.25. TimeoutInterval = EstimatedRTT + 4·DevRTT.2. EstimatedRTT = 200 ms, DevRTT = 10 ms, SampleRTT = 240 ms. New EstimatedRTT, DevRTT, timeout?
Est = 0.875·200 + 0.125·240 = 175 + 30 = 205 ms Dev = 0.75·10 + 0.25·|240 − 205| = 7.5 + 8.75 = 16.25 ms TO = 205 + 4·16.25 = 205 + 65 = 270 ms
3. EstimatedRTT = 80 ms, DevRTT = 8 ms, SampleRTT = 60 ms. New values and timeout?
Est = 0.875·80 + 0.125·60 = 70 + 7.5 = 77.5 ms Dev = 0.75·8 + 0.25·|60 − 77.5| = 6 + 4.375 = 10.375 ms TO = 77.5 + 4·10.375 = 77.5 + 41.5 = 119 ms
4. EstimatedRTT = 100 ms, DevRTT = 10 ms. Samples 140 then 100 ms. Timeout after each?
S=140: Est = 87.5 + 17.5 = 105
Dev = 7.5 + 0.25·35 = 7.5 + 8.75 = 16.25
TO = 105 + 65 = 170 ms
S=100: Est = 0.875·105 + 12.5 = 91.875 + 12.5 = 104.375
Dev = 0.75·16.25 + 0.25·|100 − 104.375| = 12.1875 + 1.09375 = 13.28125
TO = 104.375 + 53.125 = 157.5 ms5. EstimatedRTT = 40 ms, DevRTT = 4 ms. Samples 60 then 30 ms. Timeout after each?
S=60: Est = 35 + 7.5 = 42.5
Dev = 3 + 0.25·17.5 = 3 + 4.375 = 7.375
TO = 42.5 + 29.5 = 72 ms
S=30: Est = 0.875·42.5 + 3.75 = 37.1875 + 3.75 = 40.9375
Dev = 0.75·7.375 + 0.25·|30 − 40.9375| = 5.53125 + 2.734375 = 8.265625
TO = 40.9375 + 33.0625 = 74 ms6. P32 variant: α = 0.2, four samples with S1 (newest) = 100, S2 = 120, S3 = 80, S4 (oldest) = 90 ms. EstimatedRTT?
Weights: 0.2, 0.2·0.8 = 0.16, 0.2·0.8² = 0.128, 0.8³ = 0.512 (sum = 1).0.2·100 + 0.16·120 + 0.128·80 + 0.512·90 = 20 + 19.2 + 10.24 + 46.08 = 95.52 ms
7. EstimatedRTT went from 100 ms to 105 ms after a SampleRTT of 140 ms. What α was used?
105 = 100 + α(140 − 100) → 5 = 40α → α = 0.125.8. With α = 0.125, how much weight does a sample from 5 updates ago carry?
α(1 − α)5 = 0.125 · 0.8755 ≈ 0.125 · 0.513 ≈ 0.064, about 6%.9. TimeoutInterval is 143.75 ms. The segment times out twice in a row. What are the next two intervals?
Doubling on each timeout: 287.5 ms, then 575 ms. It returns to EstimatedRTT + 4·DevRTT once new data is ACKed.10. Does TCP use a retransmitted segment to measure RTT? Why? (sample 1.4, P33)
No (Karn's rule). The ACK is ambiguous: it could be for the original or the retransmission. If the original's ACK arrives just after the retransmission, timing from the retransmission gives a SampleRTT that is far too small.11. Why add 4·DevRTT instead of using EstimatedRTT alone?
EstimatedRTT is an average, so many real RTTs exceed it and would cause premature timeouts. The margin grows when RTTs vary a lot and shrinks when they're steady.12. Name the three sender events and what each does to the timer.
Data from app: start the timer if it isn't running. Timeout: retransmit the oldest unACKed segment and restart the timer. ACK for new data: advance SendBase and restart the timer if unACKed segments remain (else stop it).← prev · all topics · next →