THINK FIRST·CODE LATER

← All labs

Kubernetes Horizontal Pod Autoscaler

Problem

Input: replicas min max target podCapacity, then the load (requests/s) at each step.

At each step: utilization = load / (replicas × podCapacity). If utilization > 1, the step is overloaded. Compute ratio = utilization / target; if |ratio − 1| > 0.1, desired = ⌈replicas × ratio⌉, otherwise desired = replicas; clamp to [min, max]. The desired count becomes the replica count of the next step.

Print step 3: load 300, replicas 3, utilization 100% -> desired 5 (utilization rounded to an integer percent, with OVERLOADED before -> when > 100 %), and at the end Overloaded steps: k, pod-steps used: s (sum of replicas over all steps).

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os12-2-data-1.txt

2 1 10 0.6 100
80 150 300 450 450 200 100 60
What your program must print for os12-2-data-1.txt
step 1: load 80, replicas 2, utilization 40% -> desired 2
step 2: load 150, replicas 2, utilization 75% -> desired 3
step 3: load 300, replicas 3, utilization 100% -> desired 5
step 4: load 450, replicas 5, utilization 90% -> desired 8
step 5: load 450, replicas 8, utilization 56% -> desired 8
step 6: load 200, replicas 8, utilization 25% -> desired 4
step 7: load 100, replicas 4, utilization 25% -> desired 2
step 8: load 60, replicas 2, utilization 30% -> desired 1
Overloaded steps: 0, pod-steps used: 34

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os12-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os12-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.