Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Reduce netroute syscalls #238

Closed
Stebalien opened this issue Oct 27, 2021 · 3 comments
Closed

Reduce netroute syscalls #238

Stebalien opened this issue Oct 27, 2021 · 3 comments

Comments

@Stebalien
Copy link
Member

Some... let's call them power users... seem to enjoy abusing their systems by dialing as fast as possible. Unfortunately, this means we're wasting a lot of CPU cycles on determining source addresses in:

if router, err := netroute.New(); err == nil {
_, _, src, err := router.Route(raddr.IP)
if err == nil && !src.IsUnspecified() {
ip = &src
}
}

Ideally, we'd:

  1. Skip this entire thing if we aren't actually listening on any unicast addresses (just global addresses).
  2. Cache? Honestly, we can probably cache route information until our unicast listeners change.

cpu

@marten-seemann
Copy link
Collaborator

Ideally, we'd:

  1. Skip this entire thing if we aren't actually listening on any unicast addresses (just global addresses).
  2. Cache? Honestly, we can probably cache route information until our unicast listeners change.

We can probably optimize this somehow, but will it save the power user's problem? Assume for the moment that we had optimized this so far that this code path becomes essentially free. Then they'd end up with tons of QUIC connections (assuming that a non-negligible fraction of the dials succeed).
My (unproven) assumption here is that the single syscall to netroute here is cheaper than the sum of the syscalls (and the handshake crypto) that a QUIC connection would cause.

Am I missing something?

@willscott
Copy link
Contributor

Making a netroute router fetches the routing table from the kernel which is fairly expensive on creation.

@whyrusleeping
Copy link

I'm not doing anything special, my connection manager has a setting of 2000/3000/1m and im running a dht node.

Stebalien added a commit that referenced this issue Oct 28, 2021
Technically, someone can set net.ipv4.ip_nonlocal_bind=1 to bind to
non-existent IP addresses, but I'm comfortable making this change and
seeing if anyone complains. I highly doubt it'll have any impact.

If it doesn't work out, we have other options (e.g., catch the "invalid
route" error and try again).

fixes #238
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants