Simulate the HPA's core algorithm for a CPU target. Each step:
load[t] / (replicas × request_m) × 100 (load is total millicores in use).|utilisation / target − 1| ≤ tolerance, the recommendation is the current replica count.
Otherwise it is ceil(replicas × utilisation / target).[min_replicas, max_replicas].window steps (including this one);
the new replica count is the maximum of them when that is below the current count. Scaling up
uses this step's recommendation directly.Return the replica count after each step.
Implement simulate_hpa. Input: replicas: int, load: list[int], request_m: int, target: int, tolerance: float, min_replicas: int, max_replicas: int, window: int. Returns: list[int].
900m on 2 pods is 90% → 4 pods. Low load recommends 2 pods, applied once the last three recommendations are all ≤ 2.
import math
def simulate_hpa(replicas, load, request_m, target, tolerance, min_replicas, max_replicas, window):
out = []
for l in load:
replicas = math.ceil(l / request_m)
out.append(replicas)
return out
Run executes the public tests. Submit grades against public and hidden tests.
Simulate the HPA's core algorithm for a CPU target. Each step:
load[t] / (replicas × request_m) × 100 (load is total millicores in use).|utilisation / target − 1| ≤ tolerance, the recommendation is the current replica count.
Otherwise it is ceil(replicas × utilisation / target).[min_replicas, max_replicas].window steps (including this one);
the new replica count is the maximum of them when that is below the current count. Scaling up
uses this step's recommendation directly.Return the replica count after each step.
Implement simulate_hpa. Input: replicas: int, load: list[int], request_m: int, target: int, tolerance: float, min_replicas: int, max_replicas: int, window: int. Returns: list[int].
900m on 2 pods is 90% → 4 pods. Low load recommends 2 pods, applied once the last three recommendations are all ≤ 2.
import math
def simulate_hpa(replicas, load, request_m, target, tolerance, min_replicas, max_replicas, window):
out = []
for l in load:
replicas = math.ceil(l / request_m)
out.append(replicas)
return out
Run executes the public tests. Submit grades against public and hidden tests.