-
Notifications
You must be signed in to change notification settings - Fork 628
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
Avoid starvation from FuturesUnordered::poll_next #2049
Conversation
I'm unsure about this. Overall, I think we need some better way to address this issue globally, as this behavior is also an issue with every other kind of Future/Stream/asynchronous function. If a task has work remaining that can be done, it will never yield to the executor. Making every single looping combinator track a maximum poll count seems like a possibility, but it seems like the kind of practice we'd want some discipline around, rather than picking arbitrary integers which will stack exponentially (with this PR, the limit of leaf-future polls for a |
Yup, I agree it's not ideal, which is why I also proposed tokio-rs/tokio#2160 as a more "complete" fix. I actually argued the exact same point about exponentials in the tokio Discord a few hours ago as a reason why we ultimately want a more global mechanism :p I do think we need a solution in the short run too though, as global preemption is probably something that will take longer to settle, and this is certainly an issue right now (for example, I am running into it in Noria as we speak). |
I agree w/ @cramertj. IMO this should be tracked at the runtime task level and leaf resource operations should be the ones to impact the poll budget. |
Merging-- see discussion ongoing in #2047 |
@cramertj What's the procedure for doing a patch release with this change? |
@jonhoo I'll put one out this week! Are you under time pressure? If so, I'll can try and do one tomorrow (the 28th). |
Nope, no rush on my end. I'm using it in https://github.com/mit-pdos/noria, but we're fine using patches in |
@cramertj Any update on a release for this? Would be nice to get rid of the patches. |
Yup, I'm doing one today! |
Thanks for the feature @jonhoo. How are executor expected to use this feature? When checking for events (e.g. epoll) executors need to know if they should:
|
@jsancio I'm not entirely sure I follow? Whenever |
Thanks @jonhoo. Yeah, it makes sense. I missed the part that |
This backports rust-lang#2049 to the 0.1 branch. Without this change, polling > 200 futures trough a FuturesUnordered on a Tokio 0.2 executor results in a busy loop in Tokio's cooperative scheduling module. See for a repro of where this breaks: tokio-rs/tokio#2390 Tested by running the reproducer I submitted there. Without this change, it hangs forever (spinning on CPU). With the change, it doesn't.
This backports #2049 to the 0.1 branch. Without this change, polling > 200 futures trough a FuturesUnordered on a Tokio 0.2 executor results in a busy loop in Tokio's cooperative scheduling module. See for a repro of where this breaks: tokio-rs/tokio#2390 Tested by running the reproducer I submitted there. Without this change, it hangs forever (spinning on CPU). With the change, it doesn't.
This fixes #2047.