Reading — step 1 of 5
Read
~1 min readProduction
Performance
WireGuard performance vs alternatives:
| Throughput (gigabit) | Latency added | CPU | |
|---|---|---|---|
| WireGuard (kernel) | Near line-rate | <1ms | Low |
| OpenVPN | 100-300 Mbps | 5-20ms | High |
| IPsec (kernel) | Near line-rate | 1-2ms | Medium |
| Tailscale (userspace WG) | 500-900 Mbps | 1-2ms | Low |
Why WireGuard fast:
- Kernel module: no syscall overhead for packet I/O.
- Single AEAD cipher: no negotiation, no fallback paths.
- Cryptographic routing: no separate ACL lookup.
- Minimal protocol: 4 packet types, no extensions.
Bottlenecks:
- AEAD encryption: ChaCha20 ~3-5 GB/s/core.
- TUN: kernel must copy packets in/out of userspace (for userspace VPN).
- AES-NI hardware: AES-GCM faster on CPUs with AES-NI; ChaCha20 wins on devices without.
Optimizations:
- Multi-queue NIC + RPS: distribute packet processing across cores.
- GSO/GRO: aggregate small packets at NIC level. Saves CPU.
- DPDK / XDP: kernel-bypass packet I/O for max throughput.
UDP fragmentation:
- TUN's MTU should be set ~1420 (1500 - 80 overhead) to avoid fragmentation.
- Don't fragment in inner: kernel drops oversized; ICMP back to source.
- Path MTU discovery via inner packets.
Multi-core scaling:
- Per-peer queues.
- Hash inner packet → CPU.
- Avoid lock contention.
Mobile / low-power:
- WireGuard's small packet count + ChaCha20 win on battery.
- Compared to OpenVPN, much less wake-up time on mobile.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…