Skip to content

performance: implement adaptive worker scaling based on runtime CPU pressure #5

@more-shubham

Description

@more-shubham

Worker count is currently a static flag defaulting to 3. On multi-core machines or varying I/O conditions the optimal count changes during a run. A runtime tuner makes the system self-optimizing.

Scope:

  • Create internal/tuner/tuner.go with a background goroutine sampling throughput every 10 seconds
  • Track images/sec over a sliding window
  • Scale workers up by 1 if throughput improved in last window and memory is below 60% threshold
  • Scale workers down by 1 if throughput degraded or memory exceeds 70% threshold
  • Respect min/max worker bounds (-min-workers, -max-workers flags)
  • Log every scaling decision with reason

Example log output:

[Tuner] Scaled workers 3 → 4 (throughput: 6.08 → 7.21 img/s, memory: 42%)
[Tuner] Scaled workers 4 → 3 (throughput: 7.21 → 6.89 img/s, cause: diminishing returns)

Acceptance Criteria:

  • Worker count adjusts automatically without restart
  • Scaling decisions are logged with throughput and memory context
  • Static -workers flag still works, disabling the tuner
  • Benchmark comparison between static and adaptive modes documented in BENCHMARKS.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions