Skip to content

ateapi: prefer less-loaded workers via power of two choices - #1915

Merged
Tim Hockin (thockin) merged 2 commits into
agent-substrate:mainfrom
chw120:scheduler-least-loaded
Oct 3, 2026
Merged

Tim Hockin (thockin) merged 2 commits into
agent-substrate:mainfrom
chw120:scheduler-least-loaded

Conversation

@chw120

@chw120 Chenyi Wang (chw120) commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

With multi-actor worker support (#1836) enabled by default (--max-actors=1000), selecting a single worker uniformly at random across all candidates with remaining capacity can stack actors onto busy workers while lighter workers exist, whereas strict global least-loaded selection over the asynchronous watch cache can cause concurrent bursts to herd onto the same worker.

This change updates Scheduler.Schedule to use power of two choices: sample two distinct eligible candidates that satisfy HasRoom and pick the less-loaded one, comparing actor-slot utilization (Allocated.Actors / Capacity.Actors) first and breaking ties on dominant compute-resource utilization (CPU/memory).

Testing

  • Added unit tests covering power-of-two-choices ordering, heterogeneous worker actor-capacity utilization, compute-resource utilization tie-breaking, fallback when an idle worker lacks resource room, and tie-breaking reachability in cmd/ateapi/internal/scheduling/scheduling_test.go.

  • Tests pass

  • Appropriate changes to documentation are included in the PR

@aditya-shantanu

Copy link
Copy Markdown
Collaborator

Convention nit (AGENTS.md, "Commit Messages"): the commit message references (#1836), but the repo rule is "No issue or PR references: Leave out #1234, Fixes #1234, and GitHub URLs. ... Put that context in the pull request description instead." Please reword the reference (e.g. "with multi-actor worker support enabled by default") before merge.

@chw120 Chenyi Wang (chw120) changed the title ateapi: prefer least-loaded workers during scheduling ateapi: prefer less-loaded workers via power of two choices Sep 26, 2026
@chw120

Copy link
Copy Markdown
Collaborator Author

Convention nit (AGENTS.md, "Commit Messages"): the commit message references (#1836), but the repo rule is "No issue or PR references: Leave out #1234, Fixes #1234, and GitHub URLs. ... Put that context in the pull request description instead." Please reword the reference (e.g. "with multi-actor worker support enabled by default") before merge.

Thanks Aditya Shantanu (@aditya-shantanu) for the fast review. Resolved all comments.

With multi-actor worker support enabled by default, selecting a single
worker uniformly at random across all candidates with remaining capacity
can stack actors onto busy workers while lighter workers exist, whereas
strict global least-loaded selection over the asynchronous watch cache
causes concurrent bursts to herd onto the same worker.

Update Schedule to sample two distinct eligible candidates with room and
pick the less-loaded one, comparing actor-slot utilization first and
breaking ties on dominant compute-resource utilization and remaining
actor slots.
Address review feedback on agent-substrate#1915:
- Compare max(actor-slot utilization, compute utilization) so a worker
  near its memory/CPU limit no longer wins just by hosting one fewer
  actor. Slot utilization and remaining slots remain as tie-breaks.
- Return the wrapped parse error for malformed limits instead of
  ErrNoCapacity, so a bad template is not reported as no free workers.
- Test the j >= i shift in pair sampling and the malformed-limits path.
@thockin
Tim Hockin (thockin) added this pull request to the merge queue Oct 2, 2026
Merged via the queue into agent-substrate:main with commit a25a4fb Oct 3, 2026
10 checks passed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api-machinery area/scheduling kind/feature An enhancement / feature request or implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants