Repository navigation
[core] Move CreateCall to polling thread and add documentation on grpc threads - #55904
Conversation
|
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. |
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
19af7c8 to
3910112
Compare
| } | ||
| if (!io_service_.stopped()) { | ||
| if constexpr (std::is_base_of_v<DelayedServiceHandler, ServiceHandler>) { | ||
| if (!service_handler_initialized_) { |
There was a problem hiding this comment.
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
MaxActiveRPCslimit: 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@Yicheng-Lu-llll your understanding should turn into a ray internal doc of how async GRPC in Ray works :)
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
…c threads (ray-project#55904) Signed-off-by: dayshah <[email protected]> Signed-off-by: kriyanshii <[email protected]>
…y-project#59448) Signed-off-by: dayshah <[email protected]> Signed-off-by: kriyanshii <[email protected]>
…c threads (ray-project#55904) Signed-off-by: dayshah <[email protected]> Signed-off-by: kriyanshii <[email protected]>
…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]>
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.