Repository navigation
ateapi: select highest-fidelity worker in a single Schedule pass - #3777
Shrutiya Mohan (shrutiyam-glitch) wants to merge 5 commits into
Conversation
101fdfc to
d938f67
Compare
25f35d3 to
0496d02
Compare
|
Benchmark results from #4000 ( go test -run='^$' -bench='BenchmarkSchedule/.+/n=10000$' -benchmem -count=3 ./cmd/ateapi/internal/scheduling
What this shows:
|
| if constraints.RequiredRuntime.Runtime() == nil { | ||
| // canRelaxRuntime reports whether scheduling may accept a worker that | ||
| // restores snap without its memory state. | ||
| func canRelaxRuntime(actor *ateapi.Actor, snap *ateapi.Snapshot, required *ateapi.ActorSandboxRuntime) bool { |
There was a problem hiding this comment.
I think the "canRelaxRuntime" function might be doing multiple jobs, for example why is "snapshot locality", localElsewhere, uploadCompleted etc. taken into account here?
There was a problem hiding this comment.
These were the filters that were already there.
They indicate if the fidelity can be downgraded from MEMORY to ROOTFS.
For example,
localElsewhere (#3094): allows a snapshot whose node was deleted while its upload was still PENDING to fall back to ROOTFS from object storage.
"snapshot locality check" - probably a carryover from before local and durable restore were unified (#2967); today it is only reached on RESUMING re-entry in validateAssignedWorker while the actor is still on the snapshot's local node. 64e9448
I need to look into this more. will probably decouple if needed in a separate pr ?
0496d02 to
d9c6170
Compare
Add Requirement.BestRuntime(status, floor) to return both the winning WorkerSandboxRuntime and the SnapshotFidelity it achieves in one call (DefaultRuntime or RestorableRuntimes at MEMORY, or DefaultRuntime at ROOTFS when floor allows fallback), so the scheduler does not need to scan a worker's runtimes twice for eligibility and overhead booking. Signed-off-by: Shrutiya <[email protected]>
… pass Replace Constraints.RequiredRuntime with Constraints.MinFidelity (defaulting to SNAPSHOT_FIDELITY_MEMORY) and have Schedule evaluate the worker cache in a single pass. For each worker that passes matchesStatic, Schedule calls SnapshotRuntime.BestRuntime(status, floor) once, computes booking from the returned runtime's ActorOverhead, and resets candidates[:0] in place whenever a candidate with room exceeds bestFidelity. Signed-off-by: Shrutiya <[email protected]>
Set Constraints.MinFidelity in schedulingConstraints when canRelaxRuntime allows fallback, so assignWorkerAttempt calls Scheduler.Schedule once without mutating Constraints and validateAssignedWorker checks Scheduler.Applies directly. Remove appliesWithFallback. Signed-off-by: Shrutiya <[email protected]>
admit previously re-checked the row-locked worker against constraints.MinFidelity, so a worker picked at MEMORY that dropped the snapshot's runtime before bind could be accepted at ROOTFS when relaxable. Hold admit to at least the fidelity tier Schedule picked, returning errWorkerFilledUp so the retry can pick another worker. Signed-off-by: Shrutiya <[email protected]>
Have Schedule return the picked worker, its fidelity tier, and its resource booking in a Placement struct. assignWorkerAttempt previously recomputed both on the cached worker to populate assignment.Resources and to hold admit to the picked tier. Unexport Constraints.effectiveMinFidelity now that controlapi no longer calls it, and check the recorded assignment booking in TestAssignWorkerAttempt_RefusesChangedOverhead. Signed-off-by: Shrutiya <[email protected]>
fc83289 to
f02cba7
Compare
| if fidelity > bestFidelity { | ||
| bestFidelity = fidelity | ||
| floor = fidelity | ||
| candidates = candidates[:0] |
There was a problem hiding this comment.
nit: raising floor here is what makes later lower-tier workers drop out in BestRuntime. Worth a one-line comment.
| } | ||
|
|
||
| var candidates []candidate | ||
| floor := constraints.effectiveMinFidelity() |
There was a problem hiding this comment.
shouldn't the floor be VOLUMES for all actors? we haven't introduced the minimumFidelity concept in the API yet, why does effectiveMinFidelity default to memory?
| Limits: tmpl.GetResources().GetLimits(), | ||
| } | ||
| if canRelaxRuntime(actor, snap, required) { | ||
| c.MinFidelity = ateapi.SnapshotFidelity_SNAPSHOT_FIDELITY_ROOTFS |
There was a problem hiding this comment.
I think the floor should be VOLUMES, since we haven't introduced the [minimumFidelity concept in the API]
(https://docs.google.com/document/d/1CeN65qu64tGYvARYUUrwmESR4S0tbVXmRKubpsAQIdY/edit?tab=t.17rkgpfv7ql7#bookmark=id.xhai30s6k8w2) yet.
| // effectiveMinFidelity returns MinFidelity, or SNAPSHOT_FIDELITY_MEMORY when | ||
| // MinFidelity is unset. | ||
| func (c Constraints) effectiveMinFidelity() ateapi.SnapshotFidelity { | ||
| if c.MinFidelity == ateapi.SnapshotFidelity_SNAPSHOT_FIDELITY_UNSPECIFIED { |
There was a problem hiding this comment.
When is the MinFidelity unset? Can we make sure each callsite always sets the minFidelity?
| // MinFidelity is unset. | ||
| func (c Constraints) effectiveMinFidelity() ateapi.SnapshotFidelity { | ||
| if c.MinFidelity == ateapi.SnapshotFidelity_SNAPSHOT_FIDELITY_UNSPECIFIED { | ||
| return ateapi.SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY |
There was a problem hiding this comment.
this should default to VOLUMES, right?
| candidates = append(candidates, cand) | ||
| if fidelity > bestFidelity { | ||
| bestFidelity = fidelity | ||
| floor = fidelity |
There was a problem hiding this comment.
Why do we need to update floor here? Shouldn't floor always be the minimumFidelity that an actor can survive (i.e. volumes)?
| // runtime reaches floor. A zero Requirement imposes no runtime constraint: it | ||
| // returns DefaultRuntime at SNAPSHOT_FIDELITY_MEMORY, which meets any floor, | ||
| // or nil and SNAPSHOT_FIDELITY_UNSPECIFIED before the worker has registered. | ||
| func (r Requirement) BestRuntime(status *ateapi.WorkerStatus, floor ateapi.SnapshotFidelity) (*ateapi.WorkerSandboxRuntime, ateapi.SnapshotFidelity) { |
There was a problem hiding this comment.
🤖 should-fix 🟡 – floor only changes the result in one case: at MEMORY it turns (def, ROOTFS) into (nil, UNSPECIFIED). The scheduling callers (Schedule, doesNotFit, Applies) all check fidelity < floor (or >=) again, so the filter runs twice and "below floor" is signaled in-band through UNSPECIFIED.
The zero values also disagree. BestRuntime(status, UNSPECIFIED) accepts ROOTFS, while Constraints{MinFidelity: UNSPECIFIED} means MEMORY. The doc says a zero Requirement "meets any floor", which does not hold for a floor above MEMORY.
Could BestRuntime(status) return the runtime and the fidelity it reaches, and leave the floor comparison to callers? matchingRuntime and WorkerRuntimeFor become explicit about what they require instead of passing different constants, and Schedule can skip lower tiers directly with fidelity < floor.
| // placementOf is the Placement the real Schedule returns when it picks worker | ||
| // under c. | ||
| func placementOf(worker *ateapi.Worker, c scheduling.Constraints) scheduling.Placement { | ||
| _, fidelity := c.SnapshotRuntime.BestRuntime(worker.GetStatus(), ateapi.SnapshotFidelity_SNAPSHOT_FIDELITY_ROOTFS) |
There was a problem hiding this comment.
ateapi.SnapshotFidelity_SNAPSHOT_FIDELITY_ROOTFS
This should test other possible values of c.minFidelity as well.
Fixes #3779
Resuming an actor from a memory snapshot could scan the worker fleet twice. The scheduler first looked only for workers able to restore the snapshot's memory state. If none had room, it dropped that requirement and scanned again, accepting any worker of the same sandbox class for a cold boot from the snapshot's files. Each scan locks the worker cache and copies the fleet, and the retry had to be mirrored wherever an existing assignment is re-checked.
The scheduler now does this in one pass. It rates each worker by how much of the snapshot it can restore and keeps only the best-rated workers that have room. A worker that can restore memory state always wins over one that can only cold boot, and the existing random choice applies within that group. Callers state up front whether a cold boot is acceptable.
The set of workers an actor can land on and the choice among them are unchanged. Only the number of scans changes.
AI use: AI-assisted, I reviewed and tested the changes.