WireGuard / wgctrl-go

Package wgctrl enables control of WireGuard interfaces on multiple platforms.
https://godoc.org/golang.zx2c4.com/wireguard/wgctrl
MIT License
727 stars 85 forks source link

Optimize merging device peers recieved over netlink #62

Closed DMarby closed 5 years ago

DMarby commented 5 years ago

Hi,

Thanks for your awesome work on this library!

While using the library against wireguard devices with a large amount of peers, I noticed a big slow-down and a significant increase in CPU usage. I narrowed it down to the code for merging the peer information sent across multiple netlink messages, so this PR contains an optimized version of that.

mdlayher commented 5 years ago

Thanks for the PR! I had suspected that I implemented this code in a very naive way. I'll take a closer look on Monday, but could you please share the performance numbers you are seeing before and after this patch? Thanks!

DMarby commented 5 years ago

When testing with 20.000 peers, running on an Intel Xeon E3-1230 v6, I'm seeing the Device(name) call take 5-10 seconds to finish previous to this patch, with this patch it's near instant (< 300ms)