Skip to content

Improve Linux performance of GetAllInterfaces#47

Open
wjordan wants to merge 1 commit intohashicorp:masterfrom
wjordan:linux-netinterfaces
Open

Improve Linux performance of GetAllInterfaces#47
wjordan wants to merge 1 commit intohashicorp:masterfrom
wjordan:linux-netinterfaces

Conversation

@wjordan
Copy link

@wjordan wjordan commented Jan 30, 2023

This Linux-specific optimization avoids a separate Netlink dump of addresses for each individual interface, which is prohibitively slow on servers with a large number (thousands) of network interfaces.

Here are some example test results on a sample server using the sockaddr eval command (which provides sockaddr.GetAllInterfaces() as template data), showing a ~100x performance improvement:

$ ls /sys/class/net | wc -l
3202

$ time ./sockaddr-orig eval 0
0

real	1m3.956s
user	0m36.514s
sys	0m55.716s

$ time ./sockaddr-opt eval 0
0

real	0m0.457s
user	0m0.096s
sys	0m0.443s

See golang/go#53660 for further discussion of this Linux performance issue with net.Interface.

This Linux optimization avoids a separate Netlink dump of addresses for each individual interface,
which is prohibitively slow on servers with large numbers of interfaces.
@dangra
Copy link

dangra commented Jul 29, 2025

+1 to Merge. It is a useful performance fix when dealing with tons of interfaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants