Skip to content

perf(worker): reduce idle load of the sequence producer and cron scanners - #1637

Merged
viethung0o0 merged 1 commit into
mainfrom
perf/worker-idle-load
Nov 3, 2026
Merged

viethung0o0 merged 1 commit into
mainfrom
perf/worker-idle-load

Conversation

@viethung0o0

Copy link
Copy Markdown
Contributor

Summary

  • The sequence producer now polls every 5s instead of every 500ms, which cuts its idle Redis commands (ZRANGEBYSCORE) by about 10x. The interval is configurable with SCHEDULER_TICK_INTERVAL_MS (100–10000 ms).
  • Trade-off: a sequence step can be dispatched up to a few seconds later than before, and one bucket's peak throughput is lower. The numbers are documented next to the setting.
  • 12 of the 17 every-minute schedulers now fire at distinct seconds instead of all at :00. The 5 that depend on the minute boundary are unchanged.
  • The profile snapshot cursor compares (nextAttemptAt, id) as a row so paging stays on the index.
  • The abandoned-cart scan uses a narrower partial index (only carts with items). It ships as two CONCURRENTLY migrations, one to add the new index and one to drop the old one.
  • Memory is not changed by this PR. The high startup RAM in the issue is already addressed by the source-map pruning in the Docker image.

Verification

  • Local idle worker: CPU about 4.2% → about 1.0%, ZRANGEBYSCORE calls/s about 1050 → about 110.
  • Sequence enroll, dispatch and the flow trigger behavior were checked end to end on a local copy.
  • Worker, business and database unit tests and type checks pass.

Related to #1620

…ners

- Make the sequence producer poll interval configurable (default 5s)
- Spread 12 every-minute schedulers across the minute instead of firing at :00
- Compare the profile snapshot cursor as a row to keep paging on the index
- Narrow the abandoned-cart index to carts that still have items
@github-actions github-actions Bot added the improvement Refactor or performance improvement label Nov 3, 2026
@viethung0o0
viethung0o0 marked this pull request as ready for review November 3, 2026 09:17
@viethung0o0
viethung0o0 merged commit c04a18c into main Nov 3, 2026
15 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Refactor or performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants