From 4ec9aba69fb161433d0287a51dd5390ff223f5a2 Mon Sep 17 00:00:00 2001 From: Josh Karpel Date: Tue, 11 Jun 2024 11:45:28 -0500 Subject: [PATCH 1/4] optimize DeploymentStateManager.get_deployment_statuses Signed-off-by: Josh Karpel --- python/ray/serve/_private/deployment_state.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/python/ray/serve/_private/deployment_state.py b/python/ray/serve/_private/deployment_state.py index b9bb89c1f735..ebc2567b5920 100644 --- a/python/ray/serve/_private/deployment_state.py +++ b/python/ray/serve/_private/deployment_state.py @@ -2564,13 +2564,15 @@ 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 + if ids is None: + return [ + state.curr_status_info for state in self._deployment_states.values() + ] + else: + states = (self._deployment_states.get(id) for id in ids) + return [state.curr_status_info for state in states if state] def get_alive_replica_actor_ids(self) -> Set[str]: alive_replica_actor_ids = set() From 2c28b5b216fe24c29862d2acaa76c9c862a775de Mon Sep 17 00:00:00 2001 From: Josh Karpel Date: Tue, 11 Jun 2024 13:43:49 -0500 Subject: [PATCH 2/4] call only once Signed-off-by: Josh Karpel --- python/ray/serve/_private/application_state.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/python/ray/serve/_private/application_state.py b/python/ray/serve/_private/application_state.py index 8a77bdfeaf8a..8f8917e0afee 100644 --- a/python/ray/serve/_private/application_state.py +++ b/python/ray/serve/_private/application_state.py @@ -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." From cf9bd6d43fc0fd87358faa7b3bba94ea137e0a82 Mon Sep 17 00:00:00 2001 From: Josh Karpel Date: Tue, 18 Jun 2024 18:48:29 -0500 Subject: [PATCH 3/4] comments/docstring Signed-off-by: Josh Karpel --- python/ray/serve/_private/deployment_state.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/ray/serve/_private/deployment_state.py b/python/ray/serve/_private/deployment_state.py index ebc2567b5920..7cefa7f8c87d 100644 --- a/python/ray/serve/_private/deployment_state.py +++ b/python/ray/serve/_private/deployment_state.py @@ -2566,7 +2566,13 @@ def get_deployment_details(self, id: DeploymentID) -> Optional[DeploymentDetails def get_deployment_statuses( self, ids: Optional[List[DeploymentID]] = None ) -> List[DeploymentStatusInfo]: + """ + Return the statuses of the deployments with the given `ids`. + If `ids` is `None`, returns the status of all deployments. + """ if ids is None: + # 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() ] From 8a16047e80812640dbca8fa531140f0768137bbe Mon Sep 17 00:00:00 2001 From: Josh Karpel Date: Wed, 19 Jun 2024 17:20:09 -0500 Subject: [PATCH 4/4] just one loop Signed-off-by: Josh Karpel --- python/ray/serve/_private/deployment_state.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/ray/serve/_private/deployment_state.py b/python/ray/serve/_private/deployment_state.py index 7cefa7f8c87d..a9d543494019 100644 --- a/python/ray/serve/_private/deployment_state.py +++ b/python/ray/serve/_private/deployment_state.py @@ -2577,8 +2577,12 @@ def get_deployment_statuses( state.curr_status_info for state in self._deployment_states.values() ] else: - states = (self._deployment_states.get(id) for id in ids) - return [state.curr_status_info for state in states if state] + 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()