Sub topic 11
Congestion control: slow start and congestion avoidance
This chapter assumes you know how TCP sequence numbers, acknowledgments and retransmission work, and that you know the receive window from flow control. It covers how a sender decides how fast to send when the limit is the network, not the receiver.
Why flow control is not enough
Flow control protects the receiver. The receiver advertises a window, and the sender never has more unacknowledged data in flight than that window allows. The receiver can be fast and the sender polite, and the network between them can still be overloaded.
Congestion is the state where routers receive packets faster than they can forward them. A router holds the excess in a queue. When the queue is full, it drops packets. Dropped packets cause retransmissions, and retransmissions add load, so a network with no congestion control can collapse. In the 1980s the Internet had this problem, and TCP congestion control was added in response.
IP gives the sender no explicit signal about how much capacity the path has. TCP therefore infers it from what it can observe: acknowledgments arriving, acknowledgments not arriving, and sometimes explicit marks from routers.
| Mechanism | Protects | Signal it reacts to | Variable |
|---|---|---|---|
| Flow control | The receiver's buffer | Window field in each ACK | `rwnd` |
| Congestion control | The network path | Loss, delay or ECN marks | `cwnd` |
The congestion window
Each sender keeps a second limit called the congestion window, cwnd. It is the number of bytes the sender may have in flight, based on its estimate of what the network can carry. It is measured in bytes but is often described in segments, where one segment is one maximum segment size (MSS).
The sender is bound by both limits at once:
bytes in flight <= min(cwnd, rwnd)If rwnd is 64 KB and cwnd is 10 KB, the sender may have only 10 KB outstanding. If cwnd grows to 200 KB, the receiver's 64 KB window is the limit. Congestion control is the set of rules that raises and lowers cwnd.
A rough throughput estimate follows from this. In one round-trip time (RTT) the sender can transmit about one window of data, so:
throughput ≈ min(cwnd, rwnd) / RTTWith cwnd of 100 KB and an RTT of 50 ms, throughput is about 2 MB/s. This is why long-RTT paths need large windows to fill a fast link.
Slow start
A new connection has no information about the path. Starting at full speed risks flooding it, and starting at one packet forever wastes capacity. Slow start is the phase that probes quickly.
The sender begins with a small cwnd. Modern stacks use an initial window of 10 segments (RFC 6928); older ones used 1 to 4. For every ACK that acknowledges new data, cwnd grows by one MSS. Since a full window of segments produces a full window of ACKs per RTT, the window roughly doubles each round trip.
The name is misleading. Growth is exponential, so slow start is fast. It is "slow" only in comparison with sending at line rate immediately.
| RTT | cwnd (segments) |
|---|---|
| 0 | 10 |
| 1 | 20 |
| 2 | 40 |
| 3 | 80 |
| 4 | 160 |
Slow start ends in one of two ways:
cwndreaches the slow start threshold,ssthresh. The sender then switches to congestion avoidance.- A loss is detected. The sender reduces
cwndandssthresh, as described below.
The initial ssthresh is often set very high, so the first exit from slow start is usually caused by a loss.
Congestion avoidance
Once cwnd reaches ssthresh, the sender is near the point where it expects trouble. It stops doubling and grows cautiously. In classic congestion avoidance, cwnd increases by about one MSS per RTT, not per ACK. The usual per-ACK formula is:
cwnd += MSS * MSS / cwndSummed over one window of ACKs, this adds about one MSS. Growth is linear, not exponential.
The sender keeps adding capacity until it hits a loss. Then it cuts the window. This pattern is called additive increase, multiplicative decrease (AIMD). Additive increase probes gently for spare capacity. Multiplicative decrease backs off quickly when the network signals overload. AIMD is the reason several TCP flows sharing a bottleneck converge toward roughly equal shares.
Reacting to loss
TCP treats packet loss as a congestion signal. It detects loss in two ways, and the response differs.
Timeout
If the retransmission timer expires, no ACKs are arriving at all. This is the severe case. The sender assumes the network is badly congested and does the following:
- Sets
ssthreshto half the amount of data in flight, with a floor of two segments. - Sets
cwndto one segment (the loss window). - Retransmits the lost segment and re-enters slow start.
Triple duplicate ACK
If one segment is lost but later segments arrive, the receiver sends a duplicate ACK for each of them, repeating the same acknowledgment number. Three duplicate ACKs trigger fast retransmit: the sender resends the missing segment immediately, without waiting for the timer.
Because ACKs are still flowing, the network is still delivering data. The sender responds more gently, using fast recovery:
- Sets
ssthreshto half the amount in flight. - Sets
cwndtossthresh(plus a small allowance for the duplicate ACKs). - Continues in congestion avoidance, not slow start.
This distinction is the core of the classic Reno algorithm. A timeout is treated as a crisis and a triple duplicate ACK as a mild warning.
A simulation you can run
The following Python program models the Reno rules in units of segments, one step per RTT. It is a simplification: it ignores individual ACK timing and queueing, but it reproduces the sawtooth shape of cwnd.
def simulate(rounds, loss_at, timeout_at, init_cwnd=10, ssthresh=64):
cwnd = float(init_cwnd)
history = []
for rtt in range(rounds):
history.append((rtt, round(cwnd, 1), ssthresh))
if rtt in timeout_at:
ssthresh = max(cwnd / 2, 2)
cwnd = 1.0
elif rtt in loss_at:
ssthresh = max(cwnd / 2, 2)
cwnd = ssthresh
elif cwnd < ssthresh:
cwnd = min(cwnd * 2, ssthresh)
else:
cwnd += 1
return history
if __name__ == "__main__":
for rtt, cwnd, ssthresh in simulate(
rounds=24, loss_at={12}, timeout_at={18}
):
print(f"RTT {rtt:2d} cwnd={cwnd:6.1f} ssthresh={ssthresh:5.1f}")Reading the output, you will see:
cwnddoubles from 10 to 20, 40 and 64, where it meetsssthresh.- It then grows by one segment per RTT.
- At RTT 12 a triple-duplicate-ACK loss halves it, and linear growth resumes.
- At RTT 18 a timeout drops it to 1 segment, and slow start begins again with a lower
ssthresh.
Edge cases and common errors
Loss is not always congestion
Classic TCP assumes loss means congestion. On wireless links, packets are sometimes lost to radio interference. The sender cuts its window anyway, and throughput suffers though the network has spare capacity. Link-layer retransmission, explicit congestion notification and newer algorithms reduce this problem.
Small transfers never leave slow start
A short HTTP response of a few kilobytes may complete inside the initial window. The transfer time is then set by RTT and the handshake, not by the link bandwidth. This is why raising the initial window helped web latency, and why a fast link does not make small requests faster.
Idle connections
After a connection sits idle, the old cwnd may no longer describe the path. Many stacks reset cwnd after an idle period (slow-start restart). Long-lived connections that send in bursts can see reduced throughput after each pause. Some systems let you disable this behavior, for example the Linux setting net.ipv4.tcp_slow_start_after_idle.
Multiple connections get more than a fair share
Congestion control is applied per connection. An application opening ten parallel connections gets roughly ten shares of a bottleneck. This is a reason browsers cap connections per host and a reason HTTP/2 multiplexes requests over one connection.
Confusing the two windows
A frequent mistake is to raise the receive buffer and expect higher throughput on a lossy path. The receive window raises only the flow-control ceiling. If cwnd is the limiting value, a bigger rwnd changes nothing. To diagnose, check which of the two is smaller at the sender.
Algorithm variants
Reno is the baseline for teaching. Production systems use other algorithms.
| Algorithm | Main signal | Notes |
|---|---|---|
| Reno / NewReno | Loss | Classic AIMD, NewReno handles several losses in one window better |
| CUBIC | Loss | Window grows as a cubic function of time since the last loss, default on Linux |
| BBR | Estimated bandwidth and RTT | Models the path instead of waiting for loss, can coexist poorly with loss-based flows |
On Linux you can inspect and change the algorithm, and watch the live state of a connection:
sysctl net.ipv4.tcp_congestion_control
ss -ti dst 93.184.216.34The ss -ti output includes fields such as cwnd, ssthresh, rtt and retrans for each connection.
Explicit congestion notification
With explicit congestion notification (ECN), a router marks packets in the IP header when its queue is building, instead of dropping them. The receiver echoes the mark back, and the sender reduces cwnd as if it had seen a loss, but with no retransmission needed. ECN requires support at both endpoints and on the routers along the path.
UDP and congestion
UDP has no congestion control. A UDP sender can transmit at any rate, and it will not slow down when routers drop its packets. Applications that use UDP at high volume, such as streaming and real-time media, are expected to implement their own rate adaptation. Protocols built on UDP, such as QUIC, include congestion control in the protocol itself. An application that floods a path with UDP can starve well-behaved TCP flows.
Summary of the rules
| Event | ssthresh | cwnd | Next phase |
|---|---|---|---|
| New ACK in slow start | unchanged | +1 MSS per ACK | Slow start, or avoidance at ssthresh |
| New ACK in avoidance | unchanged | about +1 MSS per RTT | Congestion avoidance |
| Triple duplicate ACK | half of data in flight | equal to ssthresh | Fast recovery, then avoidance |
| Timeout | half of data in flight | 1 MSS | Slow start |
Exercise
A Reno sender is in congestion avoidance with cwnd = 40 segments and all 40 are in flight. It receives three duplicate ACKs. Then, after recovering, it later suffers a timeout while 24 segments are in flight. What are ssthresh and cwnd after the duplicate ACKs, and after the timeout? Which phase follows each event?
Show answer
After the three duplicate ACKs, ssthresh = 20 segments and cwnd = 20 (ignoring the small inflation during recovery). The sender goes through fast recovery and continues in congestion avoidance. After the timeout with 24 segments in flight, ssthresh = 12 segments and cwnd = 1 segment. The sender re-enters slow start and doubles its window each RTT until cwnd reaches 12, then switches to congestion avoidance.
Exercise
A connection has an RTT of 100 ms, rwnd of 256 KB and a current cwnd of 32 KB. Estimate its throughput. Then say what limits it, and whether increasing the receive buffer would help.
Show answer
Throughput is about min(cwnd, rwnd) / RTT = 32 KB / 0.1 s = 320 KB/s. The congestion window is the limit, because 32 KB is smaller than 256 KB. Increasing the receive buffer would not help. The sender must grow cwnd, which happens through ACKs arriving without loss.
Exercise
Why does a 5 KB web response over a 1 Gbit/s link often take roughly the same time as over a 100 Mbit/s link?
Show answer
The transfer is small enough to fit in the initial window of about 10 segments (around 14 KB), so it finishes within one or two round trips. The time is dominated by RTT and handshake delay, not by link bandwidth, and the connection never leaves slow start long enough to use the extra capacity.