Skip to content

fix(cascade): 限制批次内并发执行的 handler 数量 - #492

Merged
gloryfromca merged 2 commits into
EverMind-AI:mainfrom
flyto168:feature/cascade-worker-concurrency-bound
Oct 15, 2026
Merged

gloryfromca merged 2 commits into
EverMind-AI:mainfrom
flyto168:feature/cascade-worker-concurrency-bound

Conversation

@flyto168

Copy link
Copy Markdown
Contributor

问题

cascade worker 在单个批次内对 50 行并发执行 handler。daily-log handler 先按 md_path 解析既有行,碎片化的 Lance 表上该查询是原生全量扫描:50 个并发 handler 曾把生产数据回放推到 8.29 GiB 且 80 秒内未完成;1/2/4/8 并发的峰值约 0.26/0.61/0.98/1.73 GiB。原生查询不受 Python 取消控制,超时后仍会成倍占用内存与文件句柄。

改法

  • 新增 handler_concurrency(默认 4):领取批次仍为 50 行保持队列语义,仅限制同时执行的 handler 数量。
  • 非法值(<=0)在构造时即抛错。

验证

  • cascade 套件 259 passed(含新增并发上限测试);Ruff 通过。
  • 基于上游 main @ a345d08,仅 2 文件。

范围

仅含通用修复与测试。

flyto168 and others added 2 commits October 15, 2026 17:07
The semaphore was built inside drain_once, so two concurrent drains each
got their own and the bound doubled. That overlap is the shipped path:
POST /cascade/quiesce calls drain_fully() before stop() while the
background loop is still draining, which CascadeOrchestrator.drain_fully
documents ("the background worker claims batches too"). A regression
test reproduces it -- peak 8 against a documented bound of 4.

Also pass handler_concurrency through from CascadeConfig. Nothing did,
so the default was hardcoded in production and the positive-value guard
was unreachable; every other worker knob already has a config field.

The existing assertion used <=, which a bound accidentally set to 1
would also satisfy; peak is deterministic here, so pin it with ==.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@gloryfromca
gloryfromca force-pushed the feature/cascade-worker-concurrency-bound branch from b4ec080 to 05fb42d Compare October 15, 2026 09:08
@gloryfromca
gloryfromca merged commit a3359d5 into EverMind-AI:main Oct 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants