Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces bulk consumption and peeking APIs for streaming generators in Ray, including _wait_and_fetch and _wait_generators_bulk in Python, along with corresponding C++ CoreWorker implementations (WaitAndFetch, TryReadObjectRefStreamN, and PeekObjectRefStreamN). These changes are integrated into Ray Data's streaming executor to optimize task completion waiting. The review feedback highlights several critical issues: potential runtime NameErrors due to a missing time import and an un-namespaced exception reference, a bug in TryReadObjectRefStreamN where backpressure_threshold defaults to 0 instead of -1 (which could cause generator hangs), a potential crash from a strict RAY_CHECK_EQ on mismatched task IDs, and the risky use of assert False for control flow validation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| core_worker = self.worker.core_worker | ||
| try: | ||
| core_worker.try_read_next_object_ref_stream_n(self._generator_ref, num_refs) | ||
| except ObjectRefStreamEndOfStreamError: |
There was a problem hiding this comment.
The exception ObjectRefStreamEndOfStreamError is referenced here but it may not be imported in this file's namespace, which would cause a NameError at runtime. It is safer to reference it via ray.exceptions.ObjectRefStreamEndOfStreamError or explicitly import it.
| except ObjectRefStreamEndOfStreamError: | |
| except ray.exceptions.ObjectRefStreamEndOfStreamError: |
| from typing import TYPE_CHECKING, Dict, List, Optional, Tuple | ||
|
|
||
| import ray | ||
| from ray._private.worker import _wait_generators_bulk |
There was a problem hiding this comment.
The time module is used in this file (e.g., time.monotonic()) but is not imported at the top of the file. This will result in a NameError at runtime. Please import time.
| from ray._private.worker import _wait_generators_bulk | |
| import time | |
| from ray._private.worker import _wait_generators_bulk |
| except ray.exceptions.ObjectRefStreamEndOfStreamError: | ||
| try: | ||
| ray.get(self._pending_block_ref) | ||
| assert False, "Above ray.get should raise an exception." |
There was a problem hiding this comment.
Using assert False for control flow validation is risky because assertions can be optimized away when Python is run with the -O flag. If optimized away, this block will silently succeed instead of raising an exception. It is better to explicitly raise a RuntimeError.
| assert False, "Above ray.get should raise an exception." | |
| raise RuntimeError("Above ray.get should raise an exception.") |
adf9211 to
c31abae
Compare
cbfab1f to
5384b20
Compare
This PR adds a new private `_wait_generators_bulk` API for waiting for
batches of next refs from streaming generators to address the challenges
of the current `_next_sync` API.
### The current challenges of the `_next_sync` API are:
1. `_next_sync` is blocking on waiting for the next ref from a generator
because it is where we signal the backpressure of a streaming generator
by advancing the read index of the generator.
2. `_next_sync` doesn't allow waiting for multiple refs with different
`fetch_local` configurations.
These 2 challenges are inconvenient to Ray Data's use cases because:
1. Ray Data needs to wait for multiple generators in parallel to keep
the data pipeline running instead of idling.
2. Ray Data needs to wait for 2 refs from each generator each time, a
block ref, and a metadata ref, with different fetch_local
configurations, so they can't just use `ray.wait(...,
fetch_local=True)`.
### Proposed solution:
Add a new private `_wait_generators_bulk` API for waiting on multiple
next refs from streaming generators. The example usage is as follows:
```python
ready = _wait_generators_bulk(
[
(gen1, [True, False]),
(gen2, [False, True])
],
num_return=1,
timeout=2,
)
assert ready == [(gen1, [ref1, ref2])]
```
The API will return a list of tuples, each containing a generator and a
list of refs. The refs in the list are the next refs from the generator
that are all ready and pulled locally if the corresponding `fetch_local`
is true.
The API works by waiting for the last ref of each generator first, with
a new `_wait_and_fetch` helper, and then picking the ready generators
from there to issue a second `ray.wait` if their remaining refs are
required to be local.
## Benchmark
The initial integration is done at the PR
#63808 and is benchmarked on the
`worker_scaling_{{num_workers}}_{{worker_type}}` release tests with the
matrix:
```
num_workers: [500, 1000, 2000, 5000]
worker_type: [actors, tasks]
bulk: [0, 1] # whether _wait_generators_bulk path is enabled or not
```
Each config was run 5 times.
### E2E Execution Time
workers | type | bulk=0 | bulk=1 | delta
-- | -- | -- | -- | --
500 | actors | 67.375 +- 0.097 | 65.240 +- 0.979 | -3.17%
500 | tasks | 61.225 +- 0.529 | 53.870 +- 0.234 | -12.01%
1000 | actors | 123.388 +- 0.790 | 110.373 +- 0.534 | -10.55%
1000 | tasks | 115.860 +- 0.811 | 95.560 +- 0.607 | -17.52%
2000 | actors | 261.420 +- 2.266 | 216.533 +- 2.723 | -17.17%
2000 | tasks | 228.154 +- 4.027 | 178.552 +- 0.491 | -21.74%
5000 | actors | 555.034 +- 9.703 | 340.000 +- 10.101 | -38.74%
5000 | tasks | 479.263 +- 12.886 | 395.351 +- 15.269 | -17.51%
---------
Signed-off-by: Rueian Huang <[email protected]>
9d6bf8a to
ce108fd
Compare
Rebased onto master, keeping only the python/ray/data changes from the worker-wait-fetch-perf branch (all core/_raylet/task_manager changes are already in master). Reconciled map_operator.py: kept master's custom_op_stats reporting while preserving the grouped-yield perf optimization (yield block + metadata together via _num_objects_per_yield=2). Signed-off-by: Rueian Huang <[email protected]>
ce108fd to
443e068
Compare
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
This pull request has been automatically closed because there has been no more activity in the 14 days Please feel free to reopen or open a new pull request if you'd still like this to be addressed. Again, you can always ask for help on our discussion forum or Ray's public slack channel. Thanks again for your contribution! |
This PR adds a new private `_wait_generators_bulk` API for waiting for
batches of next refs from streaming generators to address the challenges
of the current `_next_sync` API.
### The current challenges of the `_next_sync` API are:
1. `_next_sync` is blocking on waiting for the next ref from a generator
because it is where we signal the backpressure of a streaming generator
by advancing the read index of the generator.
2. `_next_sync` doesn't allow waiting for multiple refs with different
`fetch_local` configurations.
These 2 challenges are inconvenient to Ray Data's use cases because:
1. Ray Data needs to wait for multiple generators in parallel to keep
the data pipeline running instead of idling.
2. Ray Data needs to wait for 2 refs from each generator each time, a
block ref, and a metadata ref, with different fetch_local
configurations, so they can't just use `ray.wait(...,
fetch_local=True)`.
### Proposed solution:
Add a new private `_wait_generators_bulk` API for waiting on multiple
next refs from streaming generators. The example usage is as follows:
```python
ready = _wait_generators_bulk(
[
(gen1, [True, False]),
(gen2, [False, True])
],
num_return=1,
timeout=2,
)
assert ready == [(gen1, [ref1, ref2])]
```
The API will return a list of tuples, each containing a generator and a
list of refs. The refs in the list are the next refs from the generator
that are all ready and pulled locally if the corresponding `fetch_local`
is true.
The API works by waiting for the last ref of each generator first, with
a new `_wait_and_fetch` helper, and then picking the ready generators
from there to issue a second `ray.wait` if their remaining refs are
required to be local.
## Benchmark
The initial integration is done at the PR
ray-project#63808 and is benchmarked on the
`worker_scaling_{{num_workers}}_{{worker_type}}` release tests with the
matrix:
```
num_workers: [500, 1000, 2000, 5000]
worker_type: [actors, tasks]
bulk: [0, 1] # whether _wait_generators_bulk path is enabled or not
```
Each config was run 5 times.
### E2E Execution Time
workers | type | bulk=0 | bulk=1 | delta
-- | -- | -- | -- | --
500 | actors | 67.375 +- 0.097 | 65.240 +- 0.979 | -3.17%
500 | tasks | 61.225 +- 0.529 | 53.870 +- 0.234 | -12.01%
1000 | actors | 123.388 +- 0.790 | 110.373 +- 0.534 | -10.55%
1000 | tasks | 115.860 +- 0.811 | 95.560 +- 0.607 | -17.52%
2000 | actors | 261.420 +- 2.266 | 216.533 +- 2.723 | -17.17%
2000 | tasks | 228.154 +- 4.027 | 178.552 +- 0.491 | -21.74%
5000 | actors | 555.034 +- 9.703 | 340.000 +- 10.101 | -38.74%
5000 | tasks | 479.263 +- 12.886 | 395.351 +- 15.269 | -17.51%
---------
Signed-off-by: Rueian Huang <[email protected]>
Signed-off-by: 400Ping <[email protected]>
DO NOT MERGE. See #62741