Wednesday, October 27, 2021

[SOLVED] ECS Service auto scaling and auto scaling group

Issue

I've decided to start playing with AWS ECS service, and created cluster and one service my issue is that I want to connect it to the AWS auto scaling group. I have followed the following guide.

The guide works, my issue is that its a total waste of money.

The guide says that I need to add machine when the total amount of CPU units that my services reserve is above 75, but in reality my services always reserve 100% because I don't want waste money, also its pretty useless to put 3 nodejs tasks on 2 cpu machine, there is no hard-limit anyway.

I am breaking my head on it for few days now, I have no idea how to make them work together properly

EDIT: Currently this is what happens:

  1. CPU getting above 75%, Service scaling is created 2 new tasks on the same server, which means that now I have 1 instance with 4 tasks

  2. Instance reservation is now 100%, Auto Scaling Group is creating new instance

  3. Once the new instance is created, Service Scaling is removing 2 tasks from the old instance and adding 2 new tasks to the new instance

Its just me or this whole process looks like waste of time? is this how it really should be or (probably) i done something wrong?


Solution

I think you are missing a few insights.

For ECS autoscaling to work properly you also have to set up scaling on a ECS Service level.

Then, the scaling flow would look like this:

  1. ECS Service is reaching 100% used CPU and has 100% reserved CPU
  2. ECS Service scales by starting an additional task, making the reserved CPU total at 200%
  3. Auto scaling group sees there is more Reserved capacity than available capacity and launches a new machine.

In addition, you can perfectly run multiple nodejes tasks on a 2 CPU machine. Especially in a micro service environment, these nodejs services can be quite small (128 CPU for example) and still run perfectly fine all together on the same host machine.



Answered By - ThomasVdBerge