Stage 3 · Build
Network Debugging in Production
Network Performance
iperf3, bandwidth testing, MTU issues, and network throughput optimization.
iperf3 for Bandwidth Testing
iperf3 is the standard tool for measuring network bandwidth. It tests TCP and UDP throughput between two endpoints, with options for parallel streams, window size, and MTU settings.
# Start iperf3 server
iperf3 -s
# TCP bandwidth test (client)
iperf3 -c server-ip
# UDP bandwidth test
iperf3 -c server-ip -u -b 100M
# Parallel streams (4 clients)
iperf3 -c server-ip -P 4
# Bidirectional test
iperf3 -c server-ip --bidir
# Reverse mode (server sends to client)
iperf3 -c server-ip -R
# Test with specific window size
iperf3 -c server-ip -w 256K
# JSON output for scripting
iperf3 -c server-ip -J | jq '.end.sum_sent.bits_per_second'iperf3 measures the maximum achievable bandwidth. If iperf3 shows 900 Mbps but your application only gets 100 Mbps, the bottleneck is application-level (serialization, processing) not network-level.
Throughput Debugging
# Check current TCP stats
ss -ti dst server-ip
# Key fields:
# cwnd: congestion window (small = TCP is conservative)
# ssthresh: slow start threshold
# rtt: round-trip time
# retrans: retransmission count
# High retransmissions = packet loss
# Small cwnd = recent packet loss
# High rtt = latency issue
# Check interface errors
ip -s link show eth0
# RX errors, TX errors, dropped = problems
# Check for packet drops at driver level
ethtool -S eth0 | grep -i error
ethtool -S eth0 | grep -i dropThroughput problems have three causes: packet loss (retransmissions reduce throughput), latency (high RTT limits TCP window growth), or bandwidth limits (physical link capacity). iperf3 and ss tell you which one.
TCP Tuning for Performance
# Increase TCP buffer sizes
sudo sysctl -w net.core.rmem_max=16777216
sudo sysctl -w net.core.wmem_max=16777216
sudo sysctl -w net.ipv4.tcp_rmem="4096 87380 16777216"
sudo sysctl -w net.ipv4.tcp_wmem="4096 65536 16777216"
# Enable TCP window scaling
sudo sysctl -w net.ipv4.tcp_window_scaling=1
# Enable TCP timestamps
sudo sysctl -w net.ipv4.tcp_timestamps=1
# Increase congestion window
sudo sysctl -w net.ipv4.tcp_slow_start_after_idle=0
# Enable BBR congestion control (Linux 4.9+)
sudo sysctl -w net.core.default_qdisc=fq
sudo sysctl -w net.ipv4.tcp_congestion_control=bbrBBR (Bottleneck Bandwidth and Round-trip propagation time) is Google's congestion control algorithm. It achieves higher throughput than CUBIC on lossy links because it estimates bandwidth and RTT instead of treating loss as the congestion signal.
The Bandwidth-Delay Product tells you how much data TCP needs to have in flight to fill the pipe. A 1 Gbps link with 10ms RTT needs 1.25 MB in flight. If the TCP buffer is smaller, you cannot achieve full throughput.
Network Optimization Patterns
Reduce round trips:
- HTTP/2 multiplexing (avoid HOL blocking)
- Connection pooling (reuse TCP connections)
- Keep-Alive (avoid repeated handshakes)
- 0-RTT TLS resumption
Reduce data transfer:
- Compression (gzip, brotli)
- Delta sync (send only changes)
- Pagination (send only what is needed)
- CDN (serve from edge)
Optimize TCP:
- BBR congestion control
- Larger TCP buffers
- Window scaling for high-BDP links
- Disable Nagle's algorithm for low-latencyNetwork optimization is about reducing round trips (latency) and data transfer (bandwidth). For latency-sensitive applications, connection pooling and multiplexing matter most. For throughput, TCP tuning and compression matter most.
Network Performance Monitoring
# Real-time bandwidth monitoring
iftop -i eth0
# Per-connection bandwidth
nload eth0
# Check interface statistics
sar -n DEV 1
# Monitor TCP retransmissions
watch -n 1 'ss -ti | grep retrans'
# Prometheus metrics for network
# node_network_receive_bytes_total
# node_network_transmit_bytes_total
# node_netstat_Tcp_RetransSegsSet up monitoring for: bandwidth utilization (do not exceed 70% sustained), TCP retransmission rate (should be < 0.1%), connection count, and latency percentiles (p50, p95, p99). Alert on anomalies.
Keep network utilization below 70%. Beyond that, queuing increases latency significantly. If you are consistently above 70%, upgrade bandwidth or optimize the application to send less data.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.