Repository navigation
[data] Keep the autoscaling coordinator's view of the cluster up-to-date - #67479
pseudo-rnd-thoughts wants to merge 11 commits into
Conversation
`_update_cluster_node_resources` kept every node that `ray.nodes()` reports as `Alive`. A draining node, for example one with a preemption notice or an autoscaler idle-termination drain, still reports `Alive`, but the raylet scheduler rejects new work on it (`ClusterResourceScheduler::NodeAvailable`). So the coordinator reserved capacity that nobody could use: Ray Data budgeted for it, and Train's elastic policy sized runs from it. Ask the GCS for draining nodes on every view refresh and drop them. The query is injectable, like the actor's other cluster dependencies. If it fails, the refresh carries on without draining info instead of failing the whole tick, and it warns on the first failure of a run rather than on every tick. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
The coordinator offers nodes to requesters largest first (ray-project#66001). `_sort_key` compared `object_store_memory` and `memory` before CPU and NodeID. Those two come from the free system memory when the raylet starts, so they differ slightly even between nodes of the same type. A node that joined with a little more memory sorted ahead of existing nodes of its type, so every requester's reservation shifted by one node on the next tick. Compare only GPU and CPU, which the node's type fixes. Among nodes of the same shape, order by the view update in which the coordinator first saw the node, then by NodeID. A new node now sorts after existing nodes of its type, while a larger node still sorts first. Rounding memory instead would still split two nodes of the same type that straddle a bucket edge. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
`_refresh_resource_reservations` recomputed every requester's reservation from scratch on every tick. When a node joined or left, requesters that weren't on it moved too, often onto nodes another requester had held, for example where that requester's workers were still running. Ray Train needs a requester's reservation to describe where its workers can go, so it can't use a view that moves under it like that. Make explicit reservations sticky. Keep each requester's explicit placement, without its leftover shares, on `OngoingRequest`, and on the next refresh pass `_compute_reservations` a per-requester node order: the nodes the requester held, in the order it held them, then nodes no other live requester held, then the rest. Requesters are still placed in priority order, so a higher-priority requester that arrives later still gets capacity, taking free nodes before nodes others hold. `_compute_reservations` stays pure, and each strategy keeps its meaning: STRICT_PACK uses one node, STRICT_SPREAD distinct nodes, and PACK and SPREAD scan the given order. SPREAD still round-robins over every node, so it can spread onto a node that just joined. Leftover shares are still split per node on every refresh, as before. Because a requester now prefers nodes nobody else holds, its explicit bundles can land on different nodes than before. Where capacity is fragmented, the new order can fit a bundle more or fewer. And since the leftover is split per node with integer division, a requester's total can shift by less than one unit per node and resource type. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request enhances the Ray Data autoscaling coordinator by excluding draining nodes from eligible cluster resources and introducing a sticky node ordering mechanism to prevent existing resource reservations from shifting when nodes join or leave. The review feedback highlights a critical type mismatch in the default draining nodes query where raw GCS node IDs must be converted to hex strings to match the format used by other parts of the system, along with a corresponding test assertion update. Additionally, the feedback recommends deduplicating node IDs in the sticky node ordering logic to correctly handle cases where a requester holds multiple bundles on the same node.
iamjustinhsu
left a comment
There was a problem hiding this comment.
some questions and initial round of feedback
| ) | ||
|
|
||
|
|
||
| def _default_get_draining_node_ids() -> Set[NodeIdStr]: |
There was a problem hiding this comment.
We already have a method called in get_draining_nodes in cached_ray_internals. Can we reuse that?
There was a problem hiding this comment.
I didn't know that existed, yes used
|
|
||
| actor = Actor.remote() | ||
| ray.get(actor.ping.remote(), timeout=60) | ||
| is_accepted, _ = ray._private.worker.global_worker.gcs_client.drain_node( |
There was a problem hiding this comment.
if u go with the get_draining_nodes() recommendation, we make a seam into the autoscaling coordinator actor, which will make it easier to test and we wouldn't have to rely on the drain_node API (so it's a unit test)
There was a problem hiding this comment.
Perfect, that makes testing easier
| # "gone" has left the cluster since. | ||
| held=["d", "gone", "b"], | ||
| held_by_others={"a", "b"}, | ||
| ) == ["d", "b", "c", "e", "a"] |
There was a problem hiding this comment.
probably want to explain this case a bit further (b, d) = held, (c, e) = nobody held, a = (others held)
There was a problem hiding this comment.
Done, I've added comments for each case
| node_ids: The nodes in the requester's subcluster, in the cluster's | ||
| order. | ||
| held: The nodes of this requester's bundles last refresh, in | ||
| placement order. May include nodes no longer in ``node_ids``. |
There was a problem hiding this comment.
May include nodes no longer in
node_ids
is this during a downscale?
There was a problem hiding this comment.
Yes, and a few other cases listed in the updated docstring
| logger.debug(msg) | ||
|
|
||
|
|
||
| def _sticky_node_order( |
There was a problem hiding this comment.
Order the nodes one requester tries, so its reservation doesn't move.
Can you give an example if how this fixes the problem? Like I know we sorted node_ids before, but not sure how a node joining, or leaving, or a new requester coming actually reorders their reservation, because we keep a mapping of which requester has their nodes, so I thought the reservation doesn't actually move
There was a problem hiding this comment.
As I understand it, we don't keep the mapping of which requester has their nodes necessarily and on each recompute, then we reallocate for each requesters. Therefore, this new function tries to allocate requests to the same nodes as you were expecting.
The function achieves this through two chanegs: the sort key no longer depends on memory, so a new node of an existing type isn't sorted first changing all the allocation and bundle_node_ids now records where each requester was last time, so the next refresh tries those nodes first.
Signed-off-by: Mark Towers <[email protected]>
# Conflicts: # python/ray/data/_internal/cluster_autoscaler/default_autoscaling_coordinator.py
Signed-off-by: Mark Towers <[email protected]>
# Conflicts: # python/ray/data/_internal/utils/cached_ray_internals.py
Signed-off-by: Mark Towers <[email protected]>
Summary
Fixes three ways the AutoscalingCoordinator's view of the cluster is wrong: it counts draining nodes, its node order reshuffles when a node joins, and every refresh moves every requester's reservation. Ray Train sizes and places runs from this view, so each one shows up as a run that retries forever or lands on the wrong nodes.
Before
_update_cluster_node_resourceskept every noderay.nodes()reports asAlive. A draining node (preemption notice, idle-termination drain) still reportsAlive, but the raylet rejects new work on it (ClusterResourceScheduler::NodeAvailable). Ray Data budgeted for it, and Train's elastic policy sized runs from it._sort_keycomparedobject_store_memoryandmemorybefore CPU. Those come from free memory at raylet start, so they differ between nodes of the same type, and a newly joined node could sort ahead of existing ones, shifting every requester by one node on the next tick._refresh_resource_reservationsrecomputed every reservation from scratch each tick. When a node joined or left, requesters that weren't on it moved too, often onto nodes another requester's workers were still using.After
(-GPU, -CPU, first seen, NodeID). Largest-first packing is kept, and a new node of an existing type sorts last.OngoingRequest, and the next refresh tries nodes in this order: the requester's own previous nodes, then nodes no other live requester holds, then the rest. Requesters are still placed in priority order, and STRICT_PACK / STRICT_SPREAD / PACK / SPREAD keep their meaning._compute_reservationsstays pure.flowchart TD subgraph Before subgraph BS[Subsystem: resource allocation] subgraph BC[Component: AutoscalingCoordinator view refresh] B1["ray.nodes() Alive, incl. draining"] --> B2[sort by GPU, CPU, memory] --> B3[recompute every reservation] end end end subgraph After subgraph AS[Subsystem: resource allocation] subgraph AC[Component: AutoscalingCoordinator view refresh] A1["ray.nodes() Alive minus draining"] --> A2[sort by GPU, CPU, first seen] --> A3["per-requester order: own nodes, free nodes, rest"] end end end classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 class A1,A2,A3 changedWhat Ray Data users may notice:
request_remainingrequesters, per-node integer division can shift a requester's leftover total by less than one unit per node and resource type.Known gap: a SPREAD requester still round-robins over every node, so it can spread onto a node that just joined.
Subsystems
Resource allocation (
_internal/cluster_autoscaler/default_autoscaling_coordinator.py).Series
This splits #67422 into reviewable pieces:
Testing
All local on macOS, on this branch (master + these three commits):
12 new unit tests in
test_autoscaling_coordinator.py, each failing on the code before its commit. The end-to-end cases (test_starts_when_a_node_is_unusable[draining],test_elastic_run_starts_when_a_node_is_unusable[draining],test_concurrent_runs_survive_node_churn) are in #67421 and #67481.Not a duplicate. I searched open PRs touching
default_autoscaling_coordinator.py. #61487 optimizes the allocation loop's complexity and doesn't change which nodes are seen or in what order; the two will need a small rebase against each other. #66762/#66763 change Train's scaling policies, not the coordinator.AI assistance (Claude Code) was used to write these changes and tests, run the suites, and write this description.
🤖 Generated with Claude Code