# BBR Congestion Control for VPN Performance

## What is BBR?

BBR (Bottleneck Bandwidth and Round-trip propagation time) is a TCP congestion control algorithm developed by Google. It provides significantly better performance on high-latency and lossy networks compared to traditional algorithms like Cubic.

## Benefits for VPN

- **Reduced latency**: 40-65% improvement in typical VPN scenarios
- **Lower jitter**: More consistent response times
- **Better throughput**: Handles network congestion more gracefully
- **Faster recovery**: Bounces back quickly from network issues

## Installation and Setup

### Quick Setup

```bash
# Load BBR kernel module
modprobe tcp_bbr

# Set BBR as default congestion control algorithm
sysctl -w net.core.default_qdisc=fq
sysctl -w net.ipv4.tcp_congestion_control=bbr

# Verify it's active
sysctl net.ipv4.tcp_congestion_control
# Should return: net.ipv4.tcp_congestion_control = bbr

lsmod | grep bbr
# Should show: tcp_bbr    20480  1
```

### Persistent Configuration

```bash
# Add to sysctl.conf for persistence
cat >> /etc/sysctl.conf << 'EOF'

# BBR congestion control optimization
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
EOF

# Ensure BBR module loads on boot
echo "tcp_bbr" >> /etc/modules-load.d/bbr.conf

# Apply settings
sysctl -p
```

## Verification

After enabling BBR, verify performance improvement:

```bash
# Test latency before and after
ping -c 10 10.0.0.2

# Look for:
# - Lower min/avg/max latency
# - Lower mdev (standard deviation = jitter)
# - More consistent response times
```

## Expected Performance Improvements

Based on real-world testing with WireGuard:

| Metric | Before (Cubic) | After (BBR) | Improvement |
|--------|---------------|-------------|-------------|
| Min latency | 756ms | 265ms | 65% reduction |
| Avg latency | 1282ms | 895ms | 30% reduction |
| Jitter (mdev) | ~1000ms | ~500ms | 50% reduction |

## Requirements

- Linux kernel 4.9+ (BBR support)
- Root/sudo access
- WireGuard or other VPN

## Troubleshooting

**BBR not loading:**
```bash
# Check kernel version
uname -r  # Should be 4.9+

# Check if BBR is built into kernel
modinfo tcp_bbr 2>&1
```

**No performance improvement:**
- Ensure MTU is also optimized (BBR works best with proper MTU)
- Test both client and server (BBR should be enabled on both ends)
- Verify network path isn't saturated

## Compatibility

BBR is safe to use alongside other optimizations:
- MTU tuning (recommended)
- WireGuard default settings
- System-level network tuning

## References

- Google BBR paper: https://queue.acm.org/detail.cfm?id=3022184
- Linux BBR documentation: https://www.kernel.org/doc/Documentation/networking/tcp-bbr.txt
