codingjoe / codingjoe/threadmill

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

未关闭
#49 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
12
派生
1
平均合并
1 天 1 小时
30 天内合并 PR
10

描述

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.

贡献指南

打开贡献指南

调研方向

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

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

评估

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

把新 issue 发到你的邮箱

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