Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Concurrent polling on async methods #424
Concurrent polling on async methods #424
Changes from all commits
6e539bd
8f2be0e
1bc3cb6
3dd1b9a
1305bdc
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Currying?
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.
This is just how you have to call a variable that happens to be a function IIRC :D
(at least, I'm sure I've had to do similar before, but right offhand I can't think why.. and you don't have to do the same for closures that you declare... maybe I've just hit it when calling eg
(something.variable_that_is_fn)(params)
.. so is it actually needed here?)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.
Ok cool, this totally makes sense, now, its just calling the callback and passing in the params, I was distracted by the syntax for a second.. Thanks for clarification, definitely overlooked that.
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.
Should this be updated to 2021? (good reminder; need to add these to telemetry files..)
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.
We haven't updated those headers yet, I think it's just a copy-paste thingy.
I guess we should run a script and update all headers in another PR :)
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.
Nit: Just the one utility by the looks of it :D
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 keep thinking that this is quite similar to https://docs.rs/futures/0.3.16/futures/stream/struct.FuturesUnordered.html in some ways, and wonder whether it can be used to simplify some of the code here or not (I had a look at its implementation though; it's way more complicated than I'd have assumed!)?
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.
tokio is brought in a dependency just for
pin
?is there any difference between
tokio::pin
andfutures::pin
?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 had a gander, and both
tokio::pin
andfutures::pin_mut
have identical impls for this usage; the tokio version just supports an alternate usage as well (assign variable to async call, then pin it) that isn't useful here.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 guess this is the bit that is different from
FuturesUnordered
; it's basicallyFuturesUnordered
+ a "foreground" future that you care about the result of (and may need polling forever).I guess the "obvious" approach is to spawn the background futures into tasks and just await the "selector", and as you've noted, that's more costly.
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.
(which is sortof weird; the advantage of spawning the background future into a task is that it's only woken up once when the waker is called.
In this approach, every future is polled every time any of them are woken up to make progress. So, I'd have assumed that spawning onto separate tasks would actually be faster when you have a bunch of concurrent requests (and generally scale better), but this approach is faster when there are very few concurrent requests (and so the wakeups are less of an issue and the synchronisation cost relatively greater
When I was benchmarking telemetry I ran into a similar sortof thing; selecting just the two tasks (read from websocket and write to websocket) actually had a not negligable cost when one of those things was firing a lot and casuing the other one to be needlessly polled a bunch as a result.)