python/ray/serve/deployment_state.py
def _scale_deployment_replicas(self) -> bool:
        """Scale the given deployment to the number of replicas."""

        assert (
            self._target_replicas >= 0
        ), "Number of replicas must be greater than or equal to 0."

        replicas_stopped = self._stop_wrong_version_replicas()

        current_replicas = self._replicas.count(
            states=[ReplicaState.STARTING, ReplicaState.UPDATING, ReplicaState.RUNNING]
        )
        recovering_replicas = self._replicas.count(states=[ReplicaState.RECOVERING])

        delta_replicas = self._target_replicas - current_replicas - recovering_replicas
        if delta_replicas == 0:
            return False

        elif delta_replicas > 0:
            # Don't ever exceed self._target_replicas.
            stopping_replicas = self._replicas.count(
                states=[
                    ReplicaState.STOPPING,
                ]
            )
            to_add = max(delta_replicas - stopping_replicas, 0)
            if to_add > 0:
                logger.info(
                    f"Adding {to_add} replicas to deployment " f"'{self._name}'."
                )
            for _ in range(to_add):
                replica_name = ReplicaName(self._name, get_random_letters())
                new_deployment_replica = DeploymentReplica(
                    self._controller_name,
                    self._detached,
                    replica_name.replica_tag,
                    replica_name.deployment_tag,
                    self._target_version,
                    _override_controller_namespace=self._override_controller_namespace,
                )
                new_deployment_replica.start(self._target_info, self._target_version)

                self._replicas.add(ReplicaState.STARTING, new_deployment_replica)
                logger.debug(
                    "Adding STARTING to replica_tag: "
                    f"{replica_name}, deployment: {self._name}"
                )

        elif delta_replicas < 0:
            replicas_stopped = True
            to_remove = -delta_replicas
            logger.info(
                f"Removing {to_remove} replicas from deployment '{self._name}'."
            )
            replicas_to_stop = self._replicas.pop(
                states=[
                    ReplicaState.STARTING,
                    ReplicaState.UPDATING,
                    ReplicaState.RECOVERING,
                    ReplicaState.RUNNING,
                ],
                max_replicas=to_remove,
                ranking_function=rank_replicas_for_stopping,
            )

            for replica in replicas_to_stop:
                logger.debug(
                    f"Adding STOPPING to replica_tag: {replica}, "
                    f"deployment_name: {self._name}"
                )
                replica.stop()
                self._replicas.add(ReplicaState.STOPPING, replica)

        return replicas_stopped
Scale the given deployment to the number of replicas.
Scale the given deployment to the number of replicas.
Scale the given deployment to the number of replicas .
def _scale_deployment_replicas(self) -> bool:
        assert (
            self._target_replicas >= 0
        ), "Number of replicas must be greater than or equal to 0."
        replicas_stopped = self._stop_wrong_version_replicas()
        current_replicas = self._replicas.count(
            states=[ReplicaState.STARTING, ReplicaState.UPDATING, ReplicaState.RUNNING]
        )
        recovering_replicas = self._replicas.count(states=[ReplicaState.RECOVERING])
        delta_replicas = self._target_replicas - current_replicas - recovering_replicas
        if delta_replicas == 0:
            return False
        elif delta_replicas > 0:
            stopping_replicas = self._replicas.count(
                states=[
                    ReplicaState.STOPPING,
                ]
            )
            to_add = max(delta_replicas - stopping_replicas, 0)
            if to_add > 0:
                logger.info(
                    f"Adding {to_add} replicas to deployment " f"'{self._name}'."
                )
            for _ in range(to_add):
                replica_name = ReplicaName(self._name, get_random_letters())
                new_deployment_replica = DeploymentReplica(
                    self._controller_name,
                    self._detached,
                    replica_name.replica_tag,
                    replica_name.deployment_tag,
                    self._target_version,
                    _override_controller_namespace=self._override_controller_namespace,
                )
                new_deployment_replica.start(self._target_info, self._target_version)
                self._replicas.add(ReplicaState.STARTING, new_deployment_replica)
                logger.debug(
                    "Adding STARTING to replica_tag: "
                    f"{replica_name}, deployment: {self._name}"
                )
        elif delta_replicas < 0:
            replicas_stopped = True
            to_remove = -delta_replicas
            logger.info(
                f"Removing {to_remove} replicas from deployment '{self._name}'."
            )
            replicas_to_stop = self._replicas.pop(
                states=[
                    ReplicaState.STARTING,
                    ReplicaState.UPDATING,
                    ReplicaState.RECOVERING,
                    ReplicaState.RUNNING,
                ],
                max_replicas=to_remove,
                ranking_function=rank_replicas_for_stopping,
            )
            for replica in replicas_to_stop:
                logger.debug(
                    f"Adding STOPPING to replica_tag: {replica}, "
                    f"deployment_name: {self._name}"
                )
                replica.stop()
                self._replicas.add(ReplicaState.STOPPING, replica)
        return replicas_stopped
def _scale_deployment_replicas ( self ) -> bool : assert ( self . _target_replicas >= 0 ) , "Number of replicas must be greater than or equal to 0." replicas_stopped = self . _stop_wrong_version_replicas ( ) current_replicas = self . _replicas . count ( states = [ ReplicaState . STARTING , ReplicaState . UPDATING , ReplicaState . RUNNING ] ) recovering_replicas = self . _replicas . count ( states = [ ReplicaState . RECOVERING ] ) delta_replicas = self . _target_replicas - current_replicas - recovering_replicas if delta_replicas == 0 : return False elif delta_replicas > 0 : stopping_replicas = self . _replicas . count ( states = [ ReplicaState . STOPPING , ] ) to_add = max ( delta_replicas - stopping_replicas , 0 ) if to_add > 0 : logger . info ( f"Adding {to_add} replicas to deployment " f"'{self._name}'." ) for _ in range ( to_add ) : replica_name = ReplicaName ( self . _name , get_random_letters ( ) ) new_deployment_replica = DeploymentReplica ( self . _controller_name , self . _detached , replica_name . replica_tag , replica_name . deployment_tag , self . _target_version , _override_controller_namespace = self . _override_controller_namespace , ) new_deployment_replica . start ( self . _target_info , self . _target_version ) self . _replicas . add ( ReplicaState . STARTING , new_deployment_replica ) logger . debug ( "Adding STARTING to replica_tag: " f"{replica_name}, deployment: {self._name}" ) elif delta_replicas < 0 : replicas_stopped = True to_remove = - delta_replicas logger . info ( f"Removing {to_remove} replicas from deployment '{self._name}'." ) replicas_to_stop = self . _replicas . pop ( states = [ ReplicaState . STARTING , ReplicaState . UPDATING , ReplicaState . RECOVERING , ReplicaState . RUNNING , ] , max_replicas = to_remove , ranking_function = rank_replicas_for_stopping , ) for replica in replicas_to_stop : logger . debug ( f"Adding STOPPING to replica_tag: {replica}, " f"deployment_name: {self._name}" ) replica . stop ( ) self . _replicas . add ( ReplicaState . STOPPING , replica ) return replicas_stopped
Scale the given deployment to the number of replicas.
Scale the given deployment to the number of replicas .
"""Scale the given deployment to the number of replicas.""" # Don't ever exceed self._target_replicas.
self