0
0
GCPcloud~5 mins

Preemptible and Spot VMs in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Preemptible and Spot VMs
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As the number of tasks (N) grows, the number of VM creations grows at least linearly.

Input Size (n)Approx. VM Creations
1010 to 15 (some restarts)
100100 to 150 (more restarts possible)
10001000 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.

Final Time Complexity

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.

Common Mistake

[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.

Interview Connect

Understanding how interruptions affect workload time shows you can plan for real cloud behavior, a key skill for designing reliable systems.

Self-Check

"What if we switched from Preemptible VMs to regular VMs without interruptions? How would the time complexity change?"