Machine types and families (E2, N2, C2) in GCP - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When choosing machine types in GCP, it's important to understand how the time to provision and manage these machines changes as you increase the number of instances.
We want to know how the work grows when we add more machines from different families like E2, N2, or C2.
Analyze the time complexity of creating multiple VM instances using different machine families.
for i in range(n):
compute.instances().insert(
project=project_id,
zone=zone,
body={
"name": f"instance-{i}",
"machineType": f"zones/{zone}/machineTypes/e2-standard-4"
}
).execute()
This sequence creates n VM instances of the E2 machine family one after another.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: The API call to create a VM instance (
compute.instances().insert()). - How many times: This call happens once for each instance, so n times.
Each new instance requires a separate API call and provisioning process, so the total work grows directly with the number of instances.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 API calls to create 10 instances |
| 100 | 100 API calls to create 100 instances |
| 1000 | 1000 API calls to create 1000 instances |
Pattern observation: The number of operations grows linearly as you add more instances.
Time Complexity: O(n)
This means the time to create instances grows directly in proportion to how many you want to create.
[X] Wrong: "Creating more instances from faster machine families like C2 will reduce the total provisioning time regardless of how many instances I create."
[OK] Correct: The machine family affects the performance of the instance, but the number of API calls and provisioning steps still grows with the number of instances, so total time still increases linearly.
Understanding how provisioning time scales with the number of machines helps you design efficient cloud deployments and shows you can think about resource management clearly.
"What if we used a bulk API to create multiple instances at once? How would the time complexity change?"
Practice
Solution
Step 1: Understand the purpose of each machine family
The E2 family is designed for cost-effective general use, N2 balances power and memory, and C2 is optimized for CPU-heavy tasks.Step 2: Match the workload type to the machine family
Since the question asks for cost-effective general use, E2 is the best fit.Final Answer:
E2 family -> Option AQuick Check:
Cost-effective general use = E2 [OK]
- Confusing C2 as cost-effective instead of CPU-optimized
- Choosing N2 for cost savings instead of balance
- Selecting a non-existent machine family like M1
Solution
Step 1: Identify the correct machine family prefix for C2
C2 machine types start with 'c2-', so the machine type string must include 'c2-standard-4'.Step 2: Verify the full machineType format
The format is 'zones/{zone}/machineTypes/{machineType}', so 'zones/us-central1-a/machineTypes/c2-standard-4' is correct.Final Answer:
machineType: 'zones/us-central1-a/machineTypes/c2-standard-4' -> Option DQuick Check:
C2 machine type string includes 'c2-' prefix [OK]
- Using 'e2-' or 'n2-' prefix for C2 machines
- Incorrect zone or path format
- Using a non-existent machine family like 'm1-'
n2-standard-8. Which statement best describes this VM's characteristics?Solution
Step 1: Understand the N2 machine family purpose
N2 machines balance CPU power and memory, suitable for general workloads needing moderate resources.Step 2: Analyze the machine type suffix
'standard-8' means 8 virtual CPUs with balanced memory, not specialized for CPU-only or high-memory.Final Answer:
It balances CPU and memory with 8 vCPUs and moderate RAM. -> Option BQuick Check:
N2 = balanced CPU and memory [OK]
- Confusing N2 with C2 which is CPU-optimized
- Thinking N2 is cost-effective like E2
- Assuming N2 is high-memory only
c2-standard-16 but gets an error. Which is the most likely cause?Solution
Step 1: Check machine type naming and limits
'c2-standard-16' is a valid machine type with 16 vCPUs; spelling is correct and allowed size.Step 2: Consider zone availability
Some zones do not support all machine types or sizes, so the error likely comes from zone limitations.Final Answer:
The zone does not support C2 machine types with 16 vCPUs. -> Option AQuick Check:
Zone support limits cause machine type errors [OK]
- Assuming spelling error when name is correct
- Believing C2 max vCPUs is 8 (it's higher)
- Ignoring zone prefix requirement in machineType
Solution
Step 1: Identify workload requirements
The job is CPU-intensive needing maximum CPU power with moderate memory.Step 2: Match machine family to workload
C2 family is optimized for CPU-heavy workloads, while E2 is cost-effective general use and N2-highmem is for memory-heavy tasks.Step 3: Choose the best machine type
Among options, 'c2-standard-16' provides high CPU power with balanced memory, fitting the requirement best.Final Answer:
c2-standard-16 -> Option CQuick Check:
CPU-heavy job = C2 machines [OK]
- Choosing E2 for CPU-heavy instead of cost-effective use
- Picking N2-highmem which wastes cost on extra memory
- Selecting E2-highcpu which is less powerful than C2
