Skip to content

[serve] Refresh GCS node-info cache off the control loop (async)#64510

Open
johntaylor-cell wants to merge 2 commits into
ray-project:masterfrom
johntaylor-cell:serve-async-node-info
Open

[serve] Refresh GCS node-info cache off the control loop (async)#64510
johntaylor-cell wants to merge 2 commits into
ray-project:masterfrom
johntaylor-cell:serve-async-node-info

Conversation

@johntaylor-cell

Copy link
Copy Markdown
Contributor

At high replica counts with direct ingress, the controller's per-loop GCS node-info refresh (ClusterNodeInfoCache.update -> get_all_node_info / get_all_resource_usage) is a synchronous RPC on the event loop. When the query exceeds its deadline during cluster churn (~12K+ nodes/replicas) the blocking call freezes the control loop for the whole RPC, the cache goes stale, and direct-ingress / HAProxy backends empty out.

Add RAY_SERVE_ASYNC_NODE_INFO (default off): refactor update() into a pure _compute_snapshot() (no self-mutation, safe in a thread) + _apply_snapshot() (atomic assignment on the event-loop thread). When the flag is on, a background _node_info_refresh_loop runs _compute_snapshot via run_in_executor -- the GCS calls release the GIL (with nogil) so the control loop keeps running while a slow reply is in flight, and reads always see the last complete snapshot. One refresh in flight at a time; the synchronous per-step update() is gated off when async is on.

Behavior is unchanged with the flag off: update() still computes and applies the snapshot synchronously (same result as before). At high N it is safe to raise RAY_GCS_RPC_TIMEOUT_S once async is on, since a longer query no longer blocks the loop.

@johntaylor-cell johntaylor-cell requested a review from a team as a code owner July 2, 2026 15:59

@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 introduces an asynchronous mechanism to refresh the cluster node-info cache off the main control loop, preventing slow GCS queries from blocking the controller. The changes include adding a non-blocking refresh_async method to ClusterNodeInfoCache and running a background refresh loop in the controller when RAY_SERVE_ASYNC_NODE_INFO is enabled. The feedback recommends using run_background_task instead of asyncio.ensure_future to avoid garbage collection of the background task, utilizing the get_env_float_positive helper for environment variable parsing, and adding a type hint to the alive_id_set parameter.

Comment thread python/ray/serve/_private/controller.py Outdated
Comment thread python/ray/serve/_private/constants.py Outdated
Comment thread python/ray/serve/_private/cluster_node_info_cache.py
@johntaylor-cell johntaylor-cell force-pushed the serve-async-node-info branch 2 times, most recently from 3e96a8d to dcb3ce9 Compare July 2, 2026 17:17
At high replica counts with direct ingress, the controller's per-loop GCS
node-info refresh (ClusterNodeInfoCache.update -> get_all_node_info /
get_all_resource_usage) is a synchronous RPC on the event loop. When the query
exceeds its deadline during cluster churn (~12K+ nodes/replicas) the blocking
call freezes the control loop for the whole RPC, the cache goes stale, and
direct-ingress / HAProxy backends empty out.

Add RAY_SERVE_ASYNC_NODE_INFO (default off): refactor update() into a pure
_compute_snapshot() (no self-mutation, safe in a thread) + _apply_snapshot()
(atomic assignment on the event-loop thread). When the flag is on, a background
_node_info_refresh_loop runs _compute_snapshot via run_in_executor -- the GCS
calls release the GIL (with nogil) so the control loop keeps running while a slow
reply is in flight, and reads always see the last complete snapshot. One refresh
in flight at a time; the synchronous per-step update() is gated off when async is
on.

Behavior is unchanged with the flag off: update() still computes and applies the
snapshot synchronously (same result as before). At high N it is safe to raise
RAY_GCS_RPC_TIMEOUT_S once async is on, since a longer query no longer blocks the
loop.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: john.taylor <john.taylor@anyscale.com>
@johntaylor-cell johntaylor-cell force-pushed the serve-async-node-info branch from dcb3ce9 to 2f8d7fb Compare July 2, 2026 17:19
@johntaylor-cell johntaylor-cell added the go add ONLY when ready to merge, run all tests label Jul 2, 2026
@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Jul 2, 2026
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: john.taylor <john.taylor@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests performance serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant