DataDog / glommio

Glommio is a thread-per-core crate that makes writing highly parallel asynchronous applications in a thread-per-core architecture easier for rustaceans.
Other
3.12k stars 164 forks source link

`yield_task_queue_now` does not seem to make sense #674

Open ellutionist opened 2 months ago

ellutionist commented 2 months ago

Hi, I have used glommio for a while and I tried this api ExecutorProxy::.yield_task_queue_now, but it does not seem to work as expected.

Natually, when I see the name of this function, I think it yields the current TaskQueue and this queue will not be executed anymore in the current iteration of scheduler. (Specifically, an iteration of the loop in LocalExecutor::run https://github.com/DataDog/glommio/blob/master/glommio/src/executor/mod.rs#L1494). The scheduler is supposed to run other coroutine and poll IO, etc. However, when I actually used this function, I find my coroutine just keep running and running. Neither other task queues nor IO polling get any chance to run. I think this is a little bit wierd, since the function is called "yield_task_queue".

When I dive into the source code of the schedular, I find that in this function (https://github.com/DataDog/glommio/blob/master/glommio/src/executor/mod.rs#L1369), as long as there is runnable task in the current task queue, the queue will be repushed, regard less of whether it is yielded already. So I propose to take the yieldness into the consideration of need_repush(https://github.com/DataDog/glommio/blob/master/glommio/src/executor/mod.rs#L1423).