Skip to content

[data][actor-only][1/n] Add resource bank - #67697

Merged
richardliaw merged 3 commits into
masterfrom
iamjustinhsu/ao/01-resource-bank
Nov 6, 2026
Merged

richardliaw merged 3 commits into
masterfrom
iamjustinhsu/ao/01-resource-bank

Conversation

@iamjustinhsu

Copy link
Copy Markdown
Contributor

Summary

Add ResourceBank, which tracks the object-store usage of the actor-only backend's actors per actor, operator, node and (operator, node), and thread it through PhysicalOperator.start(). This is wiring for later PRs: nothing reads the bank yet, and it only exists when RAY_DATA_ACTOR_ONLY_BACKEND=1 (off by default).

Part 1 of 12 of the Ray Data actor-only backend stack. Based on master. Everything here is gated behind RAY_DATA_ACTOR_ONLY_BACKEND (off by default) unless noted under After.

Before

Operators get start(options, block_ref_counter, lineage_tracker). Object-store usage is tracked only per operator (OpRuntimeMetrics). A block's producing node is read from BlockMetadata.exec_stats.node_id, so blocks without exec stats (for example InputDataBuffer inputs) report an unknown node.

After

  • With the flag on, the StreamingExecutor creates a ResourceBank and passes it to every operator through start(..., resource_bank=...). InputDataBuffer and LimitOperator register the blocks they emit, so withdrawals match deposits. Consumers report consumed blocks from get_output_blocking(), and the scheduling thread applies them.
  • On every backend: BlockMetadata carries node_id (and BlockExecStats an optional actor_id). Locality and stats paths read meta.node_id, so source-operator inputs now count as locality hits instead of misses (see the test_stats expectation changes). Map operators also record two new metrics: bytes_remote_inputs_read and num_remote_blocks_read.
flowchart TD
    subgraph Before
        subgraph BS[Subsystem: execution]
            subgraph BC[Component: StreamingExecutor]
                B1[build_streaming_topology] --> B2["op.start(options, ref_counter, lineage_tracker)"]
            end
        end
        subgraph BB[Subsystem: block]
            B3[exec_stats.node_id]
        end
    end
    subgraph After
        subgraph AS[Subsystem: execution]
            subgraph AC[Component: StreamingExecutor]
                A0["ResourceBank (flag on)"] --> A1[build_streaming_topology] --> A2["op.start(..., lineage_tracker, resource_bank)"]
                A4[InputDataBuffer / LimitOperator] -->|on_new_output| A0
            end
        end
        subgraph AB[Subsystem: block]
            A3[BlockMetadata.node_id]
        end
    end
    class A0,A4 added
    class A2,A3 changed
    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

execution (behavioral change, flag-gated), block / data format (BlockMetadata.node_id, all backends), observability (new remote-read metrics; locality-hit accounting)

Testing

Each run used a clean checkout of this branch. Any test that failed was rerun on unmodified master in the same environment; only failures that pass on master count as regressions.

  • RAY_DATA_ACTOR_ONLY_BACKEND=1 pytest python/ray/data/tests/actor_only: 41 passed.
  • pytest python/ray/data/tests/test_stats.py test_split.py test_streaming_executor.py: no new failures vs master (20 environment failures fail identically on master). The 3 test_stats failures caused by node_id moving to BlockStats were fixed in this PR's test helper; those tests now pass.
  • pytest python/ray/data/tests/unit test_operators.py unit/test_limit_operator.py: 2054 passed, 11 failed. The same 11 fail on master.
  • 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 #67710 November 2, 2026 21:05
@iamjustinhsu
iamjustinhsu marked this pull request as ready for review November 2, 2026 21:14
@iamjustinhsu
iamjustinhsu requested a review from a team as a code owner November 2, 2026 21:14
@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 new ResourceBank for per-dataset object-store accounting in the actor-only streaming executor, integrating it across various operators and the streaming executor itself to track live and cumulative object store usage, prebuffered outputs, and cross-node transfers. It also refactors BlockMetadata and BlockStats to track node and actor IDs directly. A high-severity issue was found in actor_pool_map_operator.py where bm.size_bytes could be None, potentially causing a TypeError when added to remote_bytes. A code suggestion was provided to safely handle this with a fallback value.

Comment on lines +516 to +520
for bm in bundle.metadata:
producer_node_id = bm.node_id
if producer_node_id is not None and producer_node_id != actor_node_id:
remote_bytes += bm.size_bytes
remote_blocks += 1

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.

high

In actor_pool_map_operator.py, bm.size_bytes is of type Optional[int] and can be None. Adding bm.size_bytes directly to remote_bytes without a fallback or null check will raise a TypeError and crash the executor if any block has None size metadata. Please use bm.size_bytes or 0 to safely handle None values.

Suggested change
for bm in bundle.metadata:
producer_node_id = bm.node_id
if producer_node_id is not None and producer_node_id != actor_node_id:
remote_bytes += bm.size_bytes
remote_blocks += 1
for bm in bundle.metadata:
producer_node_id = bm.node_id
if producer_node_id is not None and producer_node_id != actor_node_id:
remote_bytes += bm.size_bytes or 0
remote_blocks += 1

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Nov 3, 2026
@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/01-resource-bank branch from e91caba to 77c4e75 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.

"the output was still in flight)."
)
else:
actor_info.live.on_output_consumed(bm=bm)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Downscale consume drops remaining outputs

Medium Severity

After to_downscaled zeros an actor's pulled-output counters, on_output_consumed still decrements that actor whenever the count is non-zero. A later consume of a pre-downscale block (already dropped from the actor) subtracts from post-downscale outputs that are still live, so the actor under-reports remaining object-store use.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 77c4e75. Configure here.

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.

I don't think this is an issue, if an actor downscaled, no in flight tasks are alive

@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/01-resource-bank branch from 77c4e75 to 178fdf2 Compare November 3, 2026 23:10

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

out_metadata.append(metadata)
self._output_blocks_stats.append(metadata.to_stats())
out_metadata.append(sliced_metadata)
self._output_blocks_stats.append(sliced_metadata.to_stats())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Limit drops blocks without bank withdraw

Medium Severity

When LimitOperator hits the row limit mid-bundle, it withdraws only the block it sliced. Remaining unread blocks in that bundle are dropped and never sent through on_block_consumed, so they stay in ResourceBank as live outputs that will never drain.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 178fdf2. Configure here.

iamjustinhsu and others added 3 commits November 6, 2026 00:56
## Overview
Adds a resource bank component to track object store usage of actors. It
can be tracked through multiple ways
- per actor
- per operator
- per node
- per node, operator

The APIs exposed are in the ResourceBankBase class. This class defines
the methods with which an actor pool map operator needs to call to get
accurate resource accounting. Some may notice this as similar to op
runtime metrics -- I have duplicated the APIs since we still need op run
time metrics for backwards compatibility, and since there was a lot of
experimentation, didn't want to maintain op runtime metrics.

## Usage
None at the moment, it is just the wiring. The usage will come after we
finalize the sizer implementation, in later PRs of this stack.

## Additional Info
ResourceBank component can only be used when
`RAY_DATA_ACTOR_ONLY_BACKEND=1`. Currently, this flag is off by default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
@iamjustinhsu
iamjustinhsu force-pushed the iamjustinhsu/ao/01-resource-bank branch from 178fdf2 to 7c299ab 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.

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 7c299ab. Configure here.

left, right, left_meta_ref, right_meta_ref = split_single_block.options(
**options
).remote(b, metadata, left_size)
left_meta, right_meta = ray.get([left_meta_ref, right_meta_ref])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Split path blocks the scheduler

Medium Severity

_split_block now waits on ray.get for split metadata on every backend. Mid-block splits run on the streaming executor thread, so the scheduler stalls until the remote slice finishes instead of only holding the new block refs. That loses overlap with other operators and can hang the whole pipeline if the slice task is slow or stuck.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7c299ab. Configure here.

@richardliaw
richardliaw merged commit d15e901 into master Nov 6, 2026
5 of 6 checks passed
@richardliaw
richardliaw deleted the iamjustinhsu/ao/01-resource-bank branch November 6, 2026 19:59
richardliaw pushed a commit that referenced this pull request Nov 11, 2026
…or pools (#67698)

## Summary
When the actor-only backend is on, promote every `TaskPoolStrategy` map
operator to an equivalent `ActorPoolStrategy` in `MapOperator.create`.
The helper (`maybe_promote_compute_strategy`) is self-gated and does
nothing when the flag is off.

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

## Before
Map operators with a function UDF (or an explicit `TaskPoolStrategy`)
run as `TaskPoolMapOperator`s. `get_compute_strategy` rejects a plain
function paired with an explicit `ActorPoolStrategy`.

## After
- Under the flag, the same operators become actor pools.
- A plain function with an explicit `ActorPoolStrategy` is allowed,
because that's how callers set pool size or prevent fusion.
- ListFiles and Download plan the actor-pool variant and cap the pool at
the real listing parallelism.
- With the flag off, nothing changes.

```mermaid
flowchart TD
    subgraph Before
        subgraph BS[Subsystem: physical planning]
            subgraph BC[Component: MapOperator.create]
                B1[TaskPoolStrategy] --> B2[TaskPoolMapOperator]
            end
        end
    end
    subgraph After
        subgraph AS[Subsystem: physical planning]
            subgraph AC[Component: MapOperator.create]
                A1[TaskPoolStrategy] --> A3["maybe_promote_compute_strategy (flag on)"] --> A2[ActorPoolMapOperator]
            end
        end
    end
    class A3 added
    class A2 changed
    classDef removed fill:#ffcdd2,stroke:#c62828,color:#000
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
```
## Subsystems
physical planning (behavioral change, flag-gated), API
(`get_compute_strategy` validation)

## Testing
Each run used a clean checkout of this branch. Any test that failed was
rerun on unmodified `master` in the same environment; only failures that
pass on master count as regressions.

- `RAY_DATA_ACTOR_ONLY_BACKEND=1 pytest
python/ray/data/tests/actor_only`: 44 passed.
- `pytest python/ray/data/tests/test_actor_pool_map_operator.py
unit/datasource_v2/test_list_files_op.py test_map.py
test_map_operator.py test_combine_downloads.py`: 399 passed, 4 failed.
The same 4 fail on master.
- `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](https://claude.com/claude-code)

Signed-off-by: iamjustinhsu <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Prasad Palkar <[email protected]>
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