Fargate Rightsizing

The source of this content can be found here and was originally created by Massimo Re Ferrè.

What Problems Does the AWS Fargate Rightsizing Dashboard Solve?

The metrics collected by Containers Insights for ECS (which includes support for Fargate) isn’t granular enough to allow tracking single tasks. The metrics available (i.e. CpuReserved, CpuUtilized, MemoryReserved, MemoryUtilized) are all aggregated and averaged at the task definition family level. The assumption here is that all running tasks within the same task definition family are evenly balanced (behind an ECS service) when they scale out (so averaging their configuration and consumption is acceptable). This holds true in many situations but it doesn’t always happen. Here are some scenarios that challenge that assumption:

  • The same task definition behind an ECS service being used for both dev and prod environments: often times the load on development environments is much lower than that of production environments. Averaging these inputs may provide a balanced number which doesn’t allow to capture if the dev environment is way under-utilized and/or if the prod environment is way over-utilized
  • The same task definition doesn’t use an ECS service and is rather being used for batch type of workloads with different resource consumption profiles. Again, averaging these inputs may provide a misleading number which doesn’t allow to capture the need to have different task definitions for different workloads profiles
  • There could be situations where the running tasks part of an ECS service behind a load balancer are not evenly utilized. This could be because of a particular application pattern or because of some configuration issues. This dashboard isn’t meant to be a problem determination tool but it could be a way to spot problems other than inefficiencies

The dashboard tries to respond to these user stories

As a user I would like to,

  • see the total number of running Fargate tasks in the cluster
  • see the total waste (aggregate of all running Fargate tasks) relative to actual consumption based on memory usage
  • see the total waste (aggregate of all running Fargate tasks) relative to actual consumption based on CPU usage
  • see the top 10 running Fargate tasks order by memory waste (i.e. the 10 tasks with the highest memory optimization - opportunity)
  • see the top 10 running Fargate tasks ordered by CPU waste (i.e. the 10 tasks with the highest CPU optimization opportunity)
  • see the list of all running Fargate tasks ordered by tasks with the most waste based on cpu usage and memory usage
  • see the list of all running tasks with all the configuration and consumption details ordered by the task definition family name

Execute the following commands to create the custom dashboard

  1. In the AWS Management Console on the Services menu, navigate to CloudShell.
  2. Execute the following commands in the terminal:

These commands will create a custom CloudWatch dashboard that contains several widgets showing cluster resource performance.

PAYFORADOPTION_ECS_CLUSTER=$(aws ecs list-clusters | jq -r '.clusterArns[] | select(. | contains("PayForAdoption"))' | cut -d '/' -f 2)

curl 'https://raw.githubusercontent.com/aws-samples/one-observability-demo/main/PetAdoptions/cdk/pet_stack/resources/fargate-resize-dashboard.json' | sed "s~CLUSTERNAME~${PAYFORADOPTION_ECS_CLUSTER}~"  > fargate-resize-dashboard.json

aws cloudwatch put-dashboard --dashboard-name fargate-right-sizing --dashboard-body file://./fargate-resize-dashboard.json
  1. In the AWS console, navigate to Cloud Watch.
  2. In the left navigation menu, click Dashboards.

You should see the dashboard that you just created, fargate-right-sizing, in the list.

  1. Click on the fargate-right-sizing dashboard.

Your screen should look similar to the screenshot below.

Fargate resizing.

This concludes the ECS potion of this module.