Skip to content

ateapi: index workercache by node to speed up pinned actor resumes #3781

Description

Problem

Resuming a paused actor (an asynchronous suspend whose local checkpoint is still on its node) is the most latency-sensitive resume path in Substrate. Because the actor's status.assigned_node is set, schedulingConstraints sets Constraints.RequiredNodes to that single node so the actor resumes from its local checkpoint.

Today, workercache.Cache (cmd/ateapi/internal/workercache/workercache.go) only stores a flat map[string]*ateapi.Worker keyed by worker name:

  1. Full-cluster copy on every pinned resume: Even when Constraints.RequiredNodes names a single node, Scheduler.Schedule calls s.source.Workers(), which takes the cache read lock, iterates every worker in the cluster, and allocates a full []*ateapi.Worker slice.
  2. $O(\text{cluster})$ filtering for a single node: Schedule then loops over all $N$ workers in the cluster only for matchesStatic to discard every worker whose NodeName is not in RequiredNodes. On a 1,000-node cluster with 4 workers per node, a paused resume copies and checks 4,000 workers to inspect the 4 workers on assigned_node.
  3. Double scan when the pinned node is full: If the pinned node has no room, assignWorkerAttempt scans all $N$ workers for the pinned node, fails with ErrNoCapacity, and then detachFromFullNode scans all $N$ workers again across the cluster.

Proposal

Index workers by NodeName inside workercache.Cache so node-pinned scheduling only reads the workers on the requested node(s):

  1. Maintain a per-node index in workercache: A worker's NodeName is fixed for its lifetime, and Cache only mutates c.workers in three places (relist, applyEvent, and Forget). Keep a byNode map alongside c.workers in those three paths.
  2. Query only the target node(s) when RequiredNodes is set: When Constraints.RequiredNodes is non-empty, Schedule fetches only the workers on those nodes from workercache instead of calling Workers(). When RequiredNodes is empty (unpinned resume or cold boot), Schedule reads the full fleet as before.

This reduces worker lookup and evaluation on every paused-actor resume from $O(\text{cluster})$ to $O(\text{workers on node})$ (typically 1 to 5 workers).

Metadata

Metadata

Labels

area/lifecyclearea/schedulingkind/cleanup

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions