EC2 versus Fargate: performance comparison

Aleksandr Filichkin
3 min readMar 1, 2021

Nowadays, Fargate is very popular. It solves such ECS with EC2 problems as:

  • Scaling problem (with EC2 you should have ASG which will add additional nodes if not enough resource in ECS cluster. It’s quite tricky)
  • Not efficient resource utilization (with EC2 you always need a free buffer in ECS cluster for fast tasks allocations)
  • Regular AMI updates
  • ECS agent disconnection

Since there is no good performance comparison for EC2 and Fargate we will run the performance test and analyze it.

Our goal is to understand if Fargate provides the same performance as EC2.

All code is here

Test setup:

  • ECS cluster with a public subnet
  • ALB
  • DynamoDB with on-demand provisioning

Will compare two ECS setups:

  • EC2 m5.large (2 cores, 8 GB memory)
  • Fargate (2 cores, 8GB memory)

TEST 1 (Fibonacci numbers)

The first test is to calculate the Fibonacci number.

Load scenario: send 50 parallel users from JMeter.


We have exactly the same performance for EC2 and Fargate tasks for the Fibonacci numbers:

3000 request per minute and ~100% CPU utilization

Fargate ELB request per minute
EC2 ELB request per minute
Fargate CPU Utilizaion