Batch acquire: take up to N tasks per call across non-empty queues

未关闭
#49 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python, redis

调研方向

先阅读 threadmill/backends/redis.py 和 acquire.lua,然后跟踪 WorkerProcess 和 WorkerThread,以了解当前按线程执行的 acquire 流程。定义 fetch-and-dispatch 如何处理 lease 计时、优雅关闭和预取任务,同时将 pop 和 move 保持在一次 script 调用中。完成标准是:可以从非空队列中获取最多 N 个任务,且不会有工作被搁置或过早失败。

由索引模型根据 Issue 内容生成。

描述

Split out of #48 during the fair multi-queue scheduling change (codingjoe-fair-multi-queue-scheduling).

defer: Batch acquire (fetch up to N tasks per call across non-empty queues). Needs executor fetch-and-dispatch; the lease would tick while tasks wait in-process. [threadmill/backends/redis.py]

Why

acquire() pops a single task per script call, so a process with --threads 4 performs four Redis round trips to fill its threads. A batch acquire that spreads up to N tasks across the non-empty queues would cut round trips and drain several queues in parallel.

What makes it non-trivial

  • WorkerProcess runs one WorkerThread per thread, each calling acquire() itself. A batch would need a fetch-and-dispatch step, since a single thread cannot execute N tasks at once.
  • acquire.lua moves the task into the running set with deadline = now + lease_ttl. Tasks prefetched into an in-process queue would burn lease budget while waiting, so the reaper could fail them, or the lease clock has to start at execution instead.
  • Graceful shutdown must return prefetched, unstarted tasks to the ready set instead of leaving them to be reaped as FAILED.

Pop and move must stay inside one script call.

主要语言
Python
星标
12
派生
1
平均合并
1 天 1 小时
30 天内合并 PR
10

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codingjoe/threadmill 的其他 Issue

查看 codingjoe/threadmill 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。