-
Notifications
You must be signed in to change notification settings - Fork 236
feat: Implement RelayDatagramsQueue
#2998
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
Conversation
Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/2998/docs/iroh/ Last updated: 2024-12-04T14:15:20Z |
|
||
match self.queue.pop() { | ||
Ok(value) => { | ||
self.waker.take(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW the Flag examples in AtomicWaker
don't bother with removing this waker if it is no longer needed. I really don't know anymore how much this matters. It depends on what suprious wakeups might happen or how concurrently this is called I guess.
This should be reasonably not-concurrently called IIUC, but then I don't understand why I had things not waking up in the broken version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yeah, not removing the waker here means you're generating another spurious wakeup AFAIU. Not terrible, but also not great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it result in spurious wakeups though? You're yielding an item instead of pending. So the task does not suspend and the runtime might(?)/should(?) now drop this waker and create a new one for the next poll?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course custom poll functions could mean some other poll decides to still return pending for other reasons. In that case you'll get spurious wakeups I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's exactly that case you describe. If another poll fn decides to return pending for other reasons, then there's no need to wake up the future if there's another item in the queue. The only reason to wake up the future is for the other poll fn's reasons.
edf5bb1
to
19a8f27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised that you joined the sender & receiver back into a single object, after complaining on my PR that they were like this. But... I don't mind.
Good naming though!
😂 Sorry about that. It's not that I want the sender & receiver to be separate necessarily. |
I take this part back. This is only the |
What if we re-use the same implementation for the send side 👀 (and only rename the variable names to |
Based on #2986
Description
Replaces
RelayRecvReceiver
andRelayRecvSender
with the (clonable & shared)RelayDatagramsQueue
.This queue contains a
ConcurrentQueue
(from the smol libraryconcurrent-queue
) and anAtomicWaker
.It should only be polled from one task.
If polled from multiple tasks, then tasks will overwrite each other's wakers.
Unfortunately we can't make it use
&mut Self
inpoll_recv
becausequinn
expects theAsyncUdpSocket
spoll_recv
interface to be&self
.This (un)fortunately doesn't have an effect on performance for me.
(The benchmark is completely broken half the time for some reason, but when it runs it produces normal numbers:)
And basically exactly the same times for the PR this is based on.
Breaking Changes
Notes & open questions
Todo
relay_datagrams_queue
instead ofrelay_recv_sender
orrelay_recv_channel
etc.Change checklist