python/ray/serve/deployment_state.py
def rank_replicas_for_stopping(
    all_available_replicas: List["DeploymentReplica"],
) -> List["DeploymentReplica"]:
    """Prioritize replicas that have fewest copies on a node.

    This algorithm helps to scale down more intelligently because it can
    relinquish node faster. Note that this algorithm doesn't consider other
    deployments or other actors on the same node. See more at
    https://github.com/ray-project/ray/issues/20599.
    """
    # Categorize replicas to node they belong to.
    node_to_replicas = defaultdict(list)
    for replica in all_available_replicas:
        node_to_replicas[replica.actor_node_id].append(replica)

    # Replicas not in running state might have _node_id = None.
    # We will prioritize those first.
    node_to_replicas.setdefault(None, [])
    return list(
        itertools.chain.from_iterable(
            [
                node_to_replicas.pop(None),
            ]
            + sorted(node_to_replicas.values(), key=lambda lst: len(lst))
        )
    )
Prioritize replicas that have fewest copies on a node.

    This algorithm helps to scale down more intelligently because it can
    relinquish node faster. Note that this algorithm doesn't consider other
    deployments or other actors on the same node. See more at
    https://github.com/ray-project/ray/issues/20599.
    
Prioritize replicas that have fewest copies on a node.
This algorithm helps to scale down more intelligently because it can
relinquish node faster. Note that this algorithm doesn't consider other
deployments or other actors on the same node.
Prioritize replicas that have fewest copies on a node . This algorithm helps to scale down more intelligently because it can relinquish node faster . Note that this algorithm doesn ' t consider other deployments or other actors on the same node .
def rank_replicas_for_stopping(
    all_available_replicas: List["DeploymentReplica"],
) -> List["DeploymentReplica"]:
    node_to_replicas = defaultdict(list)
    for replica in all_available_replicas:
        node_to_replicas[replica.actor_node_id].append(replica)
    node_to_replicas.setdefault(None, [])
    return list(
        itertools.chain.from_iterable(
            [
                node_to_replicas.pop(None),
            ]
            + sorted(node_to_replicas.values(), key=lambda lst: len(lst))
        )
    )
def rank_replicas_for_stopping ( all_available_replicas : List [ "DeploymentReplica" ] , ) -> List [ "DeploymentReplica" ] : node_to_replicas = defaultdict ( list ) for replica in all_available_replicas : node_to_replicas [ replica . actor_node_id ] . append ( replica ) node_to_replicas . setdefault ( None , [ ] ) return list ( itertools . chain . from_iterable ( [ node_to_replicas . pop ( None ) , ] + sorted ( node_to_replicas . values ( ) , key = lambda lst : len ( lst ) ) ) )
Prioritize replicas that have fewest copies on a node.
Prioritize replicas that have fewest copies on a node .
"""Prioritize replicas that have fewest copies on a node.

    This algorithm helps to scale down more intelligently because it can
    relinquish node faster. Note that this algorithm doesn't consider other
    deployments or other actors on the same node. See more at
    https://github.com/ray-project/ray/issues/20599.
    """ # Categorize replicas to node they belong to. # Replicas not in running state might have _node_id = None. # We will prioritize those first.
all_available_replicas
List["DeploymentReplica"]