Skip to content

[data] Keep the autoscaling coordinator's view of the cluster up-to-date - #67479

Closed
pseudo-rnd-thoughts wants to merge 11 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/coordinator-cluster-view
Closed

pseudo-rnd-thoughts wants to merge 11 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/coordinator-cluster-view

Conversation

@pseudo-rnd-thoughts

@pseudo-rnd-thoughts pseudo-rnd-thoughts commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

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

  • Draining nodes: _update_cluster_node_resources kept every node ray.nodes() reports as Alive. A draining node (preemption notice, idle-termination drain) still reports Alive, but the raylet rejects new work on it (ClusterResourceScheduler::NodeAvailable). Ray Data budgeted for it, and Train's elastic policy sized runs from it.
  • Node order: _sort_key compared object_store_memory and memory before 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.
  • Reservations: _refresh_resource_reservations recomputed 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

  • Draining nodes are dropped on every view refresh, using an injectable GCS query. If the query fails, the refresh carries on without draining info and warns once rather than every tick.
  • Node order is (-GPU, -CPU, first seen, NodeID). Largest-first packing is kept, and a new node of an existing type sorts last.
  • Reservations stay put. Each requester's explicit placement is kept on 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_reservations stays 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 changed
Loading

What Ray Data users may notice:

  • Draining nodes no longer count toward budgets while they drain.
  • A new requester prefers nodes nobody holds over packing onto other requesters' nodes. Where capacity is fragmented, that can fit a bundle more or fewer.
  • With two or more request_remaining requesters, 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:

  1. [train] Yield the controller while waiting for a scaling decision, and fix the elastic node-killing release test #67478: controller yield + release harness
  2. [data] Keep the autoscaling coordinator's view of the cluster up-to-date #67479 (this PR): coordinator's view of the cluster
  3. [data] Run the autoscaling coordinator actor on the head node #67480: coordinator actor on the head node
  4. [train] Add end-to-end tests for elastic runs, Ctrl-C while waiting, and losing the coordinator's node #67481: end-to-end tests covering 1–3, stacked on [train] Add end-to-end scheduling tests for Train V2 worker placement #67421

Testing

All local on macOS, on this branch (master + these three commits):

pytest python/ray/data/tests/test_autoscaling_coordinator.py   # 66 passed

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

Mark Towers and others added 3 commits October 27, 2026 15:36
`_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]>
Mark Towers added 2 commits October 29, 2026 16:12
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts
pseudo-rnd-thoughts marked this pull request as ready for review October 29, 2026 17:49
@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested a review from a team as a code owner October 29, 2026 17:49
@pseudo-rnd-thoughts pseudo-rnd-thoughts changed the title [data] Keep the autoscaling coordinator's view of the cluster usable and stable [data] Keep the autoscaling coordinator's view of the cluster up-to-date Oct 29, 2026
Signed-off-by: Mark Towers <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 iamjustinhsu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some questions and initial round of feedback

)


def _default_get_draining_node_ids() -> Set[NodeIdStr]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a method called in get_draining_nodes in cached_ray_internals. Can we reuse that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to explain this case a bit further (b, d) = held, (c, e) = nobody held, a = (others held)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May include nodes no longer in node_ids

is this during a downscale?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and a few other cases listed in the updated docstring

logger.debug(msg)


def _sticky_node_order(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Mark Towers added 5 commits November 2, 2026 14:00
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants