| name | jacobson-network-performance |
| description | Engineer network systems in the style of Van Jacobson, the architect of TCP congestion control who saved the internet from collapse. Emphasizes congestion avoidance, RTT-based adaptation, queue management, and understanding network dynamics. Use when optimizing network performance, implementing congestion control, or diagnosing latency issues. |
| tags | networking, performance, measurement, protocols, tcp, congestion, monitoring, throughput, latency |
Van Jacobson Network Performance Style Guide
Overview
Van Jacobson is the most influential network performance engineer in history. In 1988, when the internet was experiencing "congestion collapse" (throughput dropping to 0.1% of capacity), Jacobson developed the congestion control algorithms that saved it. His slow start, congestion avoidance, fast retransmit, and fast recovery algorithms are still the foundation of TCP today. He also created traceroute, tcpdump, and later CoDel—tools and algorithms that define how we understand and manage networks.
Core Philosophy
"The network is a shared resource. Every packet you send affects everyone else."
"Congestion is not a problem to be avoided—it's information to be used."
"Measure, don't guess. The network will tell you what's happening if you listen."
Jacobson's insight was that the network itself provides feedback about congestion through packet loss and delay. By responding to this feedback correctly, endpoints can cooperatively share bandwidth without central coordination. The key is measuring Round-Trip Time (RTT) accurately and responding to congestion signals promptly.
Design Principles
-
Conservation of Packets: In equilibrium, inject a new packet only when one leaves.
-
Additive Increase, Multiplicative Decrease (AIMD): Probe for bandwidth slowly, back off quickly.
-
RTT is Truth: Round-trip time tells you the network's state.
-
Self-Clocking: Use ACKs to pace transmission, not timers.
-
Respond to Congestion, Don't Cause It: Detect early, react appropriately.
The Congestion Control Algorithms
Slow Start
On connection start or after timeout:
cwnd = 1 MSS (or IW = 10 in modern TCP)
On each ACK received:
cwnd = cwnd + MSS (exponential growth)
Until:
cwnd >= ssthresh → enter Congestion Avoidance
OR packet loss → enter Fast Recovery
Slow Start Visualization:
RTT 1: [1] cwnd = 1
RTT 2: [2][3] cwnd = 2
RTT 3: [4][5][6][7] cwnd = 4
RTT 4: [8][9][10][11][12][13][14][15] cwnd = 8
↑
Exponential growth: doubles each RTT
Congestion Avoidance
When cwnd >= ssthresh:
On each ACK received:
cwnd = cwnd + MSS * (MSS / cwnd) (linear growth)
Equivalently: cwnd increases by 1 MSS per RTT
On packet loss (3 duplicate ACKs):
ssthresh = cwnd / 2
cwnd = ssthresh + 3 MSS
Enter Fast Recovery
On timeout:
ssthresh = cwnd / 2
cwnd = 1 MSS
Enter Slow Start
Congestion Avoidance Visualization:
cwnd
^
| /\
| / \ /\
| / \ / \
| / \ / \
| / \ / \
| / \/ \
| / ↓ loss: cwnd = cwnd/2
| / ← slow start
| /
+---------------------------------> time
ssthresh
Fast Retransmit and Fast Recovery
On receiving 3 duplicate ACKs (same ACK number):
# Packet was likely lost, not delayed
ssthresh = cwnd / 2
cwnd = ssthresh + 3 MSS (inflate for packets in flight)
Retransmit the missing segment
On each additional duplicate ACK:
cwnd = cwnd + MSS (keep inflating)
On new ACK (acknowledges new data):
cwnd = ssthresh (deflate to new window)
Enter Congestion Avoidance
RTT Estimation
Jacobson's Algorithm
class RTTEstimator:
"""
Jacobson's algorithm for RTT estimation.
The foundation of all TCP timing.
"""
def __init__(self):
self.srtt = None
self.rttvar = None
self.rto = 1.0
self.alpha = 1/8
self.beta = 1/4
self.K = 4
self.G = 0.001
def update(self, measured_rtt: float):
"""
Update RTT estimate with new measurement.
"""
if self.srtt is None:
self.srtt = measured_rtt
self.rttvar = measured_rtt / 2
else:
.rttvar = ( - .beta) * .rttvar + \
.beta * (.srtt - measured_rtt)
.srtt = ( - .alpha) * .srtt + \
.alpha * measured_rtt
.rto = .srtt + (.G, .K * .rttvar)
.rto = (, (, .rto))
.rto
():
.rto = (, .rto * )
Karn's Algorithm
class KarnRTTEstimator(RTTEstimator):
"""
Karn's algorithm: only measure RTT from non-retransmitted segments.
Avoids ambiguity about which transmission the ACK is for.
"""
def __init__(self):
super().__init__()
self.retransmitted = set()
def send_segment(self, seq_num: int, is_retransmit: bool):
"""Track which segments are retransmits."""
if is_retransmit:
self.retransmitted.add(seq_num)
else:
self.retransmitted.discard(seq_num)
def receive_ack(self, ack_num: int, measured_rtt: float):
"""
Only update RTT if segment wasn't retransmitted.
"""
if ack_num in self.retransmitted:
self.retransmitted.discard(ack_num)
return None
else:
return self.update(measured_rtt)
When Engineering Networks
Always
- Measure RTT continuously—it's your primary signal
- Respond to packet loss by reducing rate
- Use AIMD for stable convergence
- Implement exponential backoff on timeouts
- Consider the network as a shared resource
- Test under realistic congestion conditions
Never
- Send faster than ACKs arrive (violates self-clocking)
- Ignore packet loss (the network is telling you something)
- Use fixed timeouts (RTT varies enormously)
- Assume the network is empty (others share it)
- Measure RTT from retransmits (Karn's algorithm)
- React to single events (smooth your signals)
Prefer
- RTT-based signals over loss-based (less destructive)
- Gradual probing over aggressive sending
- Self-clocking over timer-based pacing
- Smooth estimates over instantaneous values
- Multiplicative decrease over additive (stability)
- End-to-end measurement over assumptions
Code Patterns
TCP Congestion Control Implementation
class JacobsonCongestionControl:
"""
Jacobson's TCP congestion control.
The algorithm that saved the internet.
"""
def __init__(self, mss: int = 1460):
self.mss = mss
self.cwnd = mss
self.ssthresh = 65535
self.state = 'SLOW_START'
self.dup_ack_count = 0
self.rtt_estimator = RTTEstimator()
def on_ack(self, bytes_acked: int, is_duplicate: bool, rtt: float = None):
"""
Process an ACK.
"""
if rtt is not None:
self.rtt_estimator.update(rtt)
if is_duplicate:
return self._on_duplicate_ack()
else:
self.dup_ack_count = 0
return self._on_new_ack(bytes_acked)
def _on_new_ack(self, bytes_acked: int):
"""Handle new ACK (acknowledges new data)."""
.state == :
.cwnd += .mss
.cwnd >= .ssthresh:
.state =
.state == :
.cwnd += .mss * .mss // .cwnd
.state == :
.cwnd = .ssthresh
.state =
{: .cwnd, : .state}
():
.dup_ack_count +=
.state == :
.cwnd += .mss
.dup_ack_count == :
.ssthresh = (.cwnd // , * .mss)
.cwnd = .ssthresh + * .mss
.state =
{: , : .cwnd}
{: .cwnd, : .state}
():
.ssthresh = (.cwnd // , * .mss)
.cwnd = .mss
.state =
.dup_ack_count =
.rtt_estimator.timeout_occurred()
{: , : .cwnd, : .rtt_estimator.rto}
() -> :
.cwnd
Traceroute Implementation
class Traceroute:
"""
Jacobson's traceroute: discover the path packets take.
Uses TTL expiration to elicit ICMP responses from routers.
"""
def __init__(self,
target: str,
max_hops: int = 30,
probes_per_hop: int = 3,
timeout: float = 5.0):
self.target = target
self.max_hops = max_hops
self.probes = probes_per_hop
self.timeout = timeout
def trace(self) -> List[Hop]:
"""
Trace the route to target.
"""
hops = []
target_reached = False
for ttl in range(1, self.max_hops + 1):
hop_results = []
for probe in range(self.probes):
result = self._send_probe(ttl)
hop_results.append(result)
if result.reached_target:
target_reached = True
hops.append(Hop(
ttl=ttl,
probes=hop_results,
addr=self._most_common_addr(hop_results),
))
if target_reached:
break
hops
() -> ProbeResult:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_TTL, ttl)
sock.settimeout(.timeout)
dest_port = + ttl
start_time = time.time()
:
sock.sendto(, (.target, dest_port))
icmp_sock = socket.socket(socket.AF_INET, socket.SOCK_RAW,
socket.IPPROTO_ICMP)
icmp_sock.settimeout(.timeout)
data, addr = icmp_sock.recvfrom()
rtt = (time.time() - start_time) *
icmp_type = data[]
icmp_type == :
ProbeResult(addr=addr[], rtt=rtt, reached_target=)
icmp_type == :
ProbeResult(addr=addr[], rtt=rtt, reached_target=)
socket.timeout:
ProbeResult(addr=, rtt=, reached_target=)
:
sock.close()
Network Diagnostic Tools
class NetworkDiagnostics:
"""
Jacobson-style network diagnostics.
Measure, don't guess.
"""
def measure_bandwidth_delay_product(self,
rtt_ms: float,
bandwidth_mbps: float) -> int:
"""
Calculate BDP: the amount of data "in flight" for full utilization.
BDP = RTT × Bandwidth
This determines optimal buffer and window sizes.
"""
rtt_seconds = rtt_ms / 1000
bandwidth_bytes_per_sec = bandwidth_mbps * 1_000_000 / 8
bdp_bytes = int(rtt_seconds * bandwidth_bytes_per_sec)
return bdp_bytes
def diagnose_congestion(self,
samples: List[RTTSample]) -> CongestionDiagnosis:
"""
Diagnose network congestion from RTT samples.
"""
if len(samples) < 10:
return CongestionDiagnosis(status='insufficient_data')
rtts = [s.rtt for s in samples]
min_rtt = min(rtts)
avg_rtt = sum(rtts) / len(rtts)
max_rtt = max(rtts)
buffering_delay = avg_rtt - min_rtt
variance = sum((r - avg_rtt) ** 2 for r in rtts) / len(rtts)
jitter = variance **
buffering_delay > min_rtt:
status =
recommendation =
buffering_delay > min_rtt * :
status =
recommendation =
jitter > min_rtt * :
status =
recommendation =
:
status =
recommendation =
CongestionDiagnosis(
status=status,
min_rtt=min_rtt,
avg_rtt=avg_rtt,
buffering_delay=buffering_delay,
jitter=jitter,
recommendation=recommendation,
)
() -> :
bandwidths = []
pair packet_pairs:
pair.dispersion > :
bw = pair.packet_size / pair.dispersion
bandwidths.append(bw)
bandwidths:
bandwidths.sort()
median_idx = (bandwidths) //
bandwidths[median_idx]
CoDel (Controlled Delay)
class CoDel:
"""
CoDel: Controlled Delay AQM.
Jacobson & Nichols' solution to bufferbloat.
Key insight: control delay, not queue length.
"""
def __init__(self,
target_delay_ms: float = 5.0,
interval_ms: float = 100.0):
self.target = target_delay_ms
self.interval = interval_ms
self.first_above_time = None
self.drop_next = 0
self.count = 0
self.dropping = False
def should_drop(self, packet: Packet, now_ms: float) -> bool:
"""
Decide whether to drop a packet.
CoDel only drops when queue delay persistently exceeds target.
"""
sojourn_time = now_ms - packet.enqueue_time
if sojourn_time < self.target:
self.first_above_time = None
return False
if self.first_above_time is None:
self.first_above_time = now_ms
return
now_ms - .first_above_time < .interval:
.dropping:
.dropping =
.count =
.drop_next = now_ms + .interval
now_ms >= .drop_next:
.count +=
.drop_next = now_ms + .interval / (.count ** )
() -> [Packet]:
packet = queue.peek()
packet :
.dropping =
.should_drop(packet, now_ms):
queue.pop()
.dequeue(queue, now_ms)
queue.pop()
Mental Model
Jacobson approaches network performance by asking:
- What does the RTT tell me? It's the network's heartbeat
- Is there packet loss? The network signaling congestion
- Am I being fair? Others share this resource
- Am I measuring or guessing? Always measure
- What's the delay vs. throughput tradeoff? Optimize for the use case
The Network Performance Checklist
□ Measure RTT continuously and accurately
□ Respond to congestion signals (loss, delay)
□ Use AIMD for stable convergence
□ Implement proper timeout calculation (Jacobson's algorithm)
□ Follow Karn's algorithm for retransmit RTT
□ Understand your bandwidth-delay product
□ Check for bufferbloat (RTT under load vs idle)
□ Use appropriate queue management (CoDel/fq_codel)
Signature Jacobson Moves
- Slow start and congestion avoidance
- Fast retransmit and fast recovery
- RTT estimation with variance (Jacobson's algorithm)
- Self-clocking via ACK pacing
- AIMD (Additive Increase, Multiplicative Decrease)
- CoDel active queue management
- traceroute and tcpdump
- Conservation of packets principle