Autoscale Utilization Policy
EasySimulation · Amazon
An autoscaler manages a fleet that starts with instances running instances. average_util[i] is the fleet's average CPU utilization (a percentage) at second i. Scan the readings from left to right, starting at i = 0:
- If
average_util[i] < 25andinstances > 1: halve the fleet, rounding up (instances = ceil(instances / 2)). Then the autoscaler cools down: the next 10 readings are ignored, and the next reading considered isi + 11. - Otherwise, if
average_util[i] > 60and doubling would not exceed2 * 10^8(that is,2 * instances <= 2 * 10^8): double the fleet, then cool down in the same way (next reading considered isi + 11). - Otherwise, take no action and move on to reading
i + 1.
Readings of exactly 25 or exactly 60 never trigger an action, and a reading that would trigger an action but is blocked by the rule's extra condition (only one instance, or the cap) is treated as no action, with no cooldown. Return the number of instances after the scan ends.
Example 1
- Input:
- instances = 3, average_util = [80, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 30, 5, 70]
- Output:
- 3
- Explanation
- Reading 0 is 80, so the fleet doubles to 6 and readings 1 through 10 are skipped. Reading 11 (30) does nothing. Reading 12 (5) halves 6 to 3 and skips the rest, including the final 70.
Example 2
- Input:
- instances = 1, average_util = [5, 61, 20]
- Output:
- 2
- Explanation
- Reading 0 is low, but a single instance cannot be halved, so nothing happens and there is no cooldown. Reading 1 (61) doubles the fleet to 2, and the cooldown skips the last reading.
Example 3
- Input:
- instances = 150000000, average_util = [99]
- Output:
- 150000000
- Explanation
- Doubling would give 3 * 108, which is over the 2 * 108 cap, so the fleet stays the same.
Constraints
1 <= instances <= 2 * 10^80 <= average_util.length <= 10^50 <= average_util[i] <= 100