Optimizing Amazon EC2 Costs with Grafana k6
Key point
Compared performance and cost efficiency across 7 EC2 types using Grafana k6 and Monte Carlo simulation.
Details
EC2 offers more than 700 instance types, but it's hard to gauge real workload performance from spec sheets alone. Here, Grafana k6 was combined with Monte Carlo simulation to apply direct CPU-intensive load and compare 7 x86_64 and arm64 instances in the 8 vCPU-class 2xlarge tier. The targets were c5.2xlarge, c6i.2xlarge, c6g.2xlarge, c7i.2xlarge, c7g.2xlarge, c8i.2xlarge, and c8g.2xlarge.
The test app was built with Nginx, Gunicorn, and Flask. The Flask API used 500,000 random numbers to estimate π based on the ratio of points falling inside a circle, creating a pure CPU load with heavy iterative computation and random number generation.
Load was ramped up in stages using k6's stages.
- Warm up to VU 100 over 3 minutes
- Sustain VU 400 for 10 minutes
- Cool down for 2 minutes
Success criteria were set as p95 < 2000ms for http_req_duration and rate < 0.01 for http_req_failed, controlling both latency and failure rate together. On EC2, User Data was used to automatically install nginx, python3, pip, gunicorn, and flask, with the service brought up via systemd, and results were verified through CloudWatch's CPUUtilization metric. Instead of enabling EC2 detailed monitoring to collect 1-minute interval metrics, the additional cost of about $0.30/month per metric was accepted.
The results showed a trend of decreasing CPU utilization for the same workload as generations advanced. In particular, the Graviton family had favorable pricing compared to equivalent x86 instances: c6g was about 20% cheaper than c5, and c7g was about 15% cheaper than c6i while showing about a 10% performance advantage. Ultimately, c8i showed CPU utilization dropping from 100% to 44.45% compared to c5, underscoring the importance of price-performance judgment that combines actual benchmarks with the AWS Pricing Calculator and Cost Explorer.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.