code: def replica_queue_length_autoscaling_policy(
      curr_target_num_replicas: int,
      current_num_ongoing_requests: List[float],
      current_handle_queued_queries: float,
      config: Optional[AutoscalingConfig],
      capacity_adjusted_min_replicas: int,
      capacity_adjusted_max_replicas: int,
      policy_state: Dict[str, Any],
  ) -> int:
      """The default autoscaling policy based on basic thresholds for scaling.
      There is a minimum threshold for the average queue length in the cluster
      to scale up and a maximum threshold to scale down. Each period, a 'scale
      up' or 'scale down' decision is made. This decision must be made for a
      specified number of periods in a row before the number of replicas is
      actually scaled. See config options for more details.  Assumes
      `get_decision_num_replicas` is called once every CONTROL_LOOP_PERIOD_S
      seconds.
      """
      decision_counter = policy_state.get("decision_counter", 0)
      if len(current_num_ongoing_requests) == 0:
          # When 0 replicas and queries are queued, scale up the replicas
          if current_handle_queued_queries > 0:
              return max(
                  math.ceil(1 * config.get_upscale_smoothing_factor()),
                  curr_target_num_replicas,
              )
          return curr_target_num_replicas
  
      decision_num_replicas = curr_target_num_replicas
  
      desired_num_replicas = _calculate_desired_num_replicas(
          config,
          current_num_ongoing_requests,
          override_min_replicas=capacity_adjusted_min_replicas,
          override_max_replicas=capacity_adjusted_max_replicas,
      )
      # Scale up.
      if desired_num_replicas > curr_target_num_replicas:
          # If the previous decision was to scale down (the counter was
          # negative), we reset it and then increment it (set to 1).
          # Otherwise, just increment.
          if decision_counter < 0:
              decision_counter = 0
          decision_counter += 1
  
          # Only actually scale the replicas if we've made this decision for
          # 'scale_up_consecutive_periods' in a row.
          if decision_counter > int(
              config.upscale_delay_s / CONTROL_LOOP_PERIOD_S
          ):
              decision_counter = 0
              decision_num_replicas = desired_num_replicas
  
      # Scale down.
      elif desired_num_replicas < curr_target_num_replicas:
          # If the previous decision was to scale up (the counter was
          # positive), reset it to zero before decrementing.
          if decision_counter > 0:
              decision_counter = 0
          decision_counter -= 1
  
          # Only actually scale the replicas if we've made this decision for
          # 'scale_down_consecutive_periods' in a row.
          if decision_counter < -int(
              config.downscale_delay_s / CONTROL_LOOP_PERIOD_S
          ):
              decision_counter = 0
              decision_num_replicas = desired_num_replicas
  
      # Do nothing.
      else:
          decision_counter = 0
  
      policy_state["decision_counter"] = decision_counter
      return decision_num_replicas
  
file_path: ray/python/ray/serve/autoscaling_policy.py
imports: import logging
  import math
  from typing import Any, Dict, List, Optional
  from ray.serve._private.constants import CONTROL_LOOP_PERIOD_S, SERVE_LOGGER_NAME
  from ray.serve.config import AutoscalingConfig
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 2 for calling a global function with example usage: replica_queue_length_autoscaling_policy(curr_target_num_replicas, current_num_ongoing_requests, current_handle_queued_queries, config, capacity_adjusted_min_replicas, capacity_adjusted_max_replicas, policy_state) and returns: decision_num_replicas, curr_target_num_replicas, max