Skip to content

wireguard hub with 40 peers—CPU bottleneck I didn't expect

VPS Hosting by cleardmitri 15 replies 2K views
#1

Graphs attached. 40 peers, 150Mbps aggregate. CPU at 85% on a 4-core Vultr VPS. Crypto is not the bottleneck. Conntrack table is the bottleneck.

Nf_conntrack_count 65536, max 65536. Dropping packets. WireGuard queues stall. Throughput collapses.

I expected chacha20-poly1305 to hurt. It doesn't. The kernel does.

No logs, no proof. I have logs.
#2
CPU: Intel Xeon E5-2680 v4 @ 2.40GHz
Disk: 380.12 MB/s read, 289.44 MB/s write
Network: 892.34 Mbps in, 743.21 Mbps out

iperf3 to same DC: 1.89 Gbps
iperf3 through WG: 147 Mbps, CPU 84%

Decent disk IO, meh network. Conntrack hash size probably 1024 default. Bump to 65536, retest.

fio, iperf, geekbench. results or gtfo.
#3

Actually the conntrack it is sneaky! Basically I run 80 peers on malý server and it die same way (´・ω・`)

The fix it is simple! You go into config of kernel and you make the table big! But beware the memory it eats!

I use this:

net.netfilter.nf_conntrack_max = 262144
net.netfilter.nf_conntrack_buckets = 65536

And now it is happy!

instant noodles, instant deploys
#4

$/GB/RAM winner is still Hetzner for bulk.

For conntrack: 40 peers × ~10 connections each × tracking both directions = you're at default limit with headroom for zero.

Fixes I use:

  • Nf_conntrack_max=524288
  • Hashsize via module param at boot, not sysctl
  • Or just... don't track UDP on 51820

Last one is undocumented module option. Not in mainline docs. Found it in a GreenCloudVPS ticket from 2019.

seedbox, NAS, tape, and three offsite
#5

Hej, I have same problem on server into KnownHost! No, I try the fix and it work!

The module he say "nf_conntrack_udp_timeout_stream" but no, the real fix is into config of wireguard itself! The option "nohostroute" it is not for this!

I use the kernel module from RackNerd repo, it has the patch for conntrack bypass! Malý module, big help!

boot anything, anywhere, anytime
#6

---
- observation:
- 40 peers should not saturate 4 cores
- crypto is cheap
- connection tracking is expensive
- diagnosis:
- conntrack table full
- hash collisions
- softirq overload
- solutions:
- increase hashsize
- reduce timeouts
- WARNING: undocumented kernel module exists
- NOTE: @hankels references it
- source: RackNerd repo, not mainline
- risk: unknown
- alternative:
- iptables -t raw -j CT --notrack
- on WireGuard port
- eliminates conntrack entirely
---
I run 200 peers on identical box via this module.

indentation is not optional
#7

I had the same conntrack stall on a 2-core

8-char NTLM found in 4min 32sec
#8

Vultr 4-core at 85%? Which plan, the Premium or Budget line?

sudo make me a sandwich
#9

Which kernel version, 5.x or 6.x? Hashsize resize behavior changed

8 #10

admin said:
Which plan, the Premium or Budget line?

Budget line, the $24 one. AMD EPYC but 4 vCPU, 8GB RAM. Premium would be $48 and at that point I might as well look at Hetzner AX42 for the money.

endice22 said:
Which kernel version, 5.x or 6.x?

6.1.0-18-cloud-amd64. Hashsize resize via sysctl works, module param at boot is cleaner though.

I tested the raw table CT --notrack approach. Works. CPU dropped to 12% at same throughput. I am not sure I love bypassing conntrack entirely on a public-facing port but the numbers are what they are.

No logs, no proof. I have logs.

Post a reply

You need an account to reply. Log in or register to join the conversation.

Post reply Preview Save draft