Repository navigation
feat: get draining nodes in Ray Serve controller - #65502
abrarsheikh merged 5 commits into
Conversation
Signed-off-by: Le Duc Manh <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces synchronous support for retrieving draining nodes from the GCS. It exposes GetDrainingNodes in the C++ GCS client, binds it via Cython to Python's GcsClient, and integrates it into the Ray Serve DefaultClusterNodeInfoCache to keep track of draining nodes during cache updates. A unit test has also been added to verify this behavior. There are no review comments, so I have no feedback to provide.
| super().__init__(gcs_client) | ||
| self._cached_draining_nodes: Dict[str, int] = dict() | ||
|
|
||
| def update(self): |
There was a problem hiding this comment.
Can this go in the base ClusterNodeInfoCache.update instead? Every implementation needs the same fetch.
| } | ||
| return | ||
|
|
||
| self._cached_draining_nodes = { |
There was a problem hiding this comment.
We should handle the case where the fetched deadline is 0 so that these replicas don't get stopped before their replacements come up. 0 means no deadline (_private/state.py:978) but _partition_groups_to_stop reads deadlines as absolute epoch ms (deployment_state.py:5492), so 0 is treated as already expired and skips the migrate first path. Substituting now + <default draining timeout> before caching should work.
There was a problem hiding this comment.
From this comment #65502 (review)
For simplicity I intent to use 2**63 - 1
| == cluster_node_info_cache.get_active_node_ids() | ||
| ) | ||
|
|
||
| # Keep a lease on the worker so the raylet remains alive while draining. |
There was a problem hiding this comment.
We should split this into its own test_get_draining_nodes so the alive node assertions after remove_node don't run against a drained worker, and so the two features fail independently.
| worker_node_id: draining_deadline_ms | ||
| } | ||
|
|
||
| wait_for_condition(cache_has_draining_worker) |
There was a problem hiding this comment.
Once the deadline 0 substitution is in, we should cover it here: drain with deadline 0, assert the cached deadline is > 0, then assert it doesn't change across several update() calls. A cache that recomputes now + default on each tick would pass a single check and keep pushing the forced stop out forever, so the repeated read is what pins the fix.
| } | ||
|
|
||
| wait_for_condition(cache_has_draining_worker) | ||
| assert cluster_node_info_cache.get_active_node_ids() == {head_node_id} |
There was a problem hiding this comment.
The two new branches are the alive node filter and the except path, and neither is exercised here. A stubbed gcs_client that raises, plus one reporting a node that is no longer alive, would cover both without a real cluster.
Signed-off-by: Le Duc Manh <[email protected]>
Signed-off-by: Le Duc Manh <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit b7a1778. Configure here.
Signed-off-by: Le Duc Manh <[email protected]>
|
Great work! |
…eregistration window ends (#65698) ## Description What happens today when a direct-ingress replica behind HAProxy (`RAY_SERVE_ENABLE_HA_PROXY=1`) shuts down, in sequence: 1. A replica starts draining (scale-down, upgrade, or its node is being removed). 2. Every node's HAProxy receives the updated backend list and reloads. 3. A reload starts a **new** HAProxy process. The **old** process keeps running until its connections finish (bounded by `hard-stop-after`, minutes) — and it still routes with the **old** backend list. It cannot be corrected: config reloads and runtime commands only reach the new process. 4. So a stale worker can keep sending brand-new requests to the draining replica for minutes. 5. Today the replica accepts them: it keeps serving for as long as requests arrive, not just for the deregistration window (`RAY_SERVE_DIRECT_INGRESS_MIN_DRAINING_PERIOD_S`, default 30s). 6. The replica/node is only guaranteed to live through that window. When the node then goes away (e.g. spot interruption), the late-admitted requests are cut mid-flight — the client sees an error nothing can safely retry. We measured ~40 such failures per spot-interruption event in a staging fleet. **The fix** — behind HAProxy, drain in two phases: 1. Stay fully reachable for the deregistration window, exactly as today. 2. Then close the direct-ingress HTTP listener and wait for in-flight requests. A late request from a stale worker is now refused at connect time instead of admitted. HAProxy retries refused connections on another replica (`retry-on conn-failure` + `option redispatch`), so the client sees no error. **Without HAProxy nothing changes**: there is no retrying proxy in front, a refusal would reach the client, so that path keeps the existing drain. ## Related issues N/A (follow-up to the HAProxy stability series, most recently #63996). ## Additional information - Adds a `Replica._is_direct_ingress` property (mirrors the one on `ReplicaMetricsManager`), used to pick the drain path. - Only the HTTP listener closes early; direct-ingress gRPC keeps the existing behavior until the post-drain quiesce. Candidate follow-up. - Gated on `RAY_SERVE_ENABLE_HA_PROXY` because the early refusal is only safe with a retrying proxy in front. - A live-cluster reproduction with keep-alive connections against a stale HAProxy worker is a planned follow-up. ### Not a duplicate Checked open PRs before and after opening this one (`gh pr list --search "haproxy"`, `--search "drain replica graceful shutdown"`): no open PR or issue touches replica drain or direct-ingress listener shutdown. The nearest neighbours are unrelated (#65502 draining-node accessor on the controller, #65542 lazy jinja2 import). ### Tests run ``` pytest python/ray/serve/tests/unit/test_replica_quiesce.py -v ``` 12 passed — the 7 pre-existing tests plus 5 new ones covering: drain-path selection with and without HAProxy, phase ordering, the deregistration window being served in full before the listener closes, the minimum period not being applied twice, and the no-HTTP-server case. ``` pre-commit run --files python/ray/serve/_private/replica.py python/ray/serve/tests/unit/test_replica_quiesce.py ``` All hooks passed, including `mypy (ray serve)` and `pyrefly (ray serve)`. ### AI assistance This change was developed with AI assistance (Claude Code). A human author reviewed every changed line and ran the tests above locally before requesting review. --------- Signed-off-by: harshit-anyscale <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
MortalHappiness
left a comment
There was a problem hiding this comment.
Stamp for Ray core changes.
…eregistration window ends (ray-project#65698) ## Description What happens today when a direct-ingress replica behind HAProxy (`RAY_SERVE_ENABLE_HA_PROXY=1`) shuts down, in sequence: 1. A replica starts draining (scale-down, upgrade, or its node is being removed). 2. Every node's HAProxy receives the updated backend list and reloads. 3. A reload starts a **new** HAProxy process. The **old** process keeps running until its connections finish (bounded by `hard-stop-after`, minutes) — and it still routes with the **old** backend list. It cannot be corrected: config reloads and runtime commands only reach the new process. 4. So a stale worker can keep sending brand-new requests to the draining replica for minutes. 5. Today the replica accepts them: it keeps serving for as long as requests arrive, not just for the deregistration window (`RAY_SERVE_DIRECT_INGRESS_MIN_DRAINING_PERIOD_S`, default 30s). 6. The replica/node is only guaranteed to live through that window. When the node then goes away (e.g. spot interruption), the late-admitted requests are cut mid-flight — the client sees an error nothing can safely retry. We measured ~40 such failures per spot-interruption event in a staging fleet. **The fix** — behind HAProxy, drain in two phases: 1. Stay fully reachable for the deregistration window, exactly as today. 2. Then close the direct-ingress HTTP listener and wait for in-flight requests. A late request from a stale worker is now refused at connect time instead of admitted. HAProxy retries refused connections on another replica (`retry-on conn-failure` + `option redispatch`), so the client sees no error. **Without HAProxy nothing changes**: there is no retrying proxy in front, a refusal would reach the client, so that path keeps the existing drain. ## Related issues N/A (follow-up to the HAProxy stability series, most recently ray-project#63996). ## Additional information - Adds a `Replica._is_direct_ingress` property (mirrors the one on `ReplicaMetricsManager`), used to pick the drain path. - Only the HTTP listener closes early; direct-ingress gRPC keeps the existing behavior until the post-drain quiesce. Candidate follow-up. - Gated on `RAY_SERVE_ENABLE_HA_PROXY` because the early refusal is only safe with a retrying proxy in front. - A live-cluster reproduction with keep-alive connections against a stale HAProxy worker is a planned follow-up. ### Not a duplicate Checked open PRs before and after opening this one (`gh pr list --search "haproxy"`, `--search "drain replica graceful shutdown"`): no open PR or issue touches replica drain or direct-ingress listener shutdown. The nearest neighbours are unrelated (ray-project#65502 draining-node accessor on the controller, ray-project#65542 lazy jinja2 import). ### Tests run ``` pytest python/ray/serve/tests/unit/test_replica_quiesce.py -v ``` 12 passed — the 7 pre-existing tests plus 5 new ones covering: drain-path selection with and without HAProxy, phase ordering, the deregistration window being served in full before the listener closes, the minimum period not being applied twice, and the no-HTTP-server case. ``` pre-commit run --files python/ray/serve/_private/replica.py python/ray/serve/tests/unit/test_replica_quiesce.py ``` All hooks passed, including `mypy (ray serve)` and `pyrefly (ray serve)`. ### AI assistance This change was developed with AI assistance (Claude Code). A human author reviewed every changed line and ran the tests above locally before requesting review. --------- Signed-off-by: harshit-anyscale <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
…eregistration window ends (ray-project#65698) ## Description What happens today when a direct-ingress replica behind HAProxy (`RAY_SERVE_ENABLE_HA_PROXY=1`) shuts down, in sequence: 1. A replica starts draining (scale-down, upgrade, or its node is being removed). 2. Every node's HAProxy receives the updated backend list and reloads. 3. A reload starts a **new** HAProxy process. The **old** process keeps running until its connections finish (bounded by `hard-stop-after`, minutes) — and it still routes with the **old** backend list. It cannot be corrected: config reloads and runtime commands only reach the new process. 4. So a stale worker can keep sending brand-new requests to the draining replica for minutes. 5. Today the replica accepts them: it keeps serving for as long as requests arrive, not just for the deregistration window (`RAY_SERVE_DIRECT_INGRESS_MIN_DRAINING_PERIOD_S`, default 30s). 6. The replica/node is only guaranteed to live through that window. When the node then goes away (e.g. spot interruption), the late-admitted requests are cut mid-flight — the client sees an error nothing can safely retry. We measured ~40 such failures per spot-interruption event in a staging fleet. **The fix** — behind HAProxy, drain in two phases: 1. Stay fully reachable for the deregistration window, exactly as today. 2. Then close the direct-ingress HTTP listener and wait for in-flight requests. A late request from a stale worker is now refused at connect time instead of admitted. HAProxy retries refused connections on another replica (`retry-on conn-failure` + `option redispatch`), so the client sees no error. **Without HAProxy nothing changes**: there is no retrying proxy in front, a refusal would reach the client, so that path keeps the existing drain. ## Related issues N/A (follow-up to the HAProxy stability series, most recently ray-project#63996). ## Additional information - Adds a `Replica._is_direct_ingress` property (mirrors the one on `ReplicaMetricsManager`), used to pick the drain path. - Only the HTTP listener closes early; direct-ingress gRPC keeps the existing behavior until the post-drain quiesce. Candidate follow-up. - Gated on `RAY_SERVE_ENABLE_HA_PROXY` because the early refusal is only safe with a retrying proxy in front. - A live-cluster reproduction with keep-alive connections against a stale HAProxy worker is a planned follow-up. ### Not a duplicate Checked open PRs before and after opening this one (`gh pr list --search "haproxy"`, `--search "drain replica graceful shutdown"`): no open PR or issue touches replica drain or direct-ingress listener shutdown. The nearest neighbours are unrelated (ray-project#65502 draining-node accessor on the controller, ray-project#65542 lazy jinja2 import). ### Tests run ``` pytest python/ray/serve/tests/unit/test_replica_quiesce.py -v ``` 12 passed — the 7 pre-existing tests plus 5 new ones covering: drain-path selection with and without HAProxy, phase ordering, the deregistration window being served in full before the listener closes, the minimum period not being applied twice, and the no-HTTP-server case. ``` pre-commit run --files python/ray/serve/_private/replica.py python/ray/serve/tests/unit/test_replica_quiesce.py ``` All hooks passed, including `mypy (ray serve)` and `pyrefly (ray serve)`. ### AI assistance This change was developed with AI assistance (Claude Code). A human author reviewed every changed line and ran the tests above locally before requesting review. --------- Signed-off-by: harshit-anyscale <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
## Description - Ray Serve doesn't perform replicas graceful shutdown during node preemption (in-flight requests will fail immediately) - [PR ray-project#64454](ray-project#64454) marks a Ray node as draining when `ray start --block` receives SIGTERM. This allows time for Controller to draining and graceful shutdown replicas running on the nodes. - There is already logic for draining and migrating replicas on draining nodes - However, the default Ray Serve controller node cache always returned an empty draining-node map. As a result, Serve’s existing proxy and replica draining logic could not observe nodes marked as draining in GCS. - This change allow the serve controller to query draining nodes from GCS to enable draining of running replicas during node preemption --------- Signed-off-by: Le Duc Manh <[email protected]>

Description
ray start --blockreceives SIGTERM. This allows time for Controller to draining and graceful shutdown replicas running on the nodes.