Skip to content

[core] Move CreateCall to polling thread and add documentation on grpc threads - #55904

Merged
dayshah merged 5 commits into
ray-project:masterfrom
dayshah:move-server-create-call
Dec 14, 2025
Merged

dayshah merged 5 commits into
ray-project:masterfrom
dayshah:move-server-create-call

Conversation

@dayshah

@dayshah dayshah commented Aug 25, 2025 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Today our gRPC servers have polling thread(s) that do the data copying into the ServerCallImpl object. We currently create the new call object after a post to the io_context. It makes more sense to create the call object right after the previous request has been received rather than when the handle callback starts on the io_context. Creating the call is also a non-zero amount of work and the # of polling threads can be scaled up without concurrency issues.

I've also added some documentation on what the thread configs actually do and deleted some unused configs.

@dayshah dayshah added the go add ONLY when ready to merge, run all tests label Aug 25, 2025
@dayshah dayshah changed the title [core] Move create call / receiving off of execution io_context [core] Move create call / receiving request off of execution io_context Aug 25, 2025
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

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.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 10, 2025
@dayshah dayshah added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Sep 15, 2025
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
@dayshah
dayshah force-pushed the move-server-create-call branch from 19af7c8 to 3910112 Compare November 23, 2025 03:45
@dayshah dayshah changed the title [core] Move create call / receiving request off of execution io_context [core] Move creating proto request from main io_context thread onto server polling threads Dec 4, 2025
@dayshah dayshah changed the title [core] Move creating proto request from main io_context thread onto server polling threads [core] Move creating proto request from main io_context thread to server polling threads Dec 4, 2025
@dayshah dayshah changed the title [core] Move creating proto request from main io_context thread to server polling threads [core] Creating proto request from main io_context thread to server polling threads Dec 4, 2025
@dayshah dayshah changed the title [core] Creating proto request from main io_context thread to server polling threads [core] Creating proto request from io_context thread to server polling threads Dec 4, 2025
@dayshah
dayshah marked this pull request as ready for review December 4, 2025 08:50
@dayshah
dayshah requested a review from a team as a code owner December 4, 2025 08:50
@dayshah dayshah changed the title [core] Creating proto request from io_context thread to server polling threads [core] Creating proto request on server polling threads instead of io_context thread Dec 4, 2025
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Dec 4, 2025
@edoakes

edoakes commented Dec 6, 2025

Copy link
Copy Markdown
Collaborator

@ZacAttack @Yicheng-Lu-llll PTAL

Comment thread src/ray/rpc/server_call.h
}
if (!io_service_.stopped()) {
if constexpr (std::is_base_of_v<DelayedServiceHandler, ServiceHandler>) {
if (!service_handler_initialized_) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let me know if I'm wrong. My understanding of async gRPC in Ray is:

  • We have ServerCall - a struct that contains a request's status, request data, etc. gRPC fills it when an actual request arrives.
  • We have a CompletionQueue.
  • We have polling threads. gRPC fills an "empty" ServerCall in CompletionQueue when a request comes, and the polling thread (PollEventsFromCompletionQueue) takes action based on the ServerCall's status:
    PENDING → PROCESSING → SENDING_REPLY → [FINISHED]

Generally, a new request can only be accepted if there is an empty ServerCall registered with the CompletionQueue.

  • If no MaxActiveRPCs limit: we create a new ServerCall in the io_context thread when starting to handle the request (code).
  • If there is a limit: we create a new ServerCall in the polling thread after the request completes (code).

Given this, moving the creation of the next empty ServerCall from the io_context thread to the polling thread in this PR seems reasonable to me: it keeps gRPC-related work (like creating the next ServerCall to accept new requests) in the polling threads and makes the behavior consistent with the MaxActiveRPCs != -1 case.

but, since factory_.CreateCall() just creates an empty ServerCall and registers it with the CompletionQueue (no request data yet), it seems like there shouldn’t be a data copy issue—but please correct me if I’m missing something.

@dayshah dayshah Dec 7, 2025 •

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.

Ya you're right, the CreateCall isn't the source of the data-copying, it was actually this extra copy through the core worker proxy layer that was unnecessary lol #59245.

But ya, moving the create call over to the polling thread still makes sense, since it's a non-zero amount of work and we'll register a new empty server call as soon as we finish receiving the last request. Updated the title and description to reflect this.

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.

@Yicheng-Lu-llll your understanding should turn into a ray internal doc of how async GRPC in Ray works :)

@dayshah dayshah changed the title [core] Creating proto request on server polling threads instead of io_context thread [core] Move CreateCall to polling thread and add documentation on grpc threads Dec 7, 2025

@Yicheng-Lu-llll Yicheng-Lu-llll left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Comment thread src/ray/gcs/gcs_server.cc Resolved
@dayshah
dayshah requested a review from jjyao December 8, 2025 06:52
@dayshah
dayshah merged commit fb2c7b2 into ray-project:master Dec 14, 2025
@dayshah
dayshah deleted the move-server-create-call branch December 14, 2025 22:23
dayshah added a commit that referenced this pull request Dec 16, 2025
kriyanshii pushed a commit to kriyanshii/ray that referenced this pull request Dec 16, 2025
kriyanshii pushed a commit to kriyanshii/ray that referenced this pull request Dec 16, 2025
kriyanshii pushed a commit to kriyanshii/ray that referenced this pull request Dec 17, 2025
xyuzh added a commit to xyuzh/ray that referenced this pull request Jul 31, 2026
…ight-reads io_context

GetClusterId is a lock-free read of an immutable value, but its handler is
posted to the single-threaded node_manager_io_context shared with
RegisterNode/GetAllNodeInfo/CheckAlive. During mass node registration the
loop's queue delay exceeds client deadlines, and DEADLINE_EXCEEDED maps to
TimedOut which IsGrpcRetryableStatus deliberately never retries — so every
connecting process's cluster-ID fetch dies on a constant-value read
(observed as cluster bring-up collapse at 400 nodes).

Fix by isolation on an existing axis instead of new dispatch machinery: add
a dedicated lightweight_rpc_reads_io_context to GcsServerIOContextPolicy
(the GCS's existing mechanism for isolating workloads), and a
RPC_SERVICE_HANDLER_CUSTOM_AUTH_IN_IO_CONTEXT macro variant that posts one
handler to an explicit io_context (_RPC_SERVICE_HANDLER now delegates with
the service's main_service_). GetClusterId is the only opt-in; CheckAlive,
which is starved by the same storms, can follow. A slow handler on the
dedicated loop hurts only itself — unlike inline dispatch on the gRPC
polling thread, which ray-project#55904 tried wholesale and ray-project#59448 reverted for a 2x
plasma-put regression.

Tests: an rpc-layer test proving a handler bound to a dedicated io_context
replies while the service's io_context never runs, and a GCS-layer
regression test that blocks the node_manager io_context and asserts a
2s-deadline SyncGetClusterId still succeeds (fails pre-fix).

Signed-off-by: xyuzh <[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 unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants