Skip to content

[Data][4/n] Switch to use BlockRefCounter for object store memory estimation - #64456

Merged
justinvyu merged 55 commits into
ray-project:masterfrom
rayhhome:block-ref-counter-cleanup
Aug 4, 2026
Merged

justinvyu merged 55 commits into
ray-project:masterfrom
rayhhome:block-ref-counter-cleanup

Conversation

@rayhhome

@rayhhome rayhhome commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Switches ResourceManager object-store memory (OSM) tracking from queue-based accounting to BlockRefCounter (BRC) and removes the _external_consumer_bytes special-case path.

ResourceManager OSM estimation

ResourceManager._estimate_object_store_memory_usage now reads from BlockRefCounter instead of calling the old queue-based op.estimate_object_store_usage(state). This is the only change visible to the scheduler; over/under-estimation here affects backpressure decisions. The benefits are twofold:

  1. We can remove complicated logic to compute queue sizes through "ineligible operators" which don't create new blocks.
    • Example 1: Map->Limit previously needed to add together the bytes of multiple input/output queues for the Map and Limit operator, even though Map is the only operator that introduced new outputs to the system.
    • Example 2: Union
      Map1 --> Union --> ...
      Map2 ----^
      
      In this case, the accounting gets even more convoluted because each output block of a Map needs to be traced through the Union branches. This can have liveness and throughput impacts, since incorrect accounting can cause both Maps to be backpressured even though only one is overproducing.
  2. With callback-based tracking, explicitly reporting bytes from external consumers (such as iterators, streaming_split in the training ingest case) is no longer needed: the consumer holds an ObjectRef, so the bytes remain attributed until the ref is dropped and the callback fires.

Backpressure formula

The output pressure calculation in DownstreamCapacityBackpressurePolicy changes from output_queue_bytes / downstream_capacity to (get_mem_op_outputs / downstream_capacity) - 1. We use get_mem_op_outputs (BRC-based) rather than get_op_usage because get_op_usage includes pending_task_outputs, which can be large for heavy tasks and would over-backpressure. The -1 accounts for BRC tracking all live blocks including those already in downstream's pending_task_inputs.

Removal of _external_consumer_bytes

Previously, handing a block to an external consumer required an explicit set_external_consumer_bytes call from the iterator to keep the memory budget accurate. With BRC this is no longer needed. We still keep a set_external_consumer(True) which is used by a liveness escape hatch.

Tests

  • Updated test_downstream_capacity_backpressure_policy.py with BRC-based output pressure logic and renamed helpers.
  • Updated test_resource_manager.py and unit/test_resource_manager.py to validate _estimate_object_store_memory_usage against BRC accounting. Removed test_external_consumer_bytes_* tests that tested the removed path. Added test_external_consumer_bytes_not_double_counted and test_union_no_double_counting.
  • Existing e2e tests (test_backpressure_e2e.py, test_streaming_integration.py) implicitly cover the behavioral change.

Formula equivalence validation

We added temporary instrumentation in ResourceManager.update_usages() comparing the new BRC value against the old queue-based formula for each operator on every scheduling loop iteration, and ran it across ~800 release test jobs:

# Temporary check added during validation (now removed)
brc_bytes = self._mem_op_outputs.get(op, 0)  # new: BlockRefCounter
queue_based_total = (                         # old: queue-based
    op.metrics.obj_store_mem_internal_outqueue
    + state.output_queue_bytes()
    + sum(dep.metrics.obj_store_mem_internal_inqueue for dep in op.output_dependencies)
    + sum(dep.metrics.obj_store_mem_pending_task_inputs or 0 for dep in op.output_dependencies)
)
divergence = brc_bytes - queue_based_total
if divergence != 0 and ds_pending > 0:
    logger.warning(f"DIVERGE {op.name}: brc={brc_bytes}, queue_based={queue_based_total}")

Results:

  • 198/202 tests showed exact zero divergence in a representative run.
  • All observed divergences are fully explained and benign: GIL timing gap between task completion and callback firing (1-2 blocks, self-corrects in one scheduling loop iteration), ShuffleMapOperator returning 0 by design (its outputs are intermediate partitions managed by the reduce stage), and terminal Sort operator blocks consumed by materialize() that are alive in BRC but no longer in any executor queue.
  • No divergence affected backpressure decisions (ratio impact < 0.01, threshold = 2.0).

