Skip to content

perf(scheduler): skip NodeLocalGreedy nodes that cannot host a pending task - #2829

Open
sam-huang1223 wants to merge 1 commit into
kai-scheduler:mainfrom
sam-huang1223:perf/nodelocalgreedy-node-capacity
Open

sam-huang1223 wants to merge 1 commit into
kai-scheduler:mainfrom
sam-huang1223:perf/nodelocalgreedy-node-capacity

Conversation

@sam-huang1223

@sam-huang1223 sam-huang1223 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

NodeLocalGreedy simulated a scenario for every node of the latest victim, even when evicting that node's victims could not free room for any pending task. MultiNodeGang's sub-scenario emitter already drops such nodes: a node whose capacity after eviction is below the smallest pending task's GPU request cannot host any pending task. That capacity is the node's idle and releasing GPUs, plus the GPUs of the recorded and potential victims on it.

This applies the same rule in nodeLocalScenarios. NodeLocalCapacity computes the capacity nodeCapacities computes, from the same parts (recordedFreedByNode, nodeIdleOrReleasingGpus, pendingTaskGpuStats). It keeps a running per-node sum of the accumulated victims' GPUs, because accumulation only appends victims, so a check costs a map lookup and the generator doesn't rebuild batches at every step. canHostSmallestPendingTask is the predicate that sortViableCandidates and NodeLocalCapacity now share, so the two generators keep one rule. Pending tasks that request no GPUs still fit every node, as before.

A skipped scenario cannot free room for a pending task on its node. On main its simulation could still succeed only by placing the job on other room, which means the job fit without those evictions; allocate places such jobs before reclaim, preempt and consolidation run. Like the emitter, the check counts only a node's own share of a victim batch that spans nodes. Such a batch frees room on its other nodes too, but each of those nodes gets its own scenario when the batch is added, and its own share counts there.

Related Issues

Fixes #2826

Checklist

  • Self-reviewed
  • Added/updated tests (if needed)
  • Updated documentation (if needed)
  • Added a changelog fragment via make changelog (or applied the skip-changelog label). Do not edit CHANGELOG.md directly — pending fragments are folded into it at release time.

Breaking Changes

None.

Additional Notes

Test What it checks
TestNodeLocalGreedySkipsNodesThatCannotHostAPendingTask Another node's idle GPUs let the accumulated filter pass, and only the node whose victims free enough GPUs gets a scenario. Fails without the change: the other node's scenario is emitted too.
TestNodeLocalGreedyCountsTheNodesFreeGPUs Idle and releasing GPUs count toward a node's capacity; a GPU held by a running pod that is not a victim does not. The last case fails without the change.
TestNodeLocalGreedyCountsRecordedVictimsOnTheNode A recorded victim's GPUs count only on its own node. Fails without the change for a recorded victim on another node.
TestNodeLocalGreedyCountsOnlyTheNodesShareOfAVictimBatch A gang's pod on another node adds nothing to a node's capacity. Fails without the change, and also with a check that counts the whole batch.
TestNodeLocalGreedyKeepsEveryNodeForPendingTasksWithoutGPUs Guard: a pending job that requests no GPUs keeps every node's scenario.
TestNodeLocalCapacityMatchesTheEmitterRule At every step of an accumulation with a gang, a recorded victim, a pod that is no victim and an idle node, NodeLocalCapacity agrees with nodeCapacities and sortViableCandidates on every node that holds a victim, and both answers occur.
TestReclaimSkipsNodesThatCannotHostAPendingTask Reclaim end to end on a new NodeCapacity layout of the unschedulable distributed job benchmark: an elastic victim job with one GPU on each of 50 nodes, beside the reclaimer queue's own GPUs, plus a node with idle GPUs and no free CPU. 51 scenarios are simulated without the change and 1 with it, MultiNodeGang's empty sub-scenario. No eviction either way.
e2e reclaim_node_capacity_test.go On kind, with idle GPUs only on a tainted node and one evictable GPU on each other node, reclaim searches for a pod as large as the tainted node, simulates no NodeLocalGreedy scenario and evicts nothing. Fails without the change.

Mutants of CanHostPendingTask that ignore recorded victims, ignore idle and releasing GPUs, count a victim on every node, or always answer yes are each caught by at least two of these tests.

Benchmarks: same base commit, with and without the change, runs interleaved, benchstat:

Benchmark main this PR Δ
ReclaimUnschedulableDistributedJob_NodeCapacity100Node (new layout), sec/op 210 ms 144 ms −31% (p<0.001, n=10)
same, simulated scenarios/op 101 1 −99%
same, B/op and allocs/op −86% each
ReclaimUnschedulableDistributedJob_100Node, sec/op 2.00 s 2.02 s ~ (p=0.68, n=10)

No significant change in sec/op for the other ReclaimUnschedulableDistributedJob_* layouts, ReclaimLargeJobs_*, ReclaimManySingleGPUJobsFullCycle_*, or the reclaim, preempt, consolidation and full-cycle action benchmarks (n=6, re-checked with n=10 where p<0.05 at n=6). Allocations rise by at most 0.4%, except ConsolidationAction_SmallCluster (+2.1% allocs, time unchanged). That benchmark runs consolidation without allocate, so some pending jobs fit without any eviction, and main simulated, and accepted, scenarios that evict needlessly on nodes this check skips. Profiling attributes under 0.2% of its allocations to the check itself. With allocate first, as in a scheduling cycle, decisions are unchanged.

Ran: go build ./..., go test ./pkg/scheduler/... (all packages pass) and make validate (golangci-lint, 0 issues). The e2e spec passes on a local kind cluster set up with hack/setup-e2e-cluster.sh --local-images-build (two GPU workers), and fails there against a scheduler built from main.

#2811 and #2812 also change nodeLocalScenarios, so whichever merges second needs a small rebase. The changes compose: #2812 builds fewer scenarios, and this simulates fewer of them.

#2830 adds a similar e2e spec with its own helpers in the same package; whichever merges second can switch to the other's helpers.

🤖 Generated with Claude Code

…g task

NodeLocalGreedy simulated a scenario for every node of the latest victim,
even when evicting that node's victims could not free room for any pending
task. MultiNodeGang's sub-scenario emitter already drops such nodes: a node
whose capacity after eviction is below the smallest pending task's GPU
request cannot host any pending task.

Apply the same rule in nodeLocalScenarios. NodeLocalCapacity computes the
capacity nodeCapacities does, keeping a running per-node sum of the
accumulated victims' GPUs, and shares its predicate with
sortViableCandidates.

Fixes kai-scheduler#2826

Signed-off-by: Sam Huang <19882250+sam-huang1223@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

its a performance improvement, it doesn't need changelog imo

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NodeLocalGreedy simulates scenarios on nodes that cannot host any pending task

2 participants