Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serve] Optimize DeploymentStateManager.get_deployment_statuses #45872

7 changes: 3 additions & 4 deletions python/ray/serve/_private/application_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,12 @@ def _determine_app_status(self) -> Tuple[ApplicationStatus, str]:
# Get the lowest rank, i.e. highest priority, deployment status info object
# The deployment status info with highest priority determines the corresponding
# application status to set.
lowest_rank_status = min(
self.get_deployments_statuses(), key=lambda info: info.rank
)
deployment_statuses = self.get_deployments_statuses()
lowest_rank_status = min(deployment_statuses, key=lambda info: info.rank)
if lowest_rank_status.status == DeploymentStatus.UNHEALTHY:
unhealthy_deployment_names = [
s.name
for s in self.get_deployments_statuses()
for s in deployment_statuses
if s.status == DeploymentStatus.UNHEALTHY
]
status_msg = f"The deployments {unhealthy_deployment_names} are UNHEALTHY."
Expand Down
24 changes: 18 additions & 6 deletions python/ray/serve/_private/deployment_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2564,13 +2564,25 @@ def get_deployment_details(self, id: DeploymentID) -> Optional[DeploymentDetails
)

def get_deployment_statuses(
self, ids: List[DeploymentID] = None
self, ids: Optional[List[DeploymentID]] = None
) -> List[DeploymentStatusInfo]:
statuses = []
for id, state in self._deployment_states.items():
if not ids or id in ids:
statuses.append(state.curr_status_info)
return statuses
"""
Return the statuses of the deployments with the given `ids`.
If `ids` is `None`, returns the status of all deployments.
"""
if ids is None:
JoshKarpel marked this conversation as resolved.
Show resolved Hide resolved
# fast path for returning all deployments,
# avoids checking `if ids is None` in a loop
return [
state.curr_status_info for state in self._deployment_states.values()
]
else:
statuses = []
for id in ids:
state = self._deployment_states.get(id)
if state is not None:
statuses.append(state.curr_status_info)
return statuses

def get_alive_replica_actor_ids(self) -> Set[str]:
alive_replica_actor_ids = set()
Expand Down
Loading