Instance types and families in AWS - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When choosing instance types and families, it's important to understand how the number of instances affects the time to launch and manage them.
We want to know how the time to provision and handle instances grows as we increase their count.
Analyze the time complexity of launching multiple EC2 instances from a chosen instance family.
for i in range(n):
ec2.run_instances(
ImageId='ami-12345678',
InstanceType='t3.micro',
MinCount=1,
MaxCount=1
)
This sequence launches n EC2 instances one by one using the same instance type from a family.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: The
run_instancesAPI call to launch one instance. - How many times: This call repeats n times, once per instance.
Each instance requires a separate API call, so the total calls grow directly with the number of instances.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of API calls increases one-to-one with the number of instances.
Time Complexity: O(n)
This means the time to launch instances grows linearly as you add more instances.
[X] Wrong: "Launching multiple instances at once takes the same time as launching one instance."
[OK] Correct: Each instance requires its own setup and API call, so total time grows with the number of instances.
Understanding how instance provisioning scales helps you design systems that handle growth smoothly and predict resource needs.
"What if we used a single API call to launch multiple instances at once? How would the time complexity change?"
Practice
Solution
Step 1: Understand instance family purposes
The T family is designed for general purpose workloads with balanced CPU and memory.Step 2: Match workload type to instance family
Web servers and small databases typically need balanced resources, fitting T family well.Final Answer:
T family (e.g., t3, t4g) -> Option DQuick Check:
General purpose = T family [OK]
- Confusing compute-optimized C family for general purpose
- Choosing memory-optimized R family for small databases
- Selecting GPU P family for simple web servers
Solution
Step 1: Identify compute-optimized prefix
Compute-optimized instances start with 'c' (e.g., c5, c6g).Step 2: Check instance type format
Correct format is family + size, like 'c5.large'.Final Answer:
c5.large -> Option BQuick Check:
Compute-optimized = c5.large [OK]
- Choosing m5.large which is general purpose
- Selecting r5.large which is memory optimized
- Using t3.large which is burstable general purpose
A) m5.large B) c5.large C) r5.large D) t3.large
Solution
Step 1: Understand instance family memory focus
R family is memory optimized, offering more memory per vCPU than others.Step 2: Compare memory per vCPU for given types
r5.large has 16 GiB RAM and 2 vCPUs (8 GiB/vCPU), higher than m5.large (8 GiB/2 vCPU = 4 GiB/vCPU), c5.large (4 GiB/2 vCPU = 2 GiB/vCPU), t3.large (8 GiB/2 vCPU = 4 GiB/vCPU).Final Answer:
r5.large -> Option AQuick Check:
Memory optimized = r5.large [OK]
- Assuming m5.large has more memory per vCPU
- Confusing compute-optimized c5.large as memory heavy
- Thinking burstable t3.large has highest memory per vCPU
c5.large but your application needs more memory. Which instance type should you choose to fix this issue without changing the CPU count?Solution
Step 1: Identify current instance specs
c5.large has 2 vCPUs and 4 GiB memory.Step 2: Find instance with same vCPU but more memory
r5.large has 2 vCPUs and 16 GiB memory, increasing memory without changing CPU count.Final Answer:
r5.large -> Option AQuick Check:
More memory, same CPU = r5.large [OK]
- Choosing c5.xlarge which doubles CPU and memory
- Picking t3.large which is burstable, not memory optimized
- Selecting m5.large which has less memory (8 GiB) than r5.large
Solution
Step 1: Identify instance families for GPU workloads
P family instances are designed for GPU-intensive tasks like machine learning.Step 2: Choose size with high GPU and memory
p4d.24xlarge offers multiple GPUs and large memory, ideal for training jobs.Final Answer:
p4d.24xlarge -> Option CQuick Check:
GPU + large memory = p4d.24xlarge [OK]
- Picking c5.4xlarge which lacks GPUs
- Choosing r5.12xlarge which is memory optimized but no GPU
- Selecting t3.2xlarge which is burstable general purpose
