4

I'm new to docker and ECS, so I might not use the right terms. Please let me know if I need to clarify.

My Scenario: I have a number of independent containers. Each container represents a web site. Each container should run all the time, but might see long periods of inactivity (e.g. zero CPU usage). For illustration, let's assume I have 10 containers and each container requires up to 200MB RAM and up to 1vCPU. Let's further assume that I only need 2vCPU total to handle the combined load from all 10 containers (since they don't see high load all at the same time).

Fargate Option 1: I create a different task for each container: (2GB, 1vCPU) x 10 (2GB is minimum RAM for 1vCPU).

Fargate Option 2: I create a single task with all containers: (2GB, 2vCPU).

EC2 Option: I create a task per container, all mapped to a single EC2 instance.

If I understand correctly, Fargate Option 2 is much cheaper than Fargate Option 1 because I know I only need a maximum of 2vCPU. But Option 2 is a lot less flexible since it is tasks that are stopped/started/scaled and I want to treat my containers as independent of each other (e.g. stop/start/scale independently).

Furthermore, if I understand correctly, the EC2 Option is the only way I can get both the flexibility of having a task per container as well as paying for the resources I actually need.

So: It seems that for independent containers with low resource utilization, Fargate is not a good fit at this time.

Is my understanding correct?

Felix
  • 143
  • 5
  • Given that your CPU utilization is low, AWS Lambda would be a better choice if you could manage the cold start problem, because it provides the lowest standby cost. – Yang Bo Jun 03 '22 at 01:09

2 Answers2

3

That's correct, Fargate is more expensive than EC2 for the same vCPU/RAM amount.

For example:

  • The smallest Fargate container with 0.25 vCPU and 0.5 GB RAM costs $0.019/hr, that's ca $14/month per container.

  • If you need 1 vCPU then the minimum amount of RAM is 2GB (see Fargate Supported Configurations) and suddenly the price is ca $55/month per container. In your case times 10 tasks makes it $550/month.

  • On the other hand if you're confident that you can squeeze all that to a single t3.small (2 vCPU, 2 GB RAM) it will cost you $0.0208/hr which is ca $15/month. Even if you happen to need 2 or 3 t3.small instances to support your load it's still far cheaper than Fargate.

  • If you lump up all your containers into a single Fargate task (as suggested in your Option 2) it's still more expensive than using EC2 ECS, plus the complications with having multiple independent containers in one task. It's not worth the trouble.

So to wrap up - if you want to run your containers 24x7 and they are not fully utilised all the time you'll be much better off running them on an EC2-based ECS cluster.

With Fargate you pay premium for the flexibility.

If your containers only run briefly to complete a task and then exit, or if they scale up and down based on demand it will be much easier for you to run them in Fargate - you won't need to scale up and down the underlying EC2 cluster to support the load.

In many cases it works out better to run on Fargate even if it's more expensive per vCPU/RAM. We spin up batches of hundreds of containers at a time a couple times per day for some processing and each container runs for only about 10 minutes. If we had to scale up the EC2/ECS cluster before each run, wait for it to settle, deal with the failures, then run our batch job and then scale down again the overhead would be quite high and our batch processing would take much longer.

Here Fargate works great for us. I wouldn't use it for an always-on service though.

Hope that helps :)

MLu
  • 23,798
  • 5
  • 54
  • 81
  • Thanks! Regarding your first bullet point: I wouldn't be able to use 0.25 vCPU. I need 1vCPU. So the Fargate price would be more like $41/month x 10 or $410/month. Is that right? I don't mind paying a premium for Fargate, but that is too much of a premium. If you agree with what I write above, then regarding your third bullet: It would be 10x cheaper not just $1/month cheaper. – Felix Nov 08 '18 at 03:07
  • @Felix If it’s a website container than you should be all right with 0.25 vCPU per task. But if you really need 1 vCPU then suddenly the minimum amount of RAM is 2GB (see Supported configurations on the Fargate pricing page) and the price per month is $55. Even if you needed 2 x t3.small to support your workload it’s still far cheaper than Fargate. – MLu Nov 08 '18 at 03:43
  • Gotcha. The websites aren't lightweight (rails) and so response time increases with less CPU. I made up the numbers for the purpose of illustration, but I prefer more CPU. Would you like to adjust your answer to respond more closely to my question? E.g. Start with "Your thinking is correct..." and use the vCPU, etc numbers I use. I've changed my question to use 2GB of RAM to make it easier. If you would like me to adjust my question further, I can do that as well. – Felix Nov 08 '18 at 03:51
  • @Felix Updated the answer. – MLu Nov 08 '18 at 04:14
  • Thanks so much for for the help! I'm glad to learn I wasn't overlooking something obvious. – Felix Nov 08 '18 at 08:34
  • Just a general follow-up after a few years. Since my original question, I've learned a lot more about ECS. I now believe that Fargate is *not a good option price-wise* for running many lightweight tasks that might need bursts of CPU/RAM on occasion. I now use ECS with EC2 instances and it works great for my needs. As an aside, AWS pricing has always made a lot of sense to me, but in the case of Fargate I'm fairly baffled as to why they structured the service/pricing in the way that they did. – Felix May 14 '21 at 16:49
0

You can also use EKS (Elastic Kubernetes Service) instead of ECS.

Kubernetes give some more control over the pods, services, volumes and such. However not sure if it's cheaper than ECS, maybe not.

Fer Dah
  • 224
  • 1
  • 8