You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'll start by noting that whilst this is an issue, tokio doesn't currently support a clean solution for this, so it may not be something you want to resolve.
Problem statement
IFF:
Run in a loop over select!
There's a lot of data to read from kafka
Other futures are called inside `select!
Then:
The other futures will always return Pending, even when they could return data
The tokio executor might starve other tasks
Explanation
tokio implements cooperative scheduling, whereby tasks will willingly return Pending when they could return a result, in order to lead to a smoother overall execution flow1. This approximately works by tokio primitives always returning Pending if the last 128 .await calls returned Ready1.
As MessageStream doesn't use any tokio primitives, it will not voluntarily pause execution. If looping over select or similar, as it is the only call that does not pause, it will continue executing, starving all other branches.
I've been thinking about the approach, and I wonder if you'd be open to having a solution toggled by the tokio feature. Then if this is also noticed with other executors, if any of them are following a similar approach to co-operative scheduling their solutions could go under their own features.
I realise it's less than ideal, but would solve the problem in the short run and would hopefully be an easy lift if something like consume_budget is standardised in the future.
I'll start by noting that whilst this is an issue,
tokio
doesn't currently support a clean solution for this, so it may not be something you want to resolve.Problem statement
IFF:
select!
Then:
Pending
, even when they could return datatokio
executor might starve other tasksExplanation
tokio
implements cooperative scheduling, whereby tasks will willingly returnPending
when they could return a result, in order to lead to a smoother overall execution flow1. This approximately works bytokio
primitives always returningPending
if the last 128.await
calls returnedReady
1.As
MessageStream
doesn't use anytokio
primitives, it will not voluntarily pause execution. If looping overselect
or similar, as it is the only call that does not pause, it will continue executing, starving all other branches.Possible solutions
consume_budget
Pending
every XReady
stokio
's co-operative solution by calling into a no-op function (e.g. an async read onEmpty
The text was updated successfully, but these errors were encountered: