Rust tokio 调度程序工作窃取与全局队列

Rust tokio scheduler work steal vs global queue

在 rust tokio 中,当处理器完成 运行 队列中的所有任务时,它们是先查看全局队列以寻找更多任务,还是先尝试从兄弟处理器中窃取工作?

鉴于这是未记录的,我认为它是未指定的并且不是图书馆保证的一部分,除非您可以通过问题或 PR 接受来指定此行为。我强烈建议不要依赖于当前的行为。

话虽这么说,“使用代码 luke”仅一步之遥:运行 主循环将是 Context::run. When the local queue is empty, it calls Core::steal_work,它首先开始从兄弟姐妹那里窃取工作,然后回退到全局队列。

请注意,调度程序会在正常操作期间偶尔尝试从全局队列中弹出任务,essay introducing the work-stealing schedulers 注释:

The processor will attempt to pop from the global after executing ~60 tasks from the local queue.