Sub topic 10
Benchmarking price-performance before you switch
This chapter assumes you can launch EC2 instances, run the AWS CLI, read CloudWatch metrics, and use Docker. It also assumes you have already right-sized the workload and checked that it runs on Arm64, as covered in earlier chapters. Here you will measure whether a Graviton instance does the same work for less money than the x86 instance it would replace.
Why you benchmark first
Graviton instances list for a lower hourly price than comparable Intel or AMD instances. Lower price per hour does not guarantee lower cost per unit of work. A Graviton instance can be slower on your code path, faster on it, or equal. The only way to know is to measure.
The number you want is cost per unit of work. Examples are cost per 1,000 requests, cost per batch job, or cost per gigabyte processed. You compute it as:
cost per unit = hourly price / units of work per hourIf an instance costs 20% less per hour but handles 25% less traffic, it is more expensive per request. If it costs 20% less and handles the same traffic, you save 20%. If it also handles more traffic, you save more.
Two terms are useful here:
- Throughput is the amount of work completed per unit of time, such as requests per second.
- Latency is the time one unit of work takes, often reported as a percentile. The p99 latency is the value that 99% of requests beat.
You need both. A cheaper instance that meets your throughput target but breaks your p99 latency target is not a valid replacement.
Design the test so the comparison is fair
Most bad benchmark results come from unequal conditions, not from the hardware. Control these variables.
Compare like with like
- Same generation and size class. Compare
m6i.large(Intel) withm6g.large(Graviton2), orm7i.largewithm7g.large(Graviton3). Comparing a new Graviton generation to an old x86 generation tells you about generations, not architectures. - Same vCPU meaning. On most x86 instances, a vCPU is a hardware thread, and two vCPUs share one physical core. On Graviton, each vCPU is a full physical core. A 4 vCPU Graviton instance and a 4 vCPU x86 instance therefore do not have the same hardware behind them. This is often why Graviton looks good at equal vCPU counts. It also means you should compare at equal vCPU counts first, then test whether a smaller Graviton size is enough.
- Same memory ratio. Keep to one family type, such as general purpose (
m), compute optimized (c), or memory optimized (r). - Same storage and network. Use the same EBS volume type, size, and provisioned IOPS. Place the instances in the same Availability Zone and VPC subnet type.
- Same OS and runtime versions. Use Amazon Linux 2023 on both, with the same kernel family and the same language runtime version.
Use the same build, tuned for each target
Build the application separately for each architecture, but from the same source revision and the same configuration. Avoid compiling the x86 build with aggressive flags while leaving the Arm64 build at defaults. For JVM workloads, use the same JDK major version and the same heap settings. For native code, use compiler flags suited to each target and record them.
Use a realistic workload
A synthetic CPU loop shows raw speed but not how your service behaves. Prefer one of these, in order of preference:
- Replayed production traffic. Capture real requests and replay them against both stacks.
- A load test with a realistic request mix. Match the proportions of endpoints, payload sizes, and read/write ratio.
- A micro-benchmark of one hot code path. Use this only to explain a result you already saw at the service level.
Warm up and run long enough
Just-in-time compilers (the JVM, Node.js V8, .NET) and caches change performance during the first minutes. Discard a warm-up period, commonly 5 to 10 minutes. Then measure for at least 30 minutes, and repeat the full run at least three times on freshly launched instances. Compare the medians. Single runs can differ because of noisy neighbors, cache state, and burst credits.
Avoid burstable instance traps
T-family instances (t3, t4g) earn CPU credits and are throttled when credits run out. A short test can look fast because credits are full, and a long test can look slow once they are gone. For a fair benchmark, use non-burstable families, or run T instances in unlimited mode and record the surplus credit charges.
The benchmark workflow
The diagram below summarizes the loop.
Step 1: Define success before you test
Write down the pass criteria first, so the result cannot be bent to fit a preference afterward. For example:
- p99 latency at or below 250 ms at the target load.
- Error rate at or below 0.1%.
- CPU utilization below 70% at peak, leaving headroom.
- Cost per 1,000 requests lower than the baseline.
Step 2: Launch matching test instances
Launch the x86 baseline with an x86-64 AMI and the Graviton candidate with an Arm64 AMI. The public SSM parameter returns the latest Amazon Linux 2023 AMI for each architecture.
# Arm64 image for the Graviton candidate
aws ssm get-parameter \
--name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64 \
--query 'Parameter.Value' \
--output text
# x86-64 image for the baseline
aws ssm get-parameter \
--name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 \
--query 'Parameter.Value' \
--output textAn AMI built for one architecture will not launch on the other family. If you try to pair an x86-64 AMI with a g-suffixed instance type, the launch fails with an error saying the image architecture does not match the instance type. After launch, confirm the architecture on each host:
uname -m
# x86_64 on Intel/AMD instances, aarch64 on Graviton instancesFor container workloads, use the multi-architecture image from the previous chapter, so both stacks run an identical tag and differ only in the platform that Docker pulls.
Step 3: Generate load
Use a load tool that reports percentiles and lets you set a fixed request rate. Two common choices are k6 and wrk2. The second matters for one reason: many tools wait for each response before sending the next request, which hides latency spikes (this is called coordinated omission). A fixed-rate tool avoids that distortion.
Run the load generator on a separate instance, never on the instance under test. Make it large enough that it is not the bottleneck, and place it in the same Availability Zone to keep network latency stable.
Test in two modes:
- Fixed load. Send the same request rate to both stacks and compare CPU use and latency. A lower-utilization stack at the same latency has more headroom.
- Saturation. Raise the rate in steps until the SLO fails. The last rate that passes is the maximum sustainable throughput for that instance. This gives you the "units per hour" figure for the cost formula.
Step 4: Collect metrics
Pull infrastructure metrics from CloudWatch for the test window. This reuses the command from the utilization chapter. Set the times to match each run.
aws cloudwatch get-metric-statistics \
--namespace AWS/EC2 \
--metric-name CPUUtilization \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--start-time 2026-11-01T00:00:00Z \
--end-time 2026-11-15T00:00:00Z \
--period 3600 \
--statistics Average MaximumFor a short benchmark, use a smaller --period such as 60 seconds and a narrower window. Basic monitoring reports at 5-minute resolution, so enable detailed monitoring (1-minute) on the test instances if you need finer data.
CloudWatch does not report memory by default. If memory matters, install the CloudWatch agent on both instances. Also record application-level numbers from your load tool: requests per second, p50/p95/p99 latency, and error count. These are the figures that decide the outcome. CPU percentage alone cannot, because 60% busy on two different architectures does not mean the same amount of work.
Step 5: Compute cost per unit of work
Take the on-demand hourly price for each instance type in your Region from the EC2 pricing page or the Pricing Calculator. Use the maximum sustainable throughput from the saturation test.
Here is a worked example with illustrative numbers. Check current prices before using them.
| Instance | Hourly price (USD) | Max sustainable requests/sec | Requests per hour | Cost per 1M requests (USD) |
|---|---|---|---|---|
| x86 baseline, 4 vCPU | 0.192 | 1,800 | 6,480,000 | 0.0296 |
| Graviton, 4 vCPU | 0.154 | 2,000 | 7,200,000 | 0.0214 |
| Graviton, 2 vCPU | 0.077 | 1,000 | 3,600,000 | 0.0214 |
In this example the 4 vCPU Graviton instance handles 11% more traffic and costs 20% less per hour, so cost per million requests falls by about 28%. The 2 vCPU row shows an important point. Halving the size halves both price and throughput, so cost per unit is unchanged. Smaller sizes do not by themselves save money per request. They save money only when the larger size would sit mostly idle. That is the right-sizing question you answered earlier.
You can script the arithmetic so results are repeatable:
def cost_per_million(hourly_usd: float, requests_per_sec: float) -> float:
requests_per_hour = requests_per_sec * 3600
return hourly_usd / requests_per_hour * 1_000_000
baseline = cost_per_million(0.192, 1800)
graviton = cost_per_million(0.154, 2000)
saving = (baseline - graviton) / baseline * 100
print(f"x86: ${baseline:.4f} per 1M requests")
print(f"Graviton: ${graviton:.4f} per 1M requests")
print(f"Saving: {saving:.1f}%")Reading the results
Look for patterns, not just the headline number.
- Graviton wins on throughput and cost. The usual outcome for web services, containers, and many data-processing jobs. Proceed to rollout.
- Equal throughput, lower price. Still a saving, equal to the price gap. Proceed.
- Lower throughput on one code path. Profile that path. Common causes are code that uses x86-specific vector instructions with no Arm64 equivalent, a native library built without Arm optimizations, or an old runtime version. Upgrading the runtime or library often closes the gap.
- Higher tail latency but good averages. Check garbage collection, thread pool sizing, and connection pool settings. Defaults tuned for x86 hardware threads can behave differently when each vCPU is a full core.
- Graviton loses clearly. Keep that workload on x86 and move on. A failed benchmark is a valid and cheap outcome, because you found out before changing production.
Common errors
| Mistake | Effect | Fix |
|---|---|---|
| Comparing different instance generations | Result reflects generation, not architecture | Match generation and size class |
| Testing for 5 minutes | Includes warm-up and burst credits | Warm up, then measure 30+ minutes, three runs |
| Load generator on the instance under test | Generator steals CPU and skews results | Use a separate instance |
| Using average latency only | Hides tail slowdowns | Report p95 and p99 |
| Ignoring data transfer and licensing | Total cost differs from compute price | Add non-compute costs to both sides |
| Benchmarking a build that fell back to emulation | Misleadingly slow Arm64 result | Confirm `uname -m` and that no `qemu` layer is used |
What to carry forward
A passing benchmark gives you three things for the rollout chapter: a verified SLO result on Arm64, a measured cost per unit that justifies the change, and a baseline of metrics to compare against once real traffic is on Graviton. Keep the raw results and the test configuration, so you can rerun the same test after a runtime upgrade or an instance generation change.
Exercise
Your x86 instance costs 0.20 USD per hour and sustains 1,000 requests per second. A Graviton instance with the same vCPU count costs 0.16 USD per hour and sustains 900 requests per second. Which is cheaper per million requests, and by how much?
Show answer
x86: 0.20 / (1,000 x 3,600) x 1,000,000 = 0.0556 USD per million requests. Graviton: 0.16 / (900 x 3,600) x 1,000,000 = 0.0494 USD per million requests. Graviton is cheaper by about 11%, even though its throughput is 10% lower, because its hourly price is 20% lower. Whether it is acceptable still depends on meeting the latency SLO at that load.
Exercise
A colleague runs a 5-minute test on one x86 instance and one Graviton instance, with the load generator running on the same instance as the application, and concludes that Graviton is 30% slower. Name three problems with the test and how to fix each.
Show answer
First, 5 minutes is too short, because JIT compilation and caches are still warming up. Warm up for 5 to 10 minutes and then measure for 30 minutes or more. Second, running the load generator on the instance under test consumes CPU and skews results, so move it to a separate instance in the same Availability Zone. Third, a single run is not reliable, so repeat the test at least three times on fresh instances and compare medians. Other valid answers: confirm both instances are the same generation and size class, and report p99 latency in addition to throughput.