-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: net: fetch all interfaces with associated addresses in a single call #53660
Comments
What specific new API do you propose to address this? Thanks. |
@ianlancetaylor I have updated the issue with the API proposal. |
@ianlancetaylor can you point me to benchmark tests that test with a number of interfaces? I found benchmark tests in |
Alternate API: the |
Not to my knowledge. |
#51934 is a report for efficiency / race / ignoring failures from k8s |
@seankhliao as you can see in the usage example I have specified, devices and interfaces are snapshots at slightly different times. This means that we should expect to see device indexes returned by 2nd call to be unknown to the interfaces() call. The only way to fix it is to get a full snapshot from the kernel, which i don’t think is available. |
interesting idea however, |
@ianlancetaylor any comments? Does a PR need to be implemented for all platforms or can start with Linux only ? |
This will go to review by the proposal review committee as described at https://go.dev/s/proposal. If we adopt this change, it needs to do something sensible on all platforms. Thanks. |
I think it makes perfect sense, both from a 'modeling perspective' (it's called a 'belongs to' relation) and based on the existing underlying That said, this seems like a Linux-specific issue that may not require any changes to the high-level API to resolve. An alternate platform-implementation-only fix would be for the Linux implementation of |
Background
At present if we want to get all interface and associated Addresses we write the following
I would like a function that returns this entire information.
Why is it needed ?
intf.Addrs()
call is inefficient because it results in getting the entire RIBsyscall.NetlinkRIB(syscall.RTM_GETADDR, syscall.AF_UNSPEC)
every time. The size of the RIB is proportional to the number of interfaces/Addrs. If on a router you have 1000s of interfaces thisO(n^2)
behaviour becomes untenable.When number of interfaces is small this problem does not show up.
details
The flamegraphs show excessive time spent making syscall and repeatedly parsing messages.
I also ran call count using
bpftrace
calcStats
function results inAfter I made the change to fetch the entire RIB and associate addresses in a single loop it makes significant change in the call counts and times.
Proposed API
Option 1
Keeps the flavor of existing
InterfaceAddrs
API.Typical use.
Option 2
Treat all the information above as a single DB and return it. More optimizations are possible with this API without changing the API signature.
The text was updated successfully, but these errors were encountered: