Skip to main content

Transport Layer: TCP and UDP

TCP Flow and Congestion Control

0:00
LearnStep 1/3

Deep Dive into TCP State Management

The Dual-Window Mechanism

TCP throughput is governed by two independent window sizes: the Receive Window (rwnd) and the Congestion Window (cwnd). The effective transmission window is always min(rwnd, cwnd).

  • Flow Control (rwnd): Prevents the sender from overwhelming the receiver. The receiver advertises its available buffer space in every ACK.
  • Congestion Control (cwnd): Prevents the sender from overwhelming the network. This is estimated by the sender based on packet loss and RTT.

Congestion Control Algorithms

Standard TCP Reno/NewReno follows a specific lifecycle:

  1. Slow Start: cwnd starts at Initial Congestion Window (IW - usually 10 segments in modern Linux) and grows exponentially (doubles every RTT) until it hits the Slow Start Threshold (ssthresh).
  2. Congestion Avoidance: Once cwnd >= ssthresh, growth becomes linear (1 segment per RTT) to probe bandwidth cautiously.
  3. Fast Retransmit & Recovery: Triggered by 3 duplicate ACKs (packet loss without timeout). ssthresh is set to cwnd / 2, and cwnd is set to ssthresh + 3. This avoids the penalty of a full RTO (Retransmission Timeout).

TCP CUBIC

Linux's default congestion control, CUBIC, replaces the linear window growth of Reno with a cubic function dependent on the time since the last congestion event. This allows for:

  • Faster recovery on high-speed, high-latency (long fat) pipes.
  • Protocol fairness and stability.

Inspection Commands

You can inspect TCP connection states and window sizes on Linux using ss:

bash

To check or change the congestion control algorithm:

bash