Skip to content

[core] Subscribe to specific owner worker deaths instead of all worker deaths for generator backpressure - #65195

Merged
sampan-s-nayak merged 3 commits into
ray-project:masterfrom
sampan-s-nayak:keyed-owner-death-subscription
Aug 6, 2026
Merged

sampan-s-nayak merged 3 commits into
ray-project:masterfrom
sampan-s-nayak:keyed-owner-death-subscription

Conversation

@sampan-s-nayak

@sampan-s-nayak sampan-s-nayak commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #65136: instead of the backpressured generator executor subscribing to all worker failures and filtering client-side, this adds support for keyed SubscribeWorkerFailure(worker_id) to the pubsub/accessor layers and has the core worker subscribe only to the owners of the backpressured generator tasks it is actually running.

@sampan-s-nayak
sampan-s-nayak requested a review from a team as a code owner August 4, 2026 06:22

@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 replaces the global subscription to all worker failures with a keyed subscription to individual owner worker failures for generator backpressure cleanup, reducing GCS fan-out overhead. The changes implement keyed subscription and unsubscription APIs across GcsSubscriber, WorkerInfoAccessor, and CoreWorker, handle race conditions and GCS reconnection replays, and update the pubsub subscriber to use insert_or_assign to prevent stale callbacks. Comprehensive unit tests have been added to verify these changes. There are no review comments, so I have no feedback to provide.

Comment thread src/ray/gcs_rpc_client/accessor.cc Resolved
Comment thread src/ray/pubsub/gcs_subscriber.h Resolved
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Aug 4, 2026
@sampan-s-nayak
sampan-s-nayak force-pushed the keyed-owner-death-subscription branch from 7600884 to a85853a Compare August 4, 2026 08:01
Comment thread src/ray/core_worker/core_worker.h Resolved
…r deaths for generator backpressure

Adds a keyed SubscribeWorkerFailure(worker_id) to the pubsub/accessor
layers and makes the core worker subscribe only to the owners of the
backpressured generator tasks it runs, instead of subscribing to every
worker failure in the cluster. The GCS routes keyed subscriptions via
its per-entity index, so the fan-out per worker death is
O(raylets) + O(interested executors) rather than O(workers).

A liveness fetch after each subscribe closes the no-replay window where
the owner died before the subscription landed; a missing worker-table
row after a successful subscribe is treated as dead since the table
only evicts dead entries. Per-worker subscribe operations are replayed
by AsyncResubscribe (including the fetch) after GCS failover, and
SubscriberChannel keyed subscriptions now use insert_or_assign so a
re-subscribed key cannot keep a stale callback.

Signed-off-by: sampan <[email protected]>
@sampan-s-nayak
sampan-s-nayak force-pushed the keyed-owner-death-subscription branch from a85853a to 800b686 Compare August 4, 2026 09:26

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

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 67b678c. Configure here.

Comment thread src/ray/core_worker/core_worker.cc Resolved
Signed-off-by: sampan <[email protected]>
@sampan-s-nayak
sampan-s-nayak force-pushed the keyed-owner-death-subscription branch from 67b678c to 3261bc5 Compare August 4, 2026 10:25
for (const auto &[_, operation] : per_worker_subscribe_operations_) {
// nullptr makes the operation fall back to its captured `done` callback,
// re-running the caller's post-subscribe logic (e.g. the liveness fetch).
operation(nullptr);

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.

These per_worker_subscribe_operations_ are PRCs. Is it possible that we don't run them under the lock? I am worried that we can acquire the lock for too long.

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.

if its outside lock then parallel unsubscribes may race (currently not a problem as I subscribe and unsubscribe within a lock on core worker end, but given this is a client I thought of trying to keep it safe)

also I feel as this client is per process, there shouldnt be a lot of traffic so slight delays could be acceptable. but let me know what you think

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.

👍

@sampan-s-nayak sampan-s-nayak added the go add ONLY when ready to merge, run all tests label Aug 5, 2026
@sampan-s-nayak
sampan-s-nayak merged commit b45b0b4 into ray-project:master Aug 6, 2026
6 checks passed
Artimislyy pushed a commit to Artimislyy/ray that referenced this pull request Aug 11, 2026
…r deaths for generator backpressure (ray-project#65195)

## Description

Follow-up to ray-project#65136: instead of the backpressured generator executor
subscribing to all worker failures and filtering client-side, this adds
support for keyed `SubscribeWorkerFailure(worker_id)` to the
pubsub/accessor layers and has the core worker subscribe only to the
owners of the backpressured generator tasks it is actually running.

---------

Signed-off-by: sampan <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Rueian <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…r deaths for generator backpressure (ray-project#65195)

## Description

Follow-up to ray-project#65136: instead of the backpressured generator executor
subscribing to all worker failures and filtering client-side, this adds
support for keyed `SubscribeWorkerFailure(worker_id)` to the
pubsub/accessor layers and has the core worker subscribe only to the
owners of the backpressured generator tasks it is actually running.

---------

Signed-off-by: sampan <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Rueian <[email protected]>
Signed-off-by: 400Ping <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…r deaths for generator backpressure (ray-project#65195)

## Description

Follow-up to ray-project#65136: instead of the backpressured generator executor
subscribing to all worker failures and filtering client-side, this adds
support for keyed `SubscribeWorkerFailure(worker_id)` to the
pubsub/accessor layers and has the core worker subscribe only to the
owners of the backpressured generator tasks it is actually running.

---------

Signed-off-by: sampan <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Rueian <[email protected]>
sampan-s-nayak added a commit that referenced this pull request Nov 17, 2026
)

## Description

Since #63310, the owner sends `UpdateGeneratorBackpressureConsumed` to
the executor on every read from a backpressured streaming generator. The
gRPC send (`grpc_call_start_batch` / `ExecCtx::Flush`) ran inline on the
reading thread. For Ray Data that thread is the streaming executor's
Python scheduling loop, and Ray Data reads twice per block (block ref +
metadata ref), so it pays for 2 RPC sends per block. This was reported
as ~25% of the driver flame graph and a ~30% drop in task dispatch rate:
#63310 (comment)

This PR posts the send to `io_service_` so the reading thread only pays
for a post. The RPC, its contents and the executor side are unchanged.

## Related issues

Related to #63310 (the performance regression reported in the review
thread above).

## Additional information

Microbenchmark: 8 generators × 20k items, waiting until all items are
reported and then timing only `_next_sync` reads on the driver (4-CPU
dev box, 5 trials):

| Build | µs per read |
|---|---|
| master, backpressure off (no RPC) | ~15 |
| master, `_generator_backpressure_num_objects` set | ~120–155 |
| this PR, `_generator_backpressure_num_objects` set | ~25–52 |

Not a duplicate: I searched open PRs for
`UpdateGeneratorBackpressureConsumed` and "generator backpressure
consumed", and none touch this path. #65136 and #65195 only changed
owner-death subscriptions.

Tests run:
- `python -m pytest -q
python/ray/tests/test_streaming_generator_backpressure.py` → 37 passed
- `pre-commit run` → passed

AI assistance (Claude Code) was used for this change. I reviewed the
diff and ran the tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: sampan <[email protected]>
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 go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants