Preemptible and Spot VMs in GCP - Time & Space Complexity
We want to understand how the time to run workloads on Preemptible and Spot VMs changes as we increase the number of tasks.
Specifically, how does the chance of VM interruptions affect the total time to complete all tasks?
Analyze the time complexity of launching multiple Preemptible or Spot VMs to run tasks.
// Pseudocode for launching N Preemptible VMs
for i in 1 to N:
create VM instance with preemptible flag
run task on VM
if VM is preempted:
restart task on new VM
else:
complete task
This sequence runs N tasks on VMs that can be stopped anytime, requiring restarts.
Look at what happens repeatedly when running tasks on Preemptible or Spot VMs.
- Primary operation: Creating VM instances and running tasks.
- How many times: At least N times, but possibly more if VMs are preempted and tasks restart.
As the number of tasks (N) grows, the number of VM creations grows at least linearly.
| Input Size (n) | Approx. VM Creations |
|---|---|
| 10 | 10 to 15 (some restarts) |
| 100 | 100 to 150 (more restarts possible) |
| 1000 | 1000 to 1500 or more (many restarts) |
Pattern observation: The total VM creations grow roughly linearly with tasks, but preemptions add extra restarts increasing total operations.
Time Complexity: O(n)
This means the total time and VM operations grow roughly in direct proportion to the number of tasks, with some extra overhead from restarts.
[X] Wrong: "Preemptible VMs always finish tasks without interruption, so time grows exactly with task count."
[OK] Correct: Preemptible and Spot VMs can stop anytime, causing tasks to restart and increasing total operations beyond just the task count.
Understanding how interruptions affect workload time shows you can plan for real cloud behavior, a key skill for designing reliable systems.
"What if we switched from Preemptible VMs to regular VMs without interruptions? How would the time complexity change?"