Skip to content

fix(iroh): Poll all AsyncUdpSocket sources fairly #2996

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

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

flub
Copy link
Contributor

@flub flub commented Dec 3, 2024

Description

The existing AsyncUdpSocket::poll_recv polled the UDP IPv4 socket
first, only if that has no datagrams would it poll UDP IPv6 and only
also that had no datagrams to deliver was the relay socket polled.

This highly favoured IPv4 relay traffic, potentially starving the
relay traffic.

This change makes it prefer a different source on each poll. Meaning
if multiple sockets have data to deliver a fairer delivery happens.

Closes #2981.

Breaking Changes

Notes & open questions

  • Using Ordering::Relaxed is probably fine. I believe normally
    this polling would only happen from a single task (the Quinn
    endpoint driver) and even if it was polled concurrently from
    different threads it would not be that bad and still an improvement
    on the current order.

  • I'm not particularly fond of the implementation, but the macros is
    the best I could come up with. Maybe there's something cleverer
    which can be done.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

The existing AsyncUdpSocket::poll_recv polled the UDP IPv4 socket
first, only if that has no datagrams would it poll UDP IPv6 and only
also that had no datagrams to deliver was the relay socket polled.

This highly favoured IPv4 relay traffic, potentially starving the
relay traffic.

This change makes it prefer a different source on each poll.  Meaning
if multiple sockets have data to deliver a fairer delivery happens.
Copy link

github-actions bot commented Dec 3, 2024

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/2996/docs/iroh/

Last updated: 2024-12-03T15:38:17Z

Copy link

github-actions bot commented Dec 3, 2024

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: 39ba90c

Copy link
Member

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some nits, but otherwise I really like this. Especially the split off process_udp_datagrams function is a really good change!

flub and others added 2 commits December 3, 2024 15:31
@flub flub enabled auto-merge December 3, 2024 15:38
@flub flub added this pull request to the merge queue Dec 3, 2024
Merged via the queue into main with commit 26c5248 Dec 3, 2024
26 checks passed
@flub flub deleted the flub/magicsock-fair-poll-recv branch December 4, 2024 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

AsyncUdpSocket::poll_recv fairness
3 participants