Repository navigation
[Data] Count Materialized Data as Downstream Capacity - #66226
Conversation
Signed-off-by: Sirui Huang <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces tracking for retained consumer bytes to prevent unnecessary backpressure when external consumers hold onto materialized data. By reporting these retained bytes back to the executor, the backpressure policy can subtract them from the operator's output size instead of treating them as queue backlog. The review feedback points out a potential leak where client retained bytes are not cleared if a consumer exits early, suggesting that they should also be cleared in notify_split_finished().
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core backpressure/resource-signaling behavior in the streaming executor path, which can have subtle performance and liveness implications that merit final human review even though unit tests were added.
Pull request overview
This PR updates Ray Data’s downstream-capacity backpressure signal so that blocks retained by external consumers (e.g., Train loops calling materialize() on iterators/split shards) are not misinterpreted as unconsumed output backlog, which can otherwise throttle producers indefinitely under DownstreamCapacityBackpressurePolicy.
Changes:
- Add retained-by-consumer byte reporting from
DataIterator.materialize()and propagate it throughStreamingExecutor/ResourceManager. - Extend
StreamSplitDataIterator/SplitCoordinatorto report retained bytes via the existing per-bundleget()RPC path. - Subtract retained-consumer bytes from output-pressure computation only when the operator has no eligible downstream operator, and add tests covering the new reporting and policy behavior.
File summaries
| File | Description |
|---|---|
| python/ray/data/iterator.py | Report cumulative retained bytes during materialize() and reset at the end of the collection. |
| python/ray/data/_internal/iterator/stream_split_iterator.py | Store retained bytes client-side and send them to the SplitCoordinator on the next get; coordinator aggregates and reports totals to the executor. |
| python/ray/data/_internal/execution/streaming_executor.py | Add a pass-through setter to forward retained-consumer bytes to the resource manager. |
| python/ray/data/_internal/execution/resource_manager.py | Track retained-consumer bytes and expose getter/setter APIs. |
| python/ray/data/_internal/execution/backpressure_policy/downstream_capacity_backpressure_policy.py | Subtract retained-consumer bytes from output-size only for ops with no eligible downstream when computing output pressure. |
| python/ray/data/tests/test_downstream_capacity_backpressure_policy.py | Update mocks to include retained-consumer bytes and add coverage for the subtraction behavior. |
| python/ray/data/tests/test_iterator.py | Add a test asserting materialize() reports monotonically increasing retained bytes and resets to zero. |
| python/ray/data/tests/test_split.py | Add a streaming-split test that validates retained bytes are reported (non-zero peak) and cleared at completion. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Sirui Huang <[email protected]>
…pressure signal Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: Sirui Huang <[email protected]>
…r bytes Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: Sirui Huang <[email protected]>
|
|
||
| ref_bundles_iter, stats, _ = self._to_ref_bundle_iterator() | ||
| ref_bundles = list(ref_bundles_iter) | ||
| ref_bundles_iter, stats, executor = self._to_ref_bundle_iterator() |
There was a problem hiding this comment.
Can we just increment stats.iter_prefetched_bytes directly so we don't need to introduce a new concept? iter batches and materialized blocks both count as "prefetched bytes on the consumer."
stats.iter_prefetched_bytes += block_bytesSigned-off-by: Sirui Huang <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 452219f. Configure here.
| ref_bundles.append(ref_bundle) | ||
| finally: | ||
| # Nothing else on this path resets the field. | ||
| stats.iter_prefetched_bytes = 0 |
There was a problem hiding this comment.
Local materialize drops capacity reports
Medium Severity
Incrementing iter_prefetched_bytes during materialize() only reaches the resource manager on the streaming-split path, where gen_blocks already reads that field. A regular DataIterator has no such reader, and the executor that previously received set_external_consumer_bytes is now discarded, so held blocks still look like producer backlog and can throttle the producer the same way this change is meant to prevent.
Reviewed by Cursor Bugbot for commit 452219f. Configure here.
Signed-off-by: Sirui Huang <[email protected]>
Signed-off-by: Sirui Huang <[email protected]>
| stats.iter_prefetched_bytes += ref_bundle.size_bytes() | ||
| ref_bundles.append(ref_bundle) | ||
| finally: | ||
| stats.iter_prefetched_bytes = 0 |
There was a problem hiding this comment.
Technically the prefetched bytes stick around while the MaterializedDataset object lives. I think it shouldn't matter but semantically resetting this to zero while the ref_bundles are still around is slightly misleading.
There was a problem hiding this comment.
This should also make the test simpler
There was a problem hiding this comment.
Double-checked the logic; I think I mistook how to scope MaterializedDataset's accumulated bytes. I've removed the finally block so that we now keep the total number of bytes materialized.
…finally block which reset prefecteched bytes Signed-off-by: Sirui Huang <[email protected]>
…n _to_ref_bundle_iterator Signed-off-by: Sirui Huang <[email protected]>
| # The prefetched bytes stat should not accumulate across different executions | ||
| # because this stat is used by the StreamingExecutor for backpressure decisions. | ||
| self._iter_stats.iter_prefetched_bytes = 0 |
There was a problem hiding this comment.
Note for a followup: the reason we need to reset this value is that iter_prefetched_bytes is the only property of this stats object that's actually read by the executor to make backpressure decisions (downstream capacity backpressure)
If this property kept accumulating across each execution, then every execution after the first one would use an incorrect value to make backpressure decisions.
Another discrepancy: the stats object is reused across executions in the streaming split iterator case, but reset on each execution for a non streaming split iterator.
We may want to consider clearing/resetting the stats object on each execution for the streaming split case too. Or, remove this special case from the stats object.
…acity (#66226) (#66371) Cherry-pick of #66226 (master commit b18315e) onto releases/2.59.0. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Sirui Huang <[email protected]> Signed-off-by: elliot-barn <[email protected]> Co-authored-by: HFFuture <[email protected]>
) `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]>
) `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]>


Description
lightgbm_train_batch_inference_benchmark_100Gtimes out at 600s withReadParquetpinned atTasks: 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 callsmaterialize()on its shard (train_batch_inference_benchmark.py:70), so those blocks stay in the producing operator's ref-counted output andDownstreamCapacityBackpressurePolicyreads 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.
Additional information
We also now resets
StreamingSplitDataIterator'siter_prefetched_bytesto 0 when_to_ref_bundle_iterator()is called on it. We made this decision because otherwise, this number will accumulate across executions forStreamingSplitDataIteratorwhenmaterialize()is called multiple times, which means one iterator materialized twice can occupy two times total number of bytes and is thus incorrect. Please read #66226 (review) for full context.The reported prefetched bytes total is a single global, so it goes into the single global term.
_get_downstream_capacity_size_bytesreaches the external consumer's bytes only for an operator whose consumer is external; an upstream operator still paces against its downstream operator's in-flight inputs.Because capacity includes what the consumer holds, a producer may build a larger queue during a
materialize()than during ordinary iteration, bounded there by the object store budget rather than by the prefetch window.Checks
Not a duplicate: #66095 targeted the same test and is closed. This uses a consumer-reported total instead of recomputing output pressure from queue metrics, avoiding a shared output queue walk that over-charges each parent of an ineligible multi-input operator.
AI assistance was used to write this change.