Repository navigation
[serve] Gracefully drain gang replicas under migration, rollouts, downscaling, and deletion - #67172
Conversation
Signed-off-by: Jeffrey Wang <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request modifies the graceful shutdown behavior for gang deployments in Ray Serve, ensuring that all gang members are allowed to drain or reach their shutdown deadlines before any of them are killed. It introduces a kill_actor parameter to check_stopped to poll shutdown status without terminating the actor, along with a check_ready_to_stop helper, and updates migration and stopping logic to handle partly started gangs. The review feedback suggests caching the result of check_ready_to_stop to prevent redundant GCS lookups (ray.get_actor) across controller ticks, which is a valuable optimization to reduce overhead.
| def check_ready_to_stop(self) -> bool: | ||
| """Whether graceful shutdown completed or its deadline expired, without killing.""" | ||
| return ( | ||
| self._actor.check_stopped(kill_actor=False) | ||
| or time.time() >= self._shutdown_deadline | ||
| ) |
There was a problem hiding this comment.
In a gang deployment, check_ready_to_stop() is called repeatedly in every controller tick for all stopping gang members until the entire gang is ready to be stopped. Since self._actor.check_stopped(kill_actor=False) performs GCS lookups (ray.get_actor), calling it repeatedly for replicas that have already finished draining can introduce unnecessary overhead and GCS load.
We can cache the ready status on the replica once it evaluates to True to avoid redundant GCS lookups and polling in subsequent ticks.
| def check_ready_to_stop(self) -> bool: | |
| """Whether graceful shutdown completed or its deadline expired, without killing.""" | |
| return ( | |
| self._actor.check_stopped(kill_actor=False) | |
| or time.time() >= self._shutdown_deadline | |
| ) | |
| def check_ready_to_stop(self) -> bool: | |
| """Whether graceful shutdown completed or its deadline expired, without killing.""" | |
| if not getattr(self, "_ready_to_stop", False): | |
| self._ready_to_stop = ( | |
| self._actor.check_stopped(kill_actor=False) | |
| or time.time() >= self._shutdown_deadline | |
| ) | |
| return self._ready_to_stop |
| ] | ||
| ) | ||
|
|
||
| partly_started_gang_members: Set[ReplicaID] = set() |
There was a problem hiding this comment.
Notes for reviewers
If we dismiss partly_started_gang_members, for example:
- A enters PENDING_MIGRATION, waiting for a replacement.
- B enters STOPPING immediately.
- The shutdown barrier only considers STOPPING replicas, so it can kill B once B drains, while A is still serving.
That violates “every gang member drains before any actor is killed.” This block puts both replicas into STOPPING, and the barrier waits for both to finish draining or reach their deadlines before killing their actors together.
| def test_gang_pg_removed_only_after_last_member_stops( | ||
| self, mock_deployment_state_manager | ||
| @pytest.mark.parametrize("operation", ["rollout", "surge", "downscale", "delete"]) | ||
| def test_graceful_shutdown_waits_for_every_gang_member( |
There was a problem hiding this comment.
This test still preserves the following assertions from test_gang_pg_removed_only_after_last_member_stops and extends to cover rollout, surge, downscale, and deletion:
- No PG removal after the first member drains
- Exactly one removal after the last drains.
|
|
||
| def test_actor_uninitialized_before_recover(mock_deployment_state_manager): | ||
| @pytest.mark.parametrize("gang_size", [None, 2]) | ||
| def test_actor_uninitialized_before_recover(mock_deployment_state_manager, gang_size): |
There was a problem hiding this comment.
Adds coverage for failed recovery without gang metadata.
|
|
… test Signed-off-by: Jeffrey Wang <[email protected]>
…ination Signed-off-by: Jeffrey Wang <[email protected]>
|
|
Re 1: Agreed for the draining gang's own replacement, but the gate is deployment-wide, so a different gang that already died and freed its PG also can't be replaced until this drain ends. Re 2: The fix isn't applied at |
Signed-off-by: Jeffrey Wang <[email protected]>
Makes sense, I'd follow up this in a separate PR as this is an existing limitation + to keep this PR targeted.
Fixed in 47da5e5. |
Description
Gracefully drain gang replicas independently, then kill all members in one controller tick after completion or timeout.
Fixes the gang request-loss issue explicitly excluded from #67165.
Approach
Each replica runs the existing graceful shutdown independently. A controller barrier waits for every stopping gang member to finish or time out, then kills them in the same tick.
Validation
test_gang_surge_rolling_update_and_rollbackfails before the fix.Related issues
Additional information