Regression testing summary

Across 8 PR builds and 8 master builds, all benchmark averages fall within master's min-max range or within 5% of it. Scanning all 206 test jobs in the latest PR build, only 3 triggered DownstreamCapacityBackpressurePolicy, none of which showed regression.

Related issues

Depends on #64191 ([3/n] operator wiring).
Related to #63601 (prototype), #63074 (previous manual BlockRefCounter).

@rayhhome rayhhome self-assigned this Jun 30, 2026
@rayhhome rayhhome added core Issues that should be addressed in Ray Core data Ray Data-related issues labels Jun 30, 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 centralized BlockRefCounter to track object-store memory usage per operator via Ray Core out-of-scope callbacks, replacing the previous estimation-based object store usage accounting. Operators now register produced blocks with the BlockRefCounter when they are yielded, and the ResourceManager queries this counter to get live memory usage per operator. The review feedback suggests lazy-loading the default add_object_out_of_scope_callback from global_worker inside on_block_produced instead of resolving it in __init__ to prevent AttributeError in environments where Ray is not yet initialized.

Comment on lines +17 to +27
def __init__(
self,
add_object_out_of_scope_callback: Optional[
Callable[["ray.ObjectRef", Callable[[bytes], None]], bool]
] = None,
):
if add_object_out_of_scope_callback is None:
add_object_out_of_scope_callback = (
global_worker.core_worker.add_object_out_of_scope_callback # pyrefly: ignore[missing-attribute]
)
self._add_callback_fn = add_object_out_of_scope_callback

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

