Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-scaling ECS Cluster to/from zero instances

I have implemented the Job Observer Pattern using SQS and ECS. Job descriptions are pushed to the SQS queue for processing. The job processing run on an ECS Cluster within an Auto-Scaling Group running ECS Docker Tasks.

Each ECS Task does:

  1. Read message from SQS queue
  2. Execute job on data (~1 hour)
  3. Delete message
  4. Loop while there are more messages

I would like to scale down the cluster when there is no more work for each Instance, eventually to zero instances.

Looking at this similar post, the answers suggest scale-in would need to be handled outside of ASG in some way. Instances would self-scale-in, either by explicitly self-terminating or by toggling ASG Instance Protection off when there are no more messages.

This also doesn't handle the case of running multiple ECS Tasks on a single instance, as an individual task shouldn't terminate if other Tasks are running in parallel.

Am I limited to self scale-in and only one Task per Instance? Any way to only terminate once all ECS Tasks on an instance have exited? Any other scale-in alternatives?

like image 992
Jason Avatar asked Oct 19 '16 06:10

Jason


People also ask

Can fargate scale down to zero?

Yes, you can set desire count to zero once the process complete, but there are few things that you need to consider. entrypoint that will deal with nodejs process and set service count to 0 when the nodejs process completed from SQS.

How many EC2 instances can you have in an Auto Scaling group?

If you specify scaling policies, then Amazon EC2 Auto Scaling can launch or terminate instances as demand on your application increases or decreases. For example, the following Auto Scaling group has a minimum size of one instance, a desired capacity of two instances, and a maximum size of four instances.

Can Auto Scaling upgrade instance?

You can use an instance refresh to update the instances in your Auto Scaling group instead of manually replacing instances a few at a time. This can be useful when a configuration change requires you to replace instances, and you have a large number of instances in your Auto Scaling group.

Are ECS clusters scalable?

Amazon ECS uses the target capacity value to manage the CloudWatch metric the service creates to facilitate cluster auto scaling. Amazon ECS manages the CloudWatch metric, so that the Auto Scaling group is treated as a steady state so that no scaling action is required. The values can be from 0-100%.


Video Answer


1 Answers

Another solution for the problem is the AWS Batch service announced at the end of 2016.

like image 138
Jason Avatar answered Nov 06 '22 15:11

Jason