Files
substrate/cmd
Chenyi Wang a25a4fbcfe ateapi: prefer less-loaded workers via power of two choices (#1915)
### 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`.


- [x] Tests pass
- [ ] Appropriate changes to documentation are included in the PR
2026-10-02 23:56:47 +00:00
..