EC2 versus Fargate: performance comparison

  • 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

Test setup:

  • ECS cluster with a public subnet
  • ALB
  • DynamoDB with on-demand provisioning
  • 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.

Result

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

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

TEST 2(DynamoDB post)

The first test was too synthetic. So the second test is to save JSON into DynamoDB. DynamoDB is configured for on-demand provisioning. It means DynamoDB will not be a bottleneck.

Result

EC2 has 2787 requests per second and Fargate 2216. Two services have ~100% CPU utilization.

Fargate result
EC2 result

TEST 3(DynamoDB post and 5 get calls)

Since we see that Fargate has some slowness for I/O operations I would like to run more I/O intensive tests. We will save a book and concurrently get it 5 times(count=5) from DynamoDb.

https://github.com/Aleksandr-Filichkin/ec2-vs-fargate/blob/master/src/main/java/com/filichkin/blog/fargate/versus/ec2/TestController.java#L56

Result

EC2 has 728 request per second and Fargate 454. Two services have ~100% CPU utilization.

Fargate performance
EC2 performance

The bottleneck is CPU as you can see:

Fargate CPU

PS

I run test 3 for 4-cores Fargate and it 2 times better than 2-cores Fargate. Let’s check Dynamodb read metric for all 3 setups(EC2 2core, Fargate 2cores, Fargate 4cores)

Conclusion:

Fargate demonstrated good stable performance for the synthetic test, but in real life, you will see 25–40% performance degradation with I/O AWS services such as (DynamoDb, SQS, SNS, S3, etc). The problem is in CPU utilization, Fargate needs 2 times more CPU for I/O operations. From my point of view, it’s too slow and it’s better to support EC2. Otherwise, you need almost 2 times bigger setup for Fargate.

If you like it, please read my new post:

Fix Java cold start in AWS lambda with GraalVM [performance comparison]

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store