WireGuard multi-tunnel throughput
Two hosts with a 50 Gbit/s bond moved only about 10 Gbit/s through one WireGuard tunnel. 16 parallel tunnels with distinct ports move 45 to 49 Gbit/s.
The problem
Our hosts connect over a private network. Each host has two 25 Gbit/s links in one bond, so the total is 50 Gbit/s. A bond is a group of links that the kernel uses as one interface.
Plain TCP between two hosts moves about 49 Gbit/s. One WireGuard tunnel between the same hosts moves only 9 to 11.5 Gbit/s. That is about one fifth of the link.
Why one tunnel stops at 10 Gbit/s
Kernel WireGuard spreads the encryption over many CPUs. But some per-peer work runs on one CPU only:
- Send side: one worker thread puts all packets for a peer on the wire. It used about 70% of one CPU.
- Receive side: all packets of one tunnel have the same UDP source and destination. The network card (NIC) uses these values to select a receive queue, so all packets go to one queue and one CPU. That CPU was 75–92% busy.
More CPUs do not help, because the tunnel cannot use them. The fix is to make more tunnels, so that each tunnel gets its own worker and its own receive queue.
The trap: same port on both ends
Our first test used 5 tunnels, and each tunnel used the same port on both hosts. The result was 24.5 Gbit/s, and all traffic used one 25 Gbit/s link. The second link was empty.
The cause is the bond hash. The bond uses layer3+4 mode: it selects a link from a hash of the IP addresses and the ports. The hash combines the two ports with XOR. When the source port and the destination port are the same, XOR makes them cancel out. So every tunnel between two hosts gets the same hash and the same link.
The fix is simple: each tunnel uses a different port on each end. Then the ports do not cancel, and the tunnels spread over both links.
| Tunnel | Host A port | Host B port | Ports in the hash |
|---|---|---|---|
| Same port | 51820 | 51820 | cancel out: all tunnels on one link |
| Distinct ports | 51900 | 51922 | differ: tunnels spread over both links |
Results
Each test ran for 30 seconds with 64 TCP streams in total, split evenly over the tunnels. The numbers are averages of two rounds in each direction.
Bars show the lower direction. Two numbers show each direction.
| Setup | Gbit/s (each direction) | Retransmits | Link use (receiver) |
|---|---|---|---|
| 1 tunnel | 9–11.5 | – | one link |
| 5 tunnels, same port | 24.5 | – | one link, other empty |
| 8 tunnels × 8 streams | 38.4 / 46.8 | 0.8–1.1% | 23.0 + 15.6 Gbit/s |
| 16 tunnels × 4 streams | 44.9 / 48.7 | ~0.7% | 24.3 + 21.2 Gbit/s |
| Plain TCP, 64 streams | 46–49 | 0.1–0.5% | both links |
Why 16 tunnels are better than 8
The bond and the switch place each flow on one link, and they do not know how large a flow is. With 8 large flows, one link often gets more flows than the other. With 16 smaller flows, the random placement is more even.
The data shows this. With 8 tunnels, the receiver links carried 23.0 and 15.6 Gbit/s. With 16 tunnels, they carried 24.3 and 21.2 Gbit/s. A more even load also means fewer short overloads on one link, so retransmits fell from 0.8–1.1% to about 0.7%.
What did not help
We tested these changes on one tunnel or on 8 tunnels. None of them gave a useful gain:
| Change | Result |
|---|---|
| CPU performance governor, deep C-states off | no change |
| RPS (software spread of receive work) | no change |
| Threaded NAPI | already the default for WireGuard |
| wireguard-go (userspace WireGuard) | 7.7–8.0 Gbit/s, slower than the kernel |
Larger NAPI budget (netdev_budget) | no change in drops |
| BBR congestion control | much worse: millions of drops |
| Real-time priority for NAPI threads | within noise |
skb_defer_max=0 | no change across two rounds |
The per-peer limit is in the WireGuard design, not in a tunable setting. Parallel tunnels are the change that works.
What production needs
The tests used temporary tunnels next to the production tunnel. To use this for VM traffic, the mesh needs these changes:
- N tunnel interfaces on each host, each with its own listen port. Each interface has all peers, so the peer count per interface does not change. 16 interfaces with 99 peers each are enough for a 100-host mesh.
- Distinct ports on each end of a tunnel, so that the bond hash spreads the tunnels over both links.
- The mesh receive hook on every tunnel interface, not only on the first one.
- Flow spread over the tunnels. Today the outer mesh header has a flow label of 0, so ECMP routing cannot spread it. Set the flow label from the inner flow, and add equal-cost routes over the N tunnels. One VM flow stays on one tunnel, so packets stay in order.
Limits. One VM flow still gets at most one tunnel, so about 10 Gbit/s. The gain is for many flows together. At full link load, retransmits stay at about 0.7%. That is normal for TCP on a full link, and it is close to plain TCP.
Test setup
- Two bare-metal hosts: AMD EPYC 7702 (128 threads), Linux kernel 7.0.
- NIC: Broadcom BCM57454, 2 × 25 Gbit/s in an 802.3ad bond with
layer3+4hash. - Jumbo frames: MTU 9000 on the network, 8940 on the WireGuard interfaces. Kernel WireGuard.
- Load:
iperf3, 64 TCP streams in total, 30 seconds, CUBIC congestion control. - Production VMs ran on the hosts during the tests. Their traffic stayed connected.