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.

~10 Gbit/sone tunnel, any tuning
45–49 Gbit/s16 tunnels, distinct ports
~0.7%TCP retransmits at full load

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:

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.

One tunnel VM traffic 1 send worker 1 UDP flow 1 receive queue one CPU limits the tunnel to ~10 Gbit/s Several tunnels, distinct ports VM traffic worker 1 worker 2 worker N flow 1, port A flow 2, port B flow N, port … queue 1 queue 2 queue N

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.

TunnelHost A portHost B portPorts in the hash
Same port5182051820cancel out: all tunnels on one link
Distinct ports5190051922differ: 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.

50 Gbit/s 1 tunnel ~10 5 tunnels, same port 24.5 8 tunnels, distinct 38.4 / 46.8 16 tunnels, distinct 44.9 / 48.7 plain TCP, no tunnel 46–49

Bars show the lower direction. Two numbers show each direction.

SetupGbit/s (each direction)RetransmitsLink use (receiver)
1 tunnel9–11.5–one link
5 tunnels, same port24.5–one link, other empty
8 tunnels × 8 streams38.4 / 46.80.8–1.1%23.0 + 15.6 Gbit/s
16 tunnels × 4 streams44.9 / 48.7~0.7%24.3 + 21.2 Gbit/s
Plain TCP, 64 streams46–490.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:

ChangeResult
CPU performance governor, deep C-states offno change
RPS (software spread of receive work)no change
Threaded NAPIalready 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 controlmuch worse: millions of drops
Real-time priority for NAPI threadswithin noise
skb_defer_max=0no 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:

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