Skip to main content
. 2024 Feb 19;24(4):1346. doi: 10.3390/s24041346
Algorithm 1 Latency-based Horizontal Pod Autoscaling with Custom Metrics API
Require:Ltarget: Target latency value
  • 1:

    ActivePods: Set of currently active pods

  • 2:

    MinPods: Minimum number of pods

  • 3:

    ScalingThreshold: Threshold for scaling (e.g., percentage increase in latency)

  • 4:

    CustomMetrics: Custom Metrics API for collecting and measuring latency values

  • 5:

     

  • 6:

    Initialize Custom Metrics API: CustomMetrics.initialize()

  • 7:

    MaxPods = None

  • 8:

    while True:

  • 9:

           L={}

  • 10:

         for pod in ActivePods:

  • 11:

           Li=getThresholdLatencyValue(pod)

  • 12:

           L.append(Li)

  • 13:

          end for

  • 14:

          total Latency=(L)

  • 15:

          averageLatency=total LatencyActivePods.length

  • 16:

          if MaxPods is None:

  • 17:

             MaxPods = determineMaxPods()

  • 18:

          latencyChange=(averageLatencyLtarget)Ltarget×100

  • 19:

          call AggregateLatenciesAcrossNodes()

  • 20:

          call CalculateSeparateLatencyThresholdsForEachNodeOrPod()

  • 21:

          call TakeIntoAccountDifferencesInCapabilitiesAcrossNodes()

  • 22:

          if latencyChange>ScalingThreshold and len(ActivePods) < MaxPods:

  • 23:

             P=ActivePods.length×latencyChangeScalingThreshold

  • 24:

             P=min(P,MaxPodsActivePods.length)

  • 25:

          elif latencyChange<ScalingThreshold and len(ActivePods) > MinPods:

  • 26:

             P=ActivePods.length×latencyChangeScalingThreshold

  • 27:

             P=min(P,ActivePods.lengthMinPods)

  • 28:

          else:

  • 29:

             P=0

  • 30:

          end if

  • 31:

          if P>0:

  • 32:

             call ScaleUp(P)

  • 33:

          elif P<0:

  • 34:

             call ScaleDown(P)

  • 35:

          end if

  • 36:

          call wait(τ)