Skip to content
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

Add cooperative task yielding to this runtime #83

Closed
notgull opened this issue Jul 16, 2022 · 4 comments
Closed

Add cooperative task yielding to this runtime #83

notgull opened this issue Jul 16, 2022 · 4 comments

Comments

@notgull
Copy link
Member

notgull commented Jul 16, 2022

tokio uses cooperative task yielding to improve tail latencies in the circumstance that a resource polled in a loop fails to yield, leading to starvation of other tasks. Something similar could be set up for async-io as well.

The Reactor already has a concept of "ticks", which are used to coordinate polling. My idea would be that each Source keeps track of the tick which it last returned Poll::Pending. If it compares tick and this theoretical last_pending_tick value and finds that the difference between the two is a large value (say, 10_000, but this could use some tweaking), pooling the Source automatically returns Pending.

Any thoughts on this? This could be a global counter as well, or maybe a thread-local one.

I would be willing to implement this if the functionality is desired.

@taiki-e
Copy link
Collaborator

taiki-e commented Jul 17, 2022

async-io previously had something similar, but it has been removed: 4e7cdb6

@notgull
Copy link
Member Author

notgull commented Jul 17, 2022

Why was it removed? Perhaps the RNG added too much overhead, or it yielded too much?

@taiki-e
Copy link
Collaborator

taiki-e commented Aug 8, 2022

I don't know the exact reason, but the tokio's cooperative scheduling had compatibility issues with various primitives in futures and tokio that do not participate in the cooperative scheduling. (maybe a popular one is this case, finally fixed by rust-lang/futures-rs#2551) I guess there may have been a similar problem.

@notgull
Copy link
Member Author

notgull commented Aug 17, 2022

That makes sense. I'll close this issue.

@notgull notgull closed this as completed Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants