Skip to content

ECS Fargate Autoscaling Behavior

0

I have an ECS Fargate service running with the following configuration:

  • 2 running tasks
  • Each task has 1 vCPU and 2 GiB memory
  • Average CPU utilization per task: ~30%
  • Average memory utilization per task: ~35%
  • The workload is CPU-bound

I’m planning to:

  • Reduce the task count to 1
  • Enable ECS service autoscaling with a target tracking policy on CPUUtilization, with a threshold of 70%

My workload has a predictable pattern:

  • During daytime, CPU utilization is high (above 70%)
  • During off-hours (night), utilization drops

My concern: If the autoscaler adds a second task when CPU exceeds 70%, the CPU load will split between the tasks and drop below the threshold. This could cause ECS to scale in and remove the second task. When this happens:

  • The single remaining task might spike up to 90–100% CPU
  • ECS will again take time (3–6 minutes) to trigger scale-out
  • This could lead to frequent scale-in/scale-out loops during the day, potentially degrading performance

My questions are:

  1. Will this scale-in and scale-out loop really happen as described?
  2. Will such a cycle negatively affect performance and response times?
  3. What is the recommended way to handle such predictable, time-based workload patterns while still optimizing cost and performance?
  4. Any detailed guide or refernce

asked a year ago503 views

1 Answer
0
  1. Yes, the scale-in and scale-out loop you described could indeed occur. When ECS Fargate autoscaling is configured with a target tracking policy based on CPU utilization, it will attempt to maintain the average CPU utilization close to the target value (in this case, 70%). The scenario you outlined is a common challenge with autoscaling, often referred to as "thrashing" or "flapping."

  2. Such a cycle can potentially negatively affect performance and response times. During the periods when you have only one task running at high CPU utilization (90-100%), your application may experience degraded performance and increased response times. Additionally, the frequent scaling activities themselves can introduce brief periods of reduced capacity as new tasks are spinning up or old tasks are being terminated.

  3. To handle predictable, time-based workload patterns while optimizing for both cost and performance, consider the following recommendations:

a. Use scheduled scaling: Set up scheduled actions to proactively scale your service based on known patterns. For example, increase the minimum number of tasks before peak hours and decrease it during off-hours.

b. Adjust your scaling thresholds: Instead of using a single threshold (70% in your case), consider using step scaling with multiple thresholds. For example, scale out aggressively when CPU is above 80%, and scale in conservatively when it's below 60%.

c. Implement cooldown periods: Set appropriate cooldown periods between scaling activities to prevent rapid fluctuations. This gives your system time to stabilize after a scaling event before initiating another one.

d. Use a combination of metrics: Consider using both CPU and memory utilization in your scaling policy. This can provide a more holistic view of your application's resource needs.

e. Adjust your task size: Instead of using 1 vCPU per task, you might consider using smaller task sizes (e.g., 0.5 vCPU) to allow for more granular scaling.

f. Implement capacity providers: Use Fargate Capacity Providers to manage the infrastructure for your tasks, which can help optimize resource utilization and costs.

  1. For a detailed guide on ECS autoscaling, you can refer to the official AWS documentation on Amazon ECS Auto Scaling. This comprehensive resource covers various aspects of autoscaling, including target tracking policies, step scaling policies, and scheduled scaling. It also provides best practices and considerations for implementing effective autoscaling strategies.

Remember to monitor your application closely after implementing these changes and fine-tune your autoscaling configuration based on observed behavior and performance metrics.
Sources
Scaling - Containers on AWS
ECS Fargate containers automatic scaling - Prebid Server Deployment on AWS
Automatically scale your Amazon ECS service - Amazon Elastic Container Service

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.