python/ray/serve/controller.py
def autoscale(self) -> None:
        """Updates autoscaling deployments with calculated num_replicas."""
        for deployment_name, (
            deployment_info,
            route_prefix,
        ) in self.list_deployments_internal().items():
            deployment_config = deployment_info.deployment_config
            autoscaling_policy = deployment_info.autoscaling_policy

            if autoscaling_policy is None:
                continue

            replicas = self.deployment_state_manager._deployment_states[
                deployment_name
            ]._replicas
            running_replicas = replicas.get([ReplicaState.RUNNING])

            current_num_ongoing_requests = []
            for replica in running_replicas:
                replica_tag = replica.replica_tag
                num_ongoing_requests = self.autoscaling_metrics_store.window_average(
                    replica_tag,
                    time.time() - autoscaling_policy.config.look_back_period_s,
                )
                if num_ongoing_requests is not None:
                    current_num_ongoing_requests.append(num_ongoing_requests)

            if len(current_num_ongoing_requests) == 0:
                continue

            new_deployment_config = deployment_config.copy()

            decision_num_replicas = autoscaling_policy.get_decision_num_replicas(
                current_num_ongoing_requests=current_num_ongoing_requests,
                curr_target_num_replicas=deployment_config.num_replicas,
            )
            new_deployment_config.num_replicas = decision_num_replicas

            new_deployment_info = copy(deployment_info)
            new_deployment_info.deployment_config = new_deployment_config

            self.deployment_state_manager.deploy(deployment_name, new_deployment_info)
Updates autoscaling deployments with calculated num_replicas.
Updates autoscaling deployments with calculated num_replicas.
Updates autoscaling deployments with calculated num_replicas .
def autoscale(self) -> None:
        for deployment_name, (
            deployment_info,
            route_prefix,
        ) in self.list_deployments_internal().items():
            deployment_config = deployment_info.deployment_config
            autoscaling_policy = deployment_info.autoscaling_policy
            if autoscaling_policy is None:
                continue
            replicas = self.deployment_state_manager._deployment_states[
                deployment_name
            ]._replicas
            running_replicas = replicas.get([ReplicaState.RUNNING])
            current_num_ongoing_requests = []
            for replica in running_replicas:
                replica_tag = replica.replica_tag
                num_ongoing_requests = self.autoscaling_metrics_store.window_average(
                    replica_tag,
                    time.time() - autoscaling_policy.config.look_back_period_s,
                )
                if num_ongoing_requests is not None:
                    current_num_ongoing_requests.append(num_ongoing_requests)
            if len(current_num_ongoing_requests) == 0:
                continue
            new_deployment_config = deployment_config.copy()
            decision_num_replicas = autoscaling_policy.get_decision_num_replicas(
                current_num_ongoing_requests=current_num_ongoing_requests,
                curr_target_num_replicas=deployment_config.num_replicas,
            )
            new_deployment_config.num_replicas = decision_num_replicas
            new_deployment_info = copy(deployment_info)
            new_deployment_info.deployment_config = new_deployment_config
            self.deployment_state_manager.deploy(deployment_name, new_deployment_info)
def autoscale ( self ) -> None : for deployment_name , ( deployment_info , route_prefix , ) in self . list_deployments_internal ( ) . items ( ) : deployment_config = deployment_info . deployment_config autoscaling_policy = deployment_info . autoscaling_policy if autoscaling_policy is None : continue replicas = self . deployment_state_manager . _deployment_states [ deployment_name ] . _replicas running_replicas = replicas . get ( [ ReplicaState . RUNNING ] ) current_num_ongoing_requests = [ ] for replica in running_replicas : replica_tag = replica . replica_tag num_ongoing_requests = self . autoscaling_metrics_store . window_average ( replica_tag , time . time ( ) - autoscaling_policy . config . look_back_period_s , ) if num_ongoing_requests is not None : current_num_ongoing_requests . append ( num_ongoing_requests ) if len ( current_num_ongoing_requests ) == 0 : continue new_deployment_config = deployment_config . copy ( ) decision_num_replicas = autoscaling_policy . get_decision_num_replicas ( current_num_ongoing_requests = current_num_ongoing_requests , curr_target_num_replicas = deployment_config . num_replicas , ) new_deployment_config . num_replicas = decision_num_replicas new_deployment_info = copy ( deployment_info ) new_deployment_info . deployment_config = new_deployment_config self . deployment_state_manager . deploy ( deployment_name , new_deployment_info )
Updates autoscaling deployments with calculated num_replicas.
Updates autoscaling deployments with calculated num_replicas .
"""Updates autoscaling deployments with calculated num_replicas."""
self