Spot VMs for cost savings in Azure - Time & Space Complexity
We want to understand how the time to deploy and manage Spot VMs changes as we increase the number of VMs.
How does adding more Spot VMs affect the number of operations and time needed?
Analyze the time complexity of creating multiple Spot VMs in Azure.
// Create multiple Spot VMs
for (int i = 0; i < vmCount; i++) {
var vm = new VirtualMachine()
.WithSpotPriority(true)
.WithEvictionPolicy(VirtualMachineEvictionPolicy.Deallocate)
.Create();
}
This sequence creates a number of Spot VMs, each with a spot priority and eviction policy set.
Look at what repeats as we add more VMs.
- Primary operation: Creating a single Spot VM with specific settings.
- How many times: Once per VM, so vmCount times.
Each VM creation is a separate operation, so more VMs mean more operations.
| Input Size (vmCount) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 VM creation calls |
| 100 | 100 VM creation calls |
| 1000 | 1000 VM creation calls |
Pattern observation: The number of operations grows directly with the number of VMs.
Time Complexity: O(n)
This means the time to create Spot VMs grows linearly as you add more VMs.
[X] Wrong: "Creating multiple Spot VMs happens all at once, so time stays the same no matter how many VMs."
[OK] Correct: Each VM creation is a separate call and takes time, so more VMs mean more total time.
Understanding how operations scale with input size helps you design efficient cloud deployments and explain your reasoning clearly.
What if we used a batch API to create multiple Spot VMs at once? How would the time complexity change?