Skip to content

[data][actor-only][7/n] Operator sizer + sizer metrics - #67703

Open
iamjustinhsu wants to merge 4 commits into
iamjustinhsu/ao/06-scheduling-loopfrom
iamjustinhsu/ao/07-operator-sizer
Open

iamjustinhsu wants to merge 4 commits into
iamjustinhsu/ao/06-scheduling-loopfrom
iamjustinhsu/ao/07-operator-sizer

Conversation

@iamjustinhsu

Copy link
Copy Markdown
Contributor

Summary

Add the operator sizer. Every tick it decides how many actors each operator should run, and where to add or remove them. It replaces the placeholder from the previous PR, and adds sizing and placement dashboards.

Part 7 of 12 of the Ray Data actor-only backend stack. Stacked on #67702; review only the top commit. Everything here is gated behind RAY_DATA_ACTOR_ONLY_BACKEND (off by default) unless noted under After.

Before

The actor-only scheduling loop has no sizing: pools stay at their initial size.

After

  • Each tick, the sizer runs three phases:
    • scale_how_many() makes greedy sizing decisions per operator.
    • optimize() applies two whole-topology rules:
      • Capacity transfer: when the cluster is full, it moves idle capacity from an upstream operator to its bottlenecked consumer.
      • Silent bottleneck: it scales up an output-backpressured operator whose downstream keeps up.
    • scale_where() picks nodes for new actors and the actors to shed.
  • The sizer also validates actor-only ray_remote_args: only label selectors, placement groups, and CPU/GPU/memory are allowed.
flowchart TD
    subgraph Before
        subgraph BS[Subsystem: resource allocation]
            subgraph BC[Component: scheduling loop]
                B1["size (placeholder)"]
            end
        end
    end
    subgraph After
        subgraph AS[Subsystem: resource allocation]
            subgraph AC[Component: operator sizer]
                A1["scale_how_many (per-op)"] --> A2["optimize (capacity transfer, silent bottleneck)"] --> A3["scale_where (placement)"]
            end
        end
    end
    class A1,A2,A3 added
    class B1 removed
    classDef removed fill:#ffcdd2,stroke:#c62828,color:#000
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
Loading

Subsystems

resource allocation / autoscaling (flag-gated), observability (sizer metrics and dashboards)

Testing

  • RAY_DATA_ACTOR_ONLY_BACKEND=1 pytest python/ray/data/tests/actor_only: 348 passed. This PR touches no tests outside tests/actor_only.
  • pre-commit run on changed files: clean.

Notes

  • Not a duplicate: no open ray-project/ray PR covers the actor-only backend (checked with gh pr list --repo ray-project/ray --state open --search "actor-only").
  • AI assistance (Claude Code) was used for this change. I have reviewed every changed line.

🤖 Generated with Claude Code

@iamjustinhsu
iamjustinhsu added this pull request to stack #67709 November 2, 2026 21:02
@iamjustinhsu
iamjustinhsu removed this pull request from stack #67709 November 2, 2026 21:05
@iamjustinhsu
iamjustinhsu added this pull request to stack #67710 November 2, 2026 21:05
@iamjustinhsu
iamjustinhsu marked this pull request as ready for review November 2, 2026 21:15
@iamjustinhsu
iamjustinhsu requested review from a team as code owners November 2, 2026 21:15
@iamjustinhsu iamjustinhsu added the go add ONLY when ready to merge, run all tests label Nov 2, 2026

@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 introduces a robust, multi-phase actor-pool sizing and placement system (OperatorSizer) for Ray Data's actor-only backend. It implements cross-operator optimization rules (such as capacity transfers and silent bottleneck grants), locality-first actor placement, constraint-aware capacity tracking, and comprehensive telemetry. The changes are integrated into the streaming executor and backed by extensive unit and end-to-end tests. One code improvement was suggested to directly access op.op_tag() instead of retrieving it via the topology state mapping, which is safer and more direct.

):
for op, r in placed.items():
self._metrics.record_actor_delta(
operator=topology[op].op_tag(), phase=phase, delta=r.delta

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.

medium

Using topology[op].op_tag() is less direct and potentially unsafe if OpState (the value type of topology) does not expose op_tag(). Since op itself is the ExperimentalActorPoolMapOperator instance (which inherits from PhysicalOperator and has op_tag()), you can directly call op.op_tag() instead.

Suggested change
operator=topology[op].op_tag(), phase=phase, delta=r.delta
operator=op.op_tag(), phase=phase, delta=r.delta

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Nov 3, 2026
@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch from 6dd155f to bdc65af Compare November 3, 2026 20:09

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch from bdc65af to 79a04bc Compare November 3, 2026 23:10
@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch 2 times, most recently from 2b3e6de to e50e09f Compare November 6, 2026 00:57

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch from e50e09f to 9a30fe9 Compare November 6, 2026 04:17
@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch from 9a30fe9 to b1cf8b1 Compare November 6, 2026 20:34
@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch from b1cf8b1 to 43ec0e7 Compare November 10, 2026 19:01

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch from 43ec0e7 to a89460c Compare November 10, 2026 21:09

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

force=True,
reason=f"optimizer: donate to {recipient.name}",
victim_node=node_plan.node,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Transfer evicts the wrong victims

High Severity

Capacity transfer plans exact victims, including pending actors and only those that free a resource the recipient still lacks, then fires a victim_node downscale that discards those ids. Apply-time picking looks only at running actors on the node and takes the cheapest drain, so pending claims stay, CPU actors can be shed for a GPU recipient, and the new actors may never fit.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a89460c. Configure here.

@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch from a89460c to fc2e552 Compare November 12, 2026 17:04

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

for op, count in node_plan.victims_by_donor().items():
donor = donors_by_op[op]
donor.removable = max(0, donor.removable - count)
_consume_victims_from_view(donor.view, node_plan.node, count)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Donor view consumed by count

Medium Severity

After a transfer fires, _consume_victims_from_view drops the first N pending then running actors on the node rather than the actor ids the plan actually took. Candidates skipped by _frees_short_dim still occupy those prefix slots, so a later recipient in the same tick can reuse already-claimed victims or see the wrong remaining surplus.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fc2e552. Configure here.

@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch 2 times, most recently from 107f55d to 5cf9408 Compare November 13, 2026 22:36

@ayushk7102 ayushk7102 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.

Just tracking some divergences from our benchmark branch, which I want to make sure we double-check

pool = op.actor_pool
return max(1, math.ceil(self.upscale_factor * pool.serving_size()))

def growth_delta(self, op: "ExperimentalActorPoolMapOperator") -> int:

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.

This drops the backlog cap from the earlier revision, so the silent-bottleneck step is now limited only by max size. The reasoning in the docstring makes sense to me (upstream backpressure keeps the bottleneck's queue shallow). Can we confirm this is intended and not just a response to Bugbot? The two growth paths now diverge, and the old docstring said they matched on purpose.

continue
# A silent bottleneck's output-blocked actors look like surplus,
# but it is what limits the pipeline: grow it, never drain it.
if SilentBottleneckGrant.is_silent_bottleneck(op, ctx):

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.

Excluding silent bottlenecks as donors looks right to me. Since this came in through the Bugbot thread with no discussion, could someone who owns the optimizer confirm the behavior?

pool = op.actor_pool
return max(1, math.ceil(self.upscale_factor * pool.serving_size()))

def growth_delta(self, op: "ExperimentalActorPoolMapOperator") -> int:

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.

Divergence 1: growth_delta is capped at pool_cap, not backlog_actor_target (the op_state param is gone).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Intended, so basically this affects silient bottleneck. A silent bottleneck is an operator that is bottlenecked (needs more actors), however, it does not because of how the code is written (it's considered as a special case, not a normal case in the control flow). Silent bottlneck operators have shallow queues, typically run very long per task, and has backpressured actors. In this case, if we use backlog_actor_target, the "backlog" refers to the ongoing tasks + queue, and that value for backlog_actor_target will typically be less than serving size.

That's just theory, but i'll run benchmarks later to confirm this

capacity=ctx.capacity,
profiles=self._profiles,
growth_delta={
op: self._policy.growth_delta(op)

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.

Divergence 2: call site is growth_delta(op), not growth_delta(op, self._topology[op]).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

related to divergence 1

return requests

@classmethod
def is_silent_bottleneck(

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.

Divergence 3: _is_silent_bottleneck became the public @classmethod is_silent_bottleneck; the growth_delta > 0 check is no longer inside it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

related to divergence 1

for op in ctx.actor_pool_ops:
if not self._guard.can_scale(op) or op.actor_pool.num_pending_actors() > 0:
continue
if ctx.growth_delta.get(op, 0) <= 0 or not self.is_silent_bottleneck(

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.

Divergence 3 (cont.): the growth_delta > 0 check moved here into apply().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

related to divergence 1

continue
# A silent bottleneck's output-blocked actors look like surplus,
# but it is what limits the pipeline: grow it, never drain it.
if SilentBottleneckGrant.is_silent_bottleneck(op, ctx):

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.

Divergence 4: _collect_donors skips silent bottlenecks.

OptimizationRule,
)
from ray.data._internal.experimental.execution.sizer.optimizer.silent_bottleneck import ( # noqa: E501
SilentBottleneckGrant,

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.

Divergence 4 (cont.): new SilentBottleneckGrant import to support the donor exclusion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

intended, a capacity transfer means we will downscale an operator's actors to create headroom for another operator to upscale. To identify a donor, we go through multiple checks, and one silent bottlenecks

pytest.param(dict(max_size=10, running=10), 0, id="at-max-size"),
],
)
def test_silent_bottleneck_growth_delta_ignores_backlog(pool_kwargs, expected):

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.

Divergence 5: new test test_silent_bottleneck_growth_delta_ignores_backlog (covers Divergence 1).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

related to div 1



@pytest.mark.parametrize("bottleneck", [True, False], ids=["bottleneck", "not"])
def test_capacity_transfer_never_drains_a_silent_bottleneck(bottleneck):

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.

Divergence 6: new test test_capacity_transfer_never_drains_a_silent_bottleneck (covers Divergence 4).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

related to div 4

@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch from 5cf9408 to 28dca40 Compare November 19, 2026 00:41

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 28dca40. Configure here.

if limit.all_fields_gt(usage):
return True
# Nothing is working, so nothing is stalled.
return not working

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Output budget ignores stalled idle actors

Medium Severity

has_enough_budget_for_prebuffered_outputs skips every actor with num_tasks_in_flight == 0. An actor that already finished its tasks and is sitting at its output cap is treated as not stalled, and if no other actor is in flight the method reports enough budget. The escape hatch then never raises the cap, so a completed-task output deadlock can persist.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 28dca40. Configure here.

@richardliaw
richardliaw force-pushed the iamjustinhsu/ao/07-operator-sizer branch from 28dca40 to 653d1cd Compare November 19, 2026 19:52
@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/07-operator-sizer branch 2 times, most recently from 28dca40 to 87a3441 Compare November 19, 2026 20:55
iamjustinhsu and others added 2 commits November 19, 2026 15:23
## Overview
Add the operator sizer which handles sizing (answers the question: how
many actors of each operator should be running every tick) and placement
(where to scale up new actors, which actor to downscale).

the sizing path is largely broken down into:
- scale_how_many() -> responsible for per operator greedy sizing
decisions (looks at individual operators not the topology as a whole)
- scale_where() -> responsible for placement
- optimize() -> takes a more wholistic view of the topology before
making key sizing decisions, currently supports two rules
- capacity transfer: when we have reached max cluster capacity (cluster
can no longer scale up) we might run into a scenario where both a
producer (upstream) and consumer (downstream) op have a large backlog.
the producer is bottlnecked by the downstream consumer but greedy op
local sizing decisions tries to scale both op's but gets stuck due to
lack of resources. in these scenarios, unused capacity of upstream op's
is transfered to downstream ops via a cross tick (undisturbed) donor
scale down followed by the bottle neck op scale up
- an op may be output back pressured (so greedy sizing would suggest
making no changes for the op) but its downstream is keeping up with its
production speed, in this case the upstream op should scale up as all
its outputs are being promptly consumed

 this pr also adds some new dashboards specific to sizing and placement.

## Glossary

### Capacity

- **reserved**
This dataset's slice of each node, as the autoscaling coordinator hands
it out (`DatasetAllocationView`).

- **committed**
What our non-PG actors hold on a node: running actors plus pending
actors at their target node.

- **free**
  `reserved - committed`, per node.

- **schedulable nodes**
Nodes an op may run on: its label selector matches, and the slice is
large enough for at least one of its actors.

- **constrained**
An op that can run on only some nodes, either because it has a label
selector or requires a GPU.

- **nodes to reclaim**
Nodes where we hold more than our slice allows, for example because the
coordinator shrank the allocation or the node is draining. Actors are
evicted there until we fit within the slice.

- **PG-managed**
An op whose actors are placed through a placement group. The sizer never
picks their node. Non-PG ops are placed by the sizer.

### Per-op sizing (`scale_how_many`)

- **tick**
  One sizing evaluation, performed every `SIZER_CADENCE_S`.

- **warmup**
The first phase of a run. Until every critical op has produced output,
there is no backpressure to react to, so each op is sized to an equal
share of the allocation.

- **has work**
  Input is queued or tasks are in flight.

- **backpressured**
The op's output is blocked: enough of its actors have exhausted their
output budget (`SIZER_OUTQUEUE_FULL_FRACTION`).

- **demand**
How many actors the op needs for its current backlog: queued input plus
tasks in flight.

- **want**
The delta an op asks for based on its own signals, before capacity is
checked.

- **ledger**
  One tick's free capacity, debited as wants are granted.

- **shortfall**
  How many actors an op asked for but was not granted.

- **ungranted**
  An op that asked to grow and was granted zero actors.

### Cross-op optimization (`optimizer`)

- **guard**
A lock over ops: while one rule is resizing an op, nothing else touches
it.

- **keeping up**
A consumer that takes its producer's output as fast as it arrives, so it
is not what limits the pipeline.

- **silent bottleneck**
An op that limits the pipeline but never asks to grow: its actors are
busy and its output is backpressured, while its consumers keep up.

- **capacity transfer**
Moving actors from ops with spare actors (donors) to an op whose ask
keeps going ungranted (the recipient).

- **victim**
  One donor actor evicted to make room for the recipient.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Prasad Palkar <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
@richardliaw
richardliaw force-pushed the iamjustinhsu/ao/07-operator-sizer branch from 9e6bfec to b9ec19b Compare November 19, 2026 23:23

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

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.

3 participants