To prevent AttributeError when BlockRefCounter is instantiated in environments where Ray is not yet initialized (such as unit tests that don't start a Ray cluster), we should lazy-load the add_object_out_of_scope_callback from global_worker inside on_block_produced instead of resolving it immediately in __init__.

    def __init__(
        self,
        add_object_out_of_scope_callback: Optional[
            Callable[["ray.ObjectRef", Callable[[bytes], None]], bool]
        ] = None,
    ):
        self._add_callback_fn = add_object_out_of_scope_callback

Comment on lines +64 to +65
try:
registered = self._add_callback_fn(block_ref, _on_object_freed)

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

Lazy-load the default out-of-scope callback from global_worker if it was not explicitly provided during initialization.

Suggested change
try:
registered = self._add_callback_fn(block_ref, _on_object_freed)
if self._add_callback_fn is None:
self._add_callback_fn = (
global_worker.core_worker.add_object_out_of_scope_callback # pyrefly: ignore[missing-attribute]
)
try:
registered = self._add_callback_fn(block_ref, _on_object_freed)

@rayhhome rayhhome added the go add ONLY when ready to merge, run all tests label Jun 30, 2026
@rayhhome
rayhhome marked this pull request as ready for review June 30, 2026 21:46
@rayhhome
rayhhome requested a review from a team as a code owner June 30, 2026 21:46
Copilot AI review requested due to automatic review settings June 30, 2026 21:46

Copilot AI 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.

Pull request overview

This PR removes per-executor _external_consumer_bytes accounting from ResourceManager and switches object-store memory attribution fully to the new BlockRefCounter (Ray Core out-of-scope callback based). It also simplifies “external consumer” tracking to a boolean flag used for OutputBackpressureGuard behavior distinctions (iterator-consumed vs write pipelines).

Changes:

  • Replace ResourceManager object-store usage estimation with BlockRefCounter-based per-operator accounting and remove external-consumer-bytes APIs.
  • Thread a shared BlockRefCounter through StreamingExecutor → build_streaming_topology → PhysicalOperator.start and register produced blocks from tasks/operators.
  • Update iterator/stream-split paths and tests; add new BlockRefCounter lifecycle/thread-safety tests.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
python/ray/data/_internal/execution/block_ref_counter.py Introduces callback-based per-operator object-store byte accounting.
python/ray/data/_internal/execution/resource_manager.py Removes _external_consumer_bytes; reads per-op bytes from BlockRefCounter.
python/ray/data/_internal/execution/streaming_executor.py Creates/clears shared BlockRefCounter; replaces set_external_consumer_bytes with set_external_consumer.
python/ray/data/_internal/execution/streaming_executor_state.py Requires shared BlockRefCounter for topology construction and passes it into op.start().
python/ray/data/_internal/execution/interfaces/physical_operator.py Adds shared counter plumbing to start() and DataOpTask, registering produced blocks on yield.
python/ray/data/_internal/execution/backpressure_policy/downstream_capacity_backpressure_policy.py Terminal edge capacity now returns 0 (no longer consults external-consumer bytes).
python/ray/data/iterator.py Registers external consumer via boolean only; removes prefetch-bytes callback wiring.
python/ray/data/_internal/iterator/stream_split_iterator.py Registers external consumer via boolean only; removes prefetched-bytes reporting.
python/ray/data/_internal/execution/operators/map_operator.py Passes shared counter + producer id into DataOpTask; updates start() signature.
python/ray/data/_internal/execution/operators/actor_pool_map_operator.py Updates start() signature to accept shared counter.
python/ray/data/_internal/execution/operators/input_data_buffer.py Updates start() signature to accept shared counter.
python/ray/data/_internal/execution/operators/union_operator.py Updates start() signature to accept shared counter.
python/ray/data/_internal/execution/operators/output_splitter.py Updates start() signature; registers produced/forwarded blocks for tracking.
python/ray/data/_internal/execution/operators/zip_operator.py Registers zip-produced blocks for tracking.
python/ray/data/_internal/execution/operators/limit_operator.py Registers sliced-output blocks for tracking.
python/ray/data/_internal/execution/operators/aggregate_num_rows.py Registers produced aggregate block for tracking.
python/ray/data/_internal/execution/operators/base_physical_operator.py Registers bulk-op outputs for tracking.
python/ray/data/_internal/execution/operators/shuffle_operators/shuffle_reduce_operator.py Passes shared counter + producer id into DataOpTask; registers empty-partition output.
python/ray/data/_internal/execution/operators/shuffle_operators/shuffle_map_operator.py Removes now-unused estimate_object_store_usage() override.
python/ray/data/_internal/execution/operators/hash_shuffle.py Updates start() signature; passes shared counter + producer id into DataOpTask.
python/ray/data/_internal/gpu_shuffle/hash_shuffle.py Updates start() signature; passes shared counter + producer id into DataOpTask.
python/ray/data/tests/conftest.py Adds noop_counter() helper for tests that need a counter without a Ray cluster.
python/ray/data/tests/unit/test_block_ref_counter.py Adds deterministic unit tests for BlockRefCounter accounting/clear/thread-safety.
python/ray/data/tests/test_block_ref_counter.py Adds integration-style lifecycle tests against Ray Core callback behavior.
python/ray/data/tests/unit/test_resource_manager.py Updates union attribution tests and introduces counter stubbing usage.
python/ray/data/tests/test_resource_manager.py Updates ResourceManager tests for counter-based accounting and removes external-consumer-bytes tests.
python/ray/data/tests/test_streaming_executor.py Updates topology construction and DataOpTask construction for new signatures.
python/ray/data/tests/test_downstream_capacity_backpressure_policy.py Removes external-bytes mocking from test helper.
python/ray/data/tests/test_reservation_based_resource_allocator.py Updates topology construction / ResourceManager construction signatures.
python/ray/data/tests/test_output_splitter.py Updates start() calls to include BlockRefCounter.
python/ray/data/tests/test_operators.py Updates start() calls to include BlockRefCounter.
python/ray/data/tests/test_map_operator.py Updates start() calls to include BlockRefCounter.
python/ray/data/tests/test_limit_operator.py Starts ops with a shared noop counter for manual operator driving.
python/ray/data/tests/test_gpu_shuffle.py Sets operator _block_ref_counter for test setup consistency.
python/ray/data/tests/test_executor_resource_management.py Updates start() calls to include BlockRefCounter.
python/ray/data/tests/test_actor_pool_map_operator.py Updates start() calls; updates topology construction for new signature.
python/ray/data/BUILD.bazel Adds Bazel py_test target for test_block_ref_counter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +539 to 547
topo = build_streaming_topology(o2, ExecutionOptions(), noop_counter())

resource_manager = ResourceManager(
topo,
ExecutionOptions(),
MagicMock(),
DataContext.get_current(),
BlockRefCounter(),
)
Comment on lines +761 to 768
topo = build_streaming_topology(o3, opt, noop_counter())
resource_manager = ResourceManager(
topo,
ExecutionOptions(),
MagicMock(return_value=ExecutionResources.zero()),
DataContext.get_current(),
BlockRefCounter(),
)
Comment on lines +45 to +46
def set_usage(self, producer_id: str, bytes: int) -> None:
self._bytes_by_producer[producer_id] = bytes
@rayhhome

rayhhome commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Close to change merge target. (Reopened because previous commits have merge target on master, so setting the target of this PR on dependent branches break file changes.)

rayhhome added 13 commits July 2, 2026 22:29
Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: Sirui Huang <[email protected]>
…perator tests since _output_operator is removed

Signed-off-by: Sirui Huang <[email protected]>

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

Great work! 😄

A few things to fix:

  1. The PR description and title need to be updated to reflect the changes in this PR. Since we merged 4+5 together. It's misleading to only say that this PR is removing external consumer bytes.
  2. Do you have the tests asserting downstream capacity ratio calculation equivalence?
  3. Can you attach the summary of the regression testing results?

Comment on lines -139 to -141
if not op.output_dependencies:
# No output dependencies, return external consumer bytes.
return self._resource_manager.get_external_consumer_bytes()

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.

LFG!! Great to remove this external consumer special case codepath!

As a note for the future, the reason why we can remove this is:

logger.debug(
"DownstreamCapacityBackpressurePolicy enabled with backpressure "
f"capacity ratio: {self._backpressure_capacity_ratio}"
f"Backpressure ratio: {self._backpressure_capacity_ratio}"

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.

Suggested change
f"Backpressure ratio: {self._backpressure_capacity_ratio}"
f"ratio threshold: {self._backpressure_capacity_ratio}"

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.

Applied in new commit!

Comment on lines +166 to +167
def _get_backpressure_ratio(self, op: "PhysicalOperator") -> float:
"""Ratio of buffered output bytes to downstream capacity."""

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.

Suggested change
def _get_backpressure_ratio(self, op: "PhysicalOperator") -> float:
"""Ratio of buffered output bytes to downstream capacity."""
def _get_output_pressure(self, op: "PhysicalOperator") -> float:
"""Calculate the output pressure of the current operator on the downstream operator.
We estimate this with: `op_output_bytes / downstream_bytes_in_flight`
If output_pressure == 0, the consumer may be starving for inputs. Don't apply backpressure.
If output_pressure == 1, we have exactly one "batch" of prefetched outputs, and the pipeline should be flowing smoothly since the producer is keeping up.
If output_pressure > THRESHOLD, the producer is outpacing the consumer significantly. Apply backpressure."""

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.

"backpressure ratio" is kind of a non-descriptive naming. Output pressure seems better. Open to brainstorming if you have some better ideas.

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.

"output pressure" is pretty good; I was using "output ratio" before going for "backpressure ratio" because it didn't really capture the role of this variable, but I think "output pressure" summarizes its role and also how it's derived quite well

Comment on lines +173 to +176
output_size_bytes = self._resource_manager.get_mem_op_outputs(
op, include_ineligible_downstream=True
)
return (output_size_bytes / downstream_capacity_size_bytes) - 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.

Add a comment to explain this -1

output_pressure = op_outqueue_bytes / downstream_in_flight_input_bytes

output_size_bytes = (op_outqueue_bytes + downstream_in_flight_input_bytes)

output_pressure = (output_size_bytes - downstream_in_flight_input_bytes / downstream_in_flight_input_bytes) = output_size_bytes/downstream_in_flight_input_bytes - 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.

Applied in new commit!

@rayhhome rayhhome left a comment

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.

Thanks for the review:

  1. Updated the PR description to include changes from [4/n]!
  2. There are unit tests that verify the new formula's correctness in test_downstream_capacity_backpressure_policy.py (e.g. _set_output_pressure with known values and assert the policy generates the right decision); I didn't go with permanent equivalence assertions since it doesn't make sense to refer to the queue-based calculations in the tests, and using fixed values for assertions would just be checking the math of our implementation. For completeness, I added a section in the PR description summarizing the experiments I conducted to check formula equivalence between the old and the new approaches.
  3. Added summaries of release test results in the PR description!

Comment on lines +166 to +167
def _get_backpressure_ratio(self, op: "PhysicalOperator") -> float:
"""Ratio of buffered output bytes to downstream capacity."""

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.

"output pressure" is pretty good; I was using "output ratio" before going for "backpressure ratio" because it didn't really capture the role of this variable, but I think "output pressure" summarizes its role and also how it's derived quite well

Comment on lines +173 to +176
output_size_bytes = self._resource_manager.get_mem_op_outputs(
op, include_ineligible_downstream=True
)
return (output_size_bytes / downstream_capacity_size_bytes) - 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.

Applied in new commit!

logger.debug(
"DownstreamCapacityBackpressurePolicy enabled with backpressure "
f"capacity ratio: {self._backpressure_capacity_ratio}"
f"Backpressure ratio: {self._backpressure_capacity_ratio}"

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.

Applied in new commit!

Signed-off-by: Sirui Huang <[email protected]>
@rayhhome rayhhome changed the title [Data] [Core] [5/n] Remove _external_consumer_bytes from ResourceManager [Data] [Core] [4/n] Switch to BlockRefCounter-based Memory Tracking and Backpressure Aug 4, 2026
@justinvyu justinvyu changed the title [Data] [Core] [4/n] Switch to BlockRefCounter-based Memory Tracking and Backpressure [data][4/n] Switch to use BlockRefCounter for object store memory estimation Aug 4, 2026

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

Thanks!

Comment on lines +1053 to +1059
def estimate_object_store_usage(self) -> int:
"""Returns this operator's object store memory usage in bytes.

# TODO fix ineligible ops: this needs to include usage of all of OS
# for ineligible ops
#
# Outputs of this operator used downstream
used_op_outputs_bytes = sum(
(
downstream_op.metrics.obj_store_mem_internal_inqueue_for_input(
downstream_op.input_dependencies.index(self)
)
+ downstream_op.metrics.obj_store_mem_pending_task_inputs
)
for downstream_op in self.output_dependencies
)
return ObjectStoreUsage(
internal=int(mem_op_internal),
outputs=int(op_outputs_bytes + used_op_outputs_bytes),
)
ShuffleMapOperator overrides this since its outputs are intermediate
partitions managed by the reduce stage.
"""
return self._block_ref_counter.get_object_store_memory_usage(self.id)

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.

Note: This is the main change of the PR, which moves from queue-based math to a single dict lookup based on producer id.

@justinvyu
justinvyu merged commit 9b12391 into ray-project:master Aug 4, 2026
6 checks passed
@rayhhome rayhhome changed the title [data][4/n] Switch to use BlockRefCounter for object store memory estimation [Data][4/n] Switch to use BlockRefCounter for object store memory estimation Aug 5, 2026
Artimislyy pushed a commit to Artimislyy/ray that referenced this pull request Aug 11, 2026
…stimation (ray-project#64456)

Switches `ResourceManager` object-store memory (OSM) tracking from
queue-based accounting to `BlockRefCounter` (BRC) and removes the
`_external_consumer_bytes` special-case path.

---------

Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: HFFuture <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
justinvyu pushed a commit that referenced this pull request Aug 14, 2026
…ivate Backpressure (#65474)

#64456 applies the block ref counter to track the object store memory
and control backpressure signals based on downstream capacity, but this
had lead to spilling in training pipelines. This is mainly due to
backpressure not being applied to the terminal operator even though the
external consumer is not consuming blocks quickly enough.

This PR adds back the early return for
`DownstreamCapacityBackpressurePolicy`'s
`_get_downstream_capacity_size_bytes`, so that for terminal operators,
the downstream capacity is the external consumer bytes tracked instead
of 0.

---------

Signed-off-by: Sirui Huang <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…stimation (ray-project#64456)

Switches `ResourceManager` object-store memory (OSM) tracking from
queue-based accounting to `BlockRefCounter` (BRC) and removes the
`_external_consumer_bytes` special-case path.

---------

Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: HFFuture <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…ivate Backpressure (ray-project#65474)

ray-project#64456 applies the block ref counter to track the object store memory
and control backpressure signals based on downstream capacity, but this
had lead to spilling in training pipelines. This is mainly due to
backpressure not being applied to the terminal operator even though the
external consumer is not consuming blocks quickly enough.

This PR adds back the early return for
`DownstreamCapacityBackpressurePolicy`'s
`_get_downstream_capacity_size_bytes`, so that for terminal operators,
the downstream capacity is the external consumer bytes tracked instead
of 0.

---------

Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: 400Ping <[email protected]>
justinvyu pushed a commit that referenced this pull request Sep 22, 2026
`lightgbm_train_batch_inference_benchmark_100G` times out at 600s with
`ReadParquet` pinned at `Tasks: 1
[backpressured:tasks(DownstreamCapacity)]`, turning a ~40s read into
400-560s.

Since #64456 the resource manager tracks object store memory with
`BlockRefCounter`, which counts a block until every reference to it is
gone. The train loop calls `materialize()` on its shard
(`train_batch_inference_benchmark.py:70`), so those blocks stay in the
producing operator's ref-counted output and
`DownstreamCapacityBackpressurePolicy` reads them as output waiting to
be consumed. The ratio only grows, and the producer is throttled for
memory it cannot release by slowing down.

The consumer now reports what it holds, and the policy counts it as
downstream capacity rather than as output waiting to be consumed.
Accounting is unchanged; those bytes really are in the object store and
still count toward every budget.

---------

Signed-off-by: Sirui Huang <[email protected]>
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
)

`lightgbm_train_batch_inference_benchmark_100G` times out at 600s with
`ReadParquet` pinned at `Tasks: 1
[backpressured:tasks(DownstreamCapacity)]`, turning a ~40s read into
400-560s.

Since ray-project#64456 the resource manager tracks object store memory with
`BlockRefCounter`, which counts a block until every reference to it is
gone. The train loop calls `materialize()` on its shard
(`train_batch_inference_benchmark.py:70`), so those blocks stay in the
producing operator's ref-counted output and
`DownstreamCapacityBackpressurePolicy` reads them as output waiting to
be consumed. The ratio only grows, and the producer is throttled for
memory it cannot release by slowing down.

The consumer now reports what it holds, and the policy counts it as
downstream capacity rather than as output waiting to be consumed.
Accounting is unchanged; those bytes really are in the object store and
still count toward every budget.

---------

Signed-off-by: Sirui Huang <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…stimation (ray-project#64456)

Switches `ResourceManager` object-store memory (OSM) tracking from
queue-based accounting to `BlockRefCounter` (BRC) and removes the
`_external_consumer_bytes` special-case path.

---------

Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: HFFuture <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ivate Backpressure (ray-project#65474)

ray-project#64456 applies the block ref counter to track the object store memory
and control backpressure signals based on downstream capacity, but this
had lead to spilling in training pipelines. This is mainly due to
backpressure not being applied to the terminal operator even though the
external consumer is not consuming blocks quickly enough.

This PR adds back the early return for
`DownstreamCapacityBackpressurePolicy`'s
`_get_downstream_capacity_size_bytes`, so that for terminal operators,
the downstream capacity is the external consumer bytes tracked instead
of 0.

---------

Signed-off-by: Sirui Huang <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
)

`lightgbm_train_batch_inference_benchmark_100G` times out at 600s with
`ReadParquet` pinned at `Tasks: 1
[backpressured:tasks(DownstreamCapacity)]`, turning a ~40s read into
400-560s.

Since ray-project#64456 the resource manager tracks object store memory with
`BlockRefCounter`, which counts a block until every reference to it is
gone. The train loop calls `materialize()` on its shard
(`train_batch_inference_benchmark.py:70`), so those blocks stay in the
producing operator's ref-counted output and
`DownstreamCapacityBackpressurePolicy` reads them as output waiting to
be consumed. The ratio only grows, and the producer is throttled for
memory it cannot release by slowing down.

The consumer now reports what it holds, and the policy counts it as
downstream capacity rather than as output waiting to be consumed.
Accounting is unchanged; those bytes really are in the object store and
still count toward every budget.

---------

Signed-off-by: Sirui Huang <[email protected]>
@rayhhome
rayhhome deleted the block-ref-counter-cleanup branch October 19, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core 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.

4 participants