Sub topic 5
Choosing an instance family and size
You have measured utilization and applied the right-sizing method from the earlier chapters. This chapter covers the next step, which is picking the instance type that fits the measured profile. It assumes you can read an EC2 instance type name, know what an AMI is, and have CloudWatch utilization numbers for the workload you are changing. It also assumes you can run AWS CLI commands.
How an instance type name is built
An instance type name has four parts, for example m6i.xlarge:
mis the family, which sets the balance of CPU, memory and other resources.6is the generation. A higher number means newer hardware.iis an attribute suffix. Here it means Intel processors.xlargeis the size.
Common attribute suffixes are:
| Suffix | Meaning | Example |
|---|---|---|
| `a` | AMD processor | `m6a` |
| `i` | Intel processor | `m6i` |
| `g` | AWS Graviton (Arm64) processor | `m7g` |
| `d` | Local NVMe instance store volumes | `m6id` |
| `n` | Higher network bandwidth | `c6in` |
| `e` | Extra memory or storage | `r5b`, `x2iedn` |
A family with no suffix, such as m5, uses Intel processors in older generations. The suffix is part of the type name, so m6i and m6a are different instance types with different prices. Many suffix combinations exist, and not every family offers every combination.
Match the family to the resource ratio
Each general family has a typical ratio of memory to vCPU. The ratio is the main way to choose a family, because it decides which resource you pay for but leave unused.
| Family group | Typical memory per vCPU | Fits workloads that are | Example type |
|---|---|---|---|
| General purpose (`m`) | 4 GiB | Balanced, such as web and application servers | `m6i.large` (2 vCPU, 8 GiB) |
| Compute optimized (`c`) | 2 GiB | CPU-bound, such as batch encoding or game servers | `c6i.large` (2 vCPU, 4 GiB) |
| Memory optimized (`r`, `x`) | 8 GiB or more | Memory-bound, such as caches and in-memory databases | `r6i.large` (2 vCPU, 16 GiB) |
| Burstable (`t`) | 2 to 4 GiB | Low average CPU with occasional spikes | `t3.large` |
| Storage optimized (`i`, `d`) | Varies | High local disk throughput or IOPS | `i4i.large` |
| Accelerated (`g`, `p`, `inf`, `trn`) | Varies | GPU or ML workloads | Not covered here |
The letter g in the family position, as in g5, means GPU. The letter g as a suffix, as in m7g, means Graviton. Check which position the letter is in before you read a name.
You can confirm the ratio for any type with the CLI instead of relying on memory:
aws ec2 describe-instance-types \
--instance-types m6i.large c6i.large r6i.large \
--query 'InstanceTypes[].[InstanceType,VCpuInfo.DefaultVCpus,MemoryInfo.SizeInMiB]' \
--output tableThe output lists m6i.large with 2 vCPUs and 8192 MiB, and the c6i and r6i types with 4096 and 16384 MiB. Use this query whenever you compare candidates, because available types and specifications change over time.
Read your metrics as a ratio
Take the peak or high-percentile figures from your measurement period, not the averages, and convert them to a memory-to-CPU ratio.
Suppose a service runs on an m6i.2xlarge (8 vCPU, 32 GiB). Over two weeks its p95 CPU is 18% and its p95 memory use is 26 GiB. The CPU figure is low, but the memory figure is 81% of the instance. The workload is memory-heavy, so the CPU is the oversized resource. Moving to the r family keeps the memory and drops the vCPU count. An r6i.xlarge has 4 vCPU and 32 GiB. If p95 CPU of 18% on 8 vCPUs becomes roughly 36% on 4 vCPUs, the new size still has headroom.
The following script does that arithmetic. It filters a list of candidates by your memory and CPU requirements and prints the matches. The candidate specifications here are typed in by hand, so verify them with the describe-instance-types query above before you rely on them.
# Pick candidates that satisfy measured demand with headroom.
CANDIDATES = {
"m6i.xlarge": (4, 16),
"m6i.2xlarge": (8, 32),
"r6i.xlarge": (4, 32),
"r6i.2xlarge": (8, 64),
"c6i.2xlarge": (8, 16),
}
def fits(vcpu, mem_gib, need_vcpu, need_mem_gib, headroom=0.30):
"""True if the type covers demand plus a headroom fraction."""
return (vcpu >= need_vcpu * (1 + headroom)
and mem_gib >= need_mem_gib * (1 + headroom))
# Measured demand: 18% of 8 vCPU at p95, and 26 GiB memory at p95.
need_vcpu = 8 * 0.18
need_mem = 26.0
for name, (vcpu, mem) in CANDIDATES.items():
if fits(vcpu, mem, need_vcpu, need_mem):
print(f"{name}: {vcpu} vCPU, {mem} GiB")With 30% headroom, the memory requirement is 33.8 GiB, so only r6i.2xlarge passes. r6i.xlarge has 32 GiB, which is less than the p95 plus headroom. That is a reminder to check memory headroom before you shrink a memory-bound workload. Run the script, then decide whether 30% headroom is the right margin for your service.
Size within the family
Sizes inside one family scale in a regular way. From large upward, each step doubles the vCPU count and the memory, and the on-demand price roughly doubles too.
| Size | vCPU | Memory in `m` family |
|---|---|---|
| `large` | 2 | 8 GiB |
| `xlarge` | 4 | 16 GiB |
| `2xlarge` | 8 | 32 GiB |
| `4xlarge` | 16 | 64 GiB |
Because the price per vCPU is roughly constant inside a family, two xlarge instances cost about the same as one 2xlarge. This has two practical effects.
- Downsizing by one step cuts the cost of that instance by about half. This is the usual right-sizing action when p95 utilization is under about 40%.
- Choosing between one big instance and several small ones is a design decision, not a cost decision. Several small instances give finer scaling granularity and a smaller failure impact. One large instance wastes less on per-instance overhead such as the operating system, agents and sidecars.
Smaller sizes also have lower network and EBS limits. A large instance typically advertises network bandwidth as "up to" a figure, which means a burst limit backed by a lower baseline. A service that is neither CPU- nor memory-bound can still be limited by baseline network or EBS throughput. Check the per-size limits before shrinking an I/O-heavy workload.
aws ec2 describe-instance-types \
--instance-types m6i.large m6i.xlarge \
--query 'InstanceTypes[].[InstanceType,NetworkInfo.NetworkPerformance,EbsInfo.EbsOptimizedInfo.BaselineThroughputInMBps]' \
--output tableChoose the newest generation that fits
Within the same family, newer generations usually deliver more performance per dollar. An m7i is typically priced close to an m6i and performs better. Moving from m5 to a newer generation is often the lowest-risk saving, because the architecture stays x86-64 and the AMI usually works unchanged.
Check three things before you change generation:
- The Region and Availability Zones you use offer the new type. Not every type is available everywhere.
- The AMI supports the newer instance's virtualization and network driver. Current Amazon Linux and Ubuntu images do. Old custom AMIs may lack the ENA or NVMe drivers.
- Your Savings Plan or Reserved Instance covers the new type. A Compute Savings Plan does. A Reserved Instance for a specific family may not.
The g suffix marks the Graviton variants such as m7g, c7g and r7g. They run on Arm64 processors and often cost less than the equivalent x86 type. They need a compatibility check, so the next chapters cover them separately. For now, keep them in your candidate list and note them as "to evaluate".
Burstable instances need credit data
T-family instances (t3, t3a, t4g) earn CPU credits while they run below a baseline and spend them when they run above it. A t3.large has a baseline of 30% per vCPU, for example. A workload that averages 10% CPU with short spikes suits this model and costs much less than a fixed-performance type.
CPU utilization alone does not tell you whether a T instance is a good fit. Look at two additional CloudWatch metrics in the AWS/EC2 namespace:
CPUCreditBalanceshows the credits that remain. A balance that trends toward zero means the instance is running above its baseline.CPUSurplusCreditsChargedshows credits charged in unlimited mode. Unlimited mode is the default for T3 and T4g. A steady non-zero value means you are paying extra for sustained CPU use, and a fixed-performance type such asmwould probably cost less.
A decision flow
The sequence below puts the steps from this chapter in order. Run it for each candidate workload.
Common mistakes
- Sizing from averages. An average CPU of 15% can hide a p99 of 90% during a daily batch window. Use a percentile that matches your service level.
- Changing family and architecture at once. If you move from
m5.2xlargetor7g.xlargein one step, you cannot tell which change caused a regression. Right-size within x86 first, then evaluate Graviton as a separate change. - Ignoring licensing and per-core software. Some commercial software is licensed per vCPU. Halving the vCPU count can change the license cost more than the instance price.
- Ignoring instance store. Types without the
dsuffix have no local NVMe volumes. If the workload uses them for scratch space, a type change must keep that capability. - Forgetting quotas. On-demand vCPU quotas are counted per family group. A move to a different family group may hit a quota you have not raised.
Exercise
A service runs on an m6i.2xlarge (8 vCPU, 32 GiB). Over two weeks, p95 CPU is 12% and p95 memory use is 27 GiB, with a 30% headroom target. Which family and size would you shortlist, and why? What would you check before changing it?
Show answer
Memory is the binding resource. 27 GiB plus 30% is about 35 GiB, and CPU needs only about 8 × 0.12 × 1.3 ≈ 1.25 vCPU. That is roughly 28 GiB per vCPU of demand, far above the 4 GiB per vCPU of the m family. An r6i.2xlarge (8 vCPU, 64 GiB) fits memory with margin but keeps all 8 vCPUs and costs more. An r6i.xlarge (4 vCPU, 32 GiB) has too little memory for the 30% target. So shortlist r6i.2xlarge if memory headroom is required, or confirm that the 27 GiB p95 includes reclaimable page cache and that the application can live with less headroom, in which case r6i.xlarge is a candidate. Before changing, check that memory data comes from the CloudWatch agent and excludes cache, check network and EBS limits for the new size, and validate with a load test.
Exercise
A t3.large shows low average CPU, but CPUSurplusCreditsCharged is non-zero every day. What does that mean, and what would you do?
Show answer
The instance runs above its baseline long enough to exhaust its credits, and unlimited mode charges for the extra usage. The workload is no longer a good fit for a burstable type. Compare the cost of the surplus charges with a fixed-performance type such as m6i.large, or move to a larger T size with a higher baseline, and pick whichever is cheaper at the measured load.
Exercise
Why should you avoid moving from m5.2xlarge to a Graviton type in the same change as a right-sizing step?
Show answer
Two variables change at once, so a performance or stability regression cannot be attributed to the smaller size or to the new architecture. Right-size on x86 first, then evaluate Graviton as a separate, tested change.