Benchmarking TCP Congestion Control: BBR vs CUBIC Latency Testing on Linux
This guide details how to simulate network traffic and accurately measure the latency impact of different TCP congestion control algorithms (like Google's BBR versus the default CUBIC) on a Linux server environment.
Direct Diagnostic & Remediation Summary
- Check Current Algorithm: Execute
sysctl net.ipv4.tcp_congestion_controlto see which algorithm is active. - Set Desired Algorithm (Example BBR): Run
sudo sysctl -w net.ipv4.tcp_congestion_control=bbrto switch the kernel parameter temporarily. - Run Benchmark Test: Utilize a tool like iperf3 configured for throughput and latency measurement:
iperf3 -c [target_ip] -t 60.
This guide forces the system to use specific algorithms and measures throughput/latency using iperf3 under controlled conditions to quantify this difference.
Preparation: Installing Tools & Checking Baseline
Before testing, ensure all necessary tools are present and document the current network stack configuration. We must confirm that both BBR and CUBIC modules are available to the kernel.
- Install iperf3: Use your distribution's package manager to install the latest version of iperf3 on both client and server machines.
- Check Kernel Support: Verify that BBR is compiled into or loadable by the kernel.
sudo apt update && sudo apt install iperf3
After installation, run a baseline test to capture initial metrics.
iperf3 -V
Algorithm Switching: Forcing BBR and CUBIC
The core of the test involves temporarily overriding the default TCP congestion control setting. This requires root privileges.
- Check Current Setting: Determine which algorithm is active by reading system parameters.
- Switch to BBR (Test 1): Set the kernel parameter to use BBR for all subsequent tests.
- Switch back to CUBIC (Test 2): Reset the parameter to the default or desired comparison point, typically CUBIC.
# Check current setting
sysctl net.ipv4.tcp_congestion_control
# 1. Enable BBR (If not already enabled)
sudo sysctl -w net.core.default_qdisc=fq
sudo sysctl -w net.ipv4.tcp_congestion_control=bbr
Note: Some distributions may require loading the module explicitly using sudo modprobe tcp_bbr before setting parameters.
Execution: Running Controlled Benchmarks
Use iperf3 to generate sustained traffic loads while the algorithm is active. A longer duration (e.g., 60 seconds) helps stabilize measurements.
- Test BBR Performance: Run the client test targeting the server IP address (
[SERVER_IP]). - Test CUBIC Performance: Repeat the exact same test sequence after switching back to CUBIC.
# --- Test 1: BBR Active (Client Machine) --
iperf3 -c [SERVER_IP] -t 60 -R
# --- Switch Algorithm Back ---
sudo sysctl -w net.ipv4.tcp_congestion_control=cubic
# --- Test 2: CUBIC Active (Client Machine) --
iperf3 -c [SERVER_IP] -t 60 -R
Common Pitfalls & Advanced Diagnostics
If latency measurements are inconsistent, check the following areas:
- Firewall Interference: Ensure no local firewall (iptables/ufw) is rate-limiting or interfering with iperf3's outgoing packets. Temporarily disable it for testing if necessary.
- Hardware Offloading: Verify that TCP segmentation offload (TSE) and large send offload (LSO) are correctly enabled in the network interface card driver settings, as these impact throughput measurements significantly.
- Kernel Module Loading: If
sysctl -w ...fails to take effect, manually check module loading status withlsmod | grep tcp_bbr.
If latency spikes occur during the test, it often indicates queue buildup or microburst congestion rather than an algorithm failure.
Verification, Results & Long-Term Stability Validation
After completing the comparisons, always revert system settings to a known stable state. The primary validation is comparing the Mean Opinion Score (MOS) or the minimum achieved latency reported by iperf3 between the two algorithms.
- Revert System Settings: Set parameters back to default values for general stability.
- Run Final Baseline Check: Execute one last iperf3 test using the standard settings to confirm normal operation.
# Revert Congestion Control (If CUBIC was not the original)
sudo sysctl -w net.ipv4.tcp_congestion_control=cubic
# Clear temporary changes for robustness
sysctl -p
Key Takeaway: A lower average latency and higher sustained bandwidth under controlled, varying load conditions indicate superior performance for that specific algorithm in your use case.
sysctl net.ipv4.tcp_congestion_control
isperf3 -V
sudo sysctl -w net.core.default_qdisc=fq
sudo sysctl -w net.ipv4.tcp_congestion_control=bbr
sudo sysctl -w net.ipv4.tcp_congestion_control=cubic
iperf3 -c [SERVER_IP] -t 60 -R
sudo sysctl -p
Frequently Asked Questions
Why is this test necessary if my applications seem fine?
Applications might appear fine under light load, but the underlying TCP stack's handling of congestion (which dictates latency stability) can degrade significantly under unpredictable or high-volume traffic bursts. This test exposes that behavior.
What is the difference between BBR and CUBIC conceptually?
CUBIC uses a window-based approach that grows aggressively after periods of inactivity, which works well for bulk transfers but can overfill buffers. BBR models bandwidth and RTT directly, aiming to keep queues shallow, thus minimizing queuing delay (latency).
Can I run this test without root privileges?
No. Changing the kernel's default networking parameters (<code>net.ipv4.*</code>) requires elevated privileges (sudo/root access).
Need help implementing this solution?
Our cybersecurity and infrastructure engineers can audit, harden, or configure your systems directly.
Community Discussion & Confirmations (3)
Technical questions, hardware findings, and verified fix reports.