TExcelTAD
Home › AWS Cloud › EC2 Instance Types

EC2 Instance Types

EC2 offers hundreds of instance types. They look cryptic at first, but the names follow a pattern.

Reading an instance type name

Take m7g.2xlarge:

Part Meaning
m Family: general purpose
7 Generation: higher is newer, usually better price/performance
g Attributes: g = AWS Graviton (ARM) processor, i = Intel, a = AMD, d = local NVMe disk, n = more network
2xlarge Size: within a family each size up roughly doubles vCPUs and memory

Families

Family Optimised for Typical workload
t (burstable), m General purpose: balanced CPU/memory Web servers, small databases, dev/test
c Compute Batch processing, video encoding, game servers
r, x Memory In-memory caches, large databases, analytics
i, d Storage (fast local disks) NoSQL databases, data warehousing
p, g, trn, inf Accelerated computing (GPUs, AWS chips) Machine learning, graphics

Model: parse instance type names

python · try it yourself
import re

FAMILIES = {"t": "burstable general purpose", "m": "general purpose", "c": "compute optimised",
            "r": "memory optimised", "x": "memory optimised", "i": "storage optimised",
            "p": "accelerated (GPU)", "g": "accelerated (graphics)"}
ATTRS = {"g": "Graviton/ARM", "a": "AMD", "i": "Intel", "d": "local NVMe", "n": "high network"}

PATTERN = re.compile(r"^([a-z]+?)(\d+)([a-z-]*)\.(\w+)
quot;) def describe(name): family, gen, attrs, size = PATTERN.match(name).groups() extras = [ATTRS[a] for a in attrs if a in ATTRS] or ["default CPU"] return f"{name:<13} {FAMILIES.get(family, family):<26} gen {gen} {', '.join(extras):<24} size {size}" for name in ["t3.micro", "m7g.2xlarge", "c6in.large", "r7a.4xlarge", "i4i.xlarge"]: print(describe(name))
t3.micro      burstable general purpose  gen 3  default CPU              size micro
m7g.2xlarge   general purpose            gen 7  Graviton/ARM             size 2xlarge
c6in.large    compute optimised          gen 6  Intel, high network      size large
r7a.4xlarge   memory optimised           gen 7  AMD                      size 4xlarge
i4i.xlarge    storage optimised          gen 4  Intel                    size xlarge

Sizes double

Inside one family, every step up roughly doubles the resources (and the price). The table below uses the shape of the m family (4 GiB of memory per vCPU):

python · try it yourself
sizes = ["large", "xlarge", "2xlarge", "4xlarge", "8xlarge"]
vcpus = 2
example_price = 0.096          # example $/hour for the 'large' size

print(f"{'size':<9}{'vCPU':>5}{'GiB':>6}{'$/hour':>9}")
for size in sizes:
    print(f"{size:<9}{vcpus:>5}{vcpus * 4:>6}{example_price:>9.3f}")
    vcpus *= 2
    example_price *= 2
size      vCPU   GiB   $/hour
large        2     8    0.096
xlarge       4    16    0.192
2xlarge      8    32    0.384
4xlarge     16    64    0.768
8xlarge     32   128    1.536

This makes right-sizing easy to reason about: if an xlarge instance averages 20% CPU, a large would run at about 40% for half the price.

Burstable instances (T family)

t3/t4g instances have a low baseline CPU and earn CPU credits while they are below it. Credits are spent when the instance bursts above the baseline. If the credits run out, the instance is throttled to its baseline (in "standard" mode) or you pay for extra credits ("unlimited" mode).

python · try it yourself
baseline = 20          # percent of one vCPU (example baseline)
credits = 30.0         # starting balance; 1 credit = 1 vCPU at 100% for 1 minute
max_credits = 144

hourly_cpu = [5, 5, 10, 90, 100, 100, 100, 100, 30, 10]   # demanded CPU % per hour
for hour, demand in enumerate(hourly_cpu):
    earned = baseline / 100 * 60
    wanted = demand / 100 * 60
    if wanted <= earned + credits:
        used_cpu = demand
        credits = min(max_credits, credits + earned - wanted)
    else:
        used_cpu = (earned + credits) / 60 * 100
        credits = 0.0
    status = "throttled" if used_cpu < demand else ""
    print(f"hour {hour}: demand {demand:>3}%  got {used_cpu:5.1f}%  credits {credits:6.1f} {status}")
hour 0: demand   5%  got   5.0%  credits   39.0
hour 1: demand   5%  got   5.0%  credits   48.0
hour 2: demand  10%  got  10.0%  credits   54.0
hour 3: demand  90%  got  90.0%  credits   12.0
hour 4: demand 100%  got  40.0%  credits    0.0 throttled
hour 5: demand 100%  got  20.0%  credits    0.0 throttled
hour 6: demand 100%  got  20.0%  credits    0.0 throttled
hour 7: demand 100%  got  20.0%  credits    0.0 throttled
hour 8: demand  30%  got  20.0%  credits    0.0 throttled
hour 9: demand  10%  got  10.0%  credits    6.0

The instance happily absorbs a short burst, but a sustained 100% load drains the credits and the instance gets throttled. A workload that is busy all the time belongs on an m or c instance.

Choosing a type

  1. Start with a general-purpose type of the newest generation.
  2. Measure CPU, memory and network with CloudWatch.
  3. Switch family if one resource is the bottleneck; change size to match the load.
  4. Consider Graviton (g) types: usually cheaper for the same work, if your software runs on ARM.

Tip: AWS Compute Optimizer analyses your instances' metrics and recommends better-sized types.

Test yourself

In c7g.large, what does the g mean?

  1. GPU
  2. Graviton (ARM) processor
  3. General purpose
  4. Gigabit network

Which family fits an in-memory cache that needs lots of RAM?

  1. c
  2. r
  3. t
  4. p

What happens to a T instance in standard mode when it runs out of CPU credits?

  1. It stops
  2. It is throttled to its baseline
  3. It becomes free
  4. It moves to another AZ