Skip to content

Resume scans the worker fleet twice when no worker can restore a memory snapshot #3779

In review

Description

Problem

When an actor resumes from a MEMORY snapshot, runtime fallback is driven by assignWorkerAttempt in cmd/ateapi/internal/controlapi/workflow_resume.go, outside Scheduler.Schedule. Three costs follow from that.

  1. Two fleet scans on fallback. assignWorkerAttempt calls Schedule with RequiredRuntime set. On ErrNoCapacity it clears RequiredRuntime and calls Schedule again. Each call takes the workercache read lock, copies the full []*ateapi.Worker slice, and runs the static filters and label selectors over every worker.

  2. Two runtime scans per candidate. Inside Schedule, Applies calls RequiredRuntime.WorkerMatches, which walks the worker's DefaultRuntime and RestorableRuntimes. Booking then calls SnapshotRuntime.WorkerRuntimeFor, which walks the same list again to read ActorOverhead.

  3. Fallback state spread into controlapi. Because the retry mutates Constraints between passes, Constraints carries two hardware.Requirement fields (RequiredRuntime and SnapshotRuntime), and validateAssignedWorker needs its own appliesWithFallback to agree with what placement would do.

This gets worse with a third fidelity. #3230 asks resume to drop to VOLUMES rather than ROOTFS when the architecture differs. With caller-driven retries that is a third pass over workercache.

Proposal

Move fidelity preference into the scheduler so placement picks the best worker in a single pass:

  1. Pass the lowest acceptable fidelity once: Instead of calling Schedule for MEMORY, catching ErrNoCapacity, mutating Constraints, and calling Schedule again, the resume workflow tells Schedule upfront both the snapshot's runtime and the lowest fidelity it is willing to accept (MEMORY when pinned to a node, or ROOTFS — and later VOLUMES — when fallback is allowed).
  2. Keep only the highest-fidelity tier during a single scan: As Schedule walks the worker cache once, it evaluates each eligible worker's runtime once to get both the restore fidelity it can achieve and its memory overhead:
    • While only ROOTFS workers with room have been seen, Schedule collects ROOTFS candidates.
    • As soon as the first MEMORY worker with room is found, Schedule discards the ROOTFS candidates in place, raises its floor to MEMORY, and skips any remaining lower-fidelity workers for the rest of the loop.
  3. Sample from the winning tier: At the end of the pass, candidates holds every available worker at the highest fidelity reachable in the fleet (MEMORY if any had room, otherwise ROOTFS, and later VOLUMES), and Power-of-Two-Choices picks between them as before.

The set of workers an actor can land on and the choice among them do not change: today's second pass only runs when no MEMORY worker has room, which is the exact ROOTFS set the single pass keeps when no MEMORY worker qualifies.

Activity

  1. added
    kind/cleanup
    on Nov 12, 2026
  2. juli4n commented on Nov 17, 2026

    @juli4n
    Collaborator

    This is a good idea. The scheduler should be aware of constraints that can be relaxed (e.g. fidelity) so we don't need to do do multiple scans. I think there is also value in having the logic to decide how fidelity interplays with scheduling in one place.

    cc Zoe Zhao (@zoez7) as we discussed this last week.

  3. added
    ready-for-pr
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/lifecyclearea/schedulingkind/cleanupready-for-pr

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions