Azure Spot VMs for cost savings - Time & Space Complexity
We want to understand how the time to deploy and manage Azure Spot VMs changes as we increase the number of VMs.
Specifically, how does adding more Spot VMs affect the number of operations and time needed?
Analyze the time complexity of creating multiple Azure Spot VMs in a batch.
// Create multiple Spot VMs
for (int i = 0; i < vmCount; i++) {
var vm = new VirtualMachine()
.WithSpotPriority()
.WithEvictionPolicyDeallocate()
.Create();
}
This sequence creates each Spot VM one by one with eviction policy set.
Look at what repeats as we add more VMs.
- Primary operation: API call to create a single Spot VM.
- How many times: Once per VM, so vmCount times.
Each VM requires a separate create call, so the total calls grow directly with the number of VMs.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 create calls |
| 100 | 100 create calls |
| 1000 | 1000 create calls |
Pattern observation: The number of operations increases evenly as we add more VMs.
Time Complexity: O(n)
This means the time to create Spot VMs grows in direct proportion to how many VMs you want.
[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 operation that takes time, so more VMs mean more total time.
Understanding how resource creation scales helps you design efficient cloud deployments and shows you can think about costs and time clearly.
"What if we used a single deployment template to create all Spot VMs at once? How would the time complexity change?"