-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
runtime: Callbacks when a worker parks and unparks #4070
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
…lback in that case
|
I can rebase and force push a new version, but I've chosen not to for now to make it easier for existing reviewers to have a fresh look at the changes. |
|
The test failure doesn't repro on my Fedora machine, nor on a Mac I have access to - I'll leave it for now as I can't retry the failed check without a new push. If someone spots an easy fix or an easy repro plan (or can tell me that it's bad on |
|
I've restarted CI on the commit to check whether it's an issue with your PR or something else. Feel free to push empty commits if you want to restart CI. You can do this by passing |
|
This is similar to a suggestion from @carllerche in response to #1481. For reference, there is a fork of tokio v0.2 with a different approach to park callbacks here: That one passes a duration to a single callback (to handle |
That's solving a different problem, and while it's in the same area of code, I don't believe that one solution covers both problems. The branch you've pointed at, and Carl's suggestion, are both about the case where you're integrating This is trying to solve the problem of allowing code to react to the A combined solution feels like it'll be suboptimal for the cases I have in mind - I'm using Tokio's event loop, and I therefore don't want lots of spurious notifications; I just want to be able to stop threads parking if there's work they could be doing. |
|
Re-reading the thread you pointed me at. I think a better route for solving that problem would be to expose a way to add a That then gives you full access to everything that you could want for integrating an extra source of events to the |
|
I only have some review details on the comments in the PR. I'll merge the PR afterwards. |
|
I believe I've fixed everything - let me know if there's more work you want me to do before you merge this PR, and I'll get it done. |
Motivation
Tracking the idleness of the executor has several uses:
Rather than implement mechanisms for each of these things separately, implement a generic mechanism to let us implement these in libraries atop
tokio.Solution
Similar to the thread start and thread stop callbacks, provide callbacks when a worker thread is parked (goes idle), and unparked (resumes doing work). This allows users to implement anything that depends on tracking how idle the executor is on top of these callbacks - and (for example) the user could choose to call into
tracingto get idleness traces, or check their own work queue for work to do when the runtime is idle.Note that as per the documentation, there's room to get things badly wrong with
on_thread_unpark; I am not determined to keep this, but it feels useful to me in the idleness tracking use case despite the risks.Fixes: #3975