ECS | Capacity Provider Strategy

Introduction:

In the previous blog post, we covered the topic of Amazon Elastic Container Service (ECS) and delved into how this service can be effectively utilized. If you haven’t had a chance to explore that blog yet, we highly recommend visiting it to gain a deeper understanding of ECS and its practical applications.

link: https://opstree.com/blog//2023/09/19/applications-hosting-on-ecs/


In this blog, we will explore the concept of Capacity Providers in Amazon ECS. We’ll delve into the reasons for choosing Capacity Providers in Amazon ECS, understand how they function, examine the various types of Capacity Providers, explore the significance of weight and base settings within Capacity Providers, and take a closer look at the potential drawbacks associated with their usage.

What is a Capacity Provider:

Amazon Elastic Container Service (ECS) is a robust container orchestration service offered by Amazon Web Services (AWS), designed to simplify the deployment, management, and scaling of containerized applications. At the heart of ECS lies the concept of Capacity Providers. It’s a fundamental element streamlining the intricate process of managing the compute resources that underpin your containerized workloads.

Why to choose Capacity Provider:

When deploying applications, it’s essential to consider how many instances are required for the application to operate effectively. Determining the right number of instances can be a complex and challenging task. To simplify this process, Amazon offers a feature known as “Amazon ECS Capacity Providers.” These Capacity Providers take on the responsibility of managing the scaling of infrastructure for your tasks and services within your clusters. If utilization increases, ECS provisions more resources; if it decreases, the cluster scales down.

How Capacity Providers Works:

When creating tasks or services within your ECS cluster, you have the option to associate them with Capacity Providers and configure the capacityProviderStrategy to control how tasks are scheduled. The ECS scheduler leverages these rules to make placement decisions, taking into account resource requirements, task weights, and base values.

When configuring your service or task, you’ll find a setting called “Compute options” under the compute configuration.

Within this setting, you can choose between “Use cluster default” and “Use custom” for the “Capacity provider strategy.” In the “Capacity provider strategy,” you can specify multiple Capacity Providers to be used for task placement.

Types of Capacity Provider:

Amazon ECS offers two types of Capacity Providers that you can use to manage the capacity in your ECS cluster:

  1. Amazon ECS workloads that are hosted on Fargate:

Fargate Capacity Providers are designed for tasks that run on AWS Fargate, a serverless compute engine for containers. When you create a Fargate Capacity Provider, you specify the Fargate Spot or Fargate On-Demand launch type. Fargate Capacity Providers are ideal for workloads that require a serverless container execution environment with automatic scaling and no need to manage the underlying infrastructure.

  1. Amazon ECS workloads that are hosted on Amazon EC2 instances:

EC2 Capacity Providers are used for tasks that run on Amazon EC2 instances. You can create EC2 Capacity Providers that are either associated with On-Demand instances or Spot instances. EC2 Capacity Providers are well-suited for workloads that require more control over the underlying EC2 instances, custom instance types, and support for different instance families.

Concept of Weight and Base

In Amazon Elastic Container Service (ECS) Capacity Providers, “weight” and “base” are two important parameters used to optimize the resource allocation and task placement strategies within your cluster. These parameters allow you to define how resources are allocated among different Capacity Providers.

Weight:
Weight is a relative value assigned to each Capacity Provider. It determines the priority or share of resources a particular Capacity Provider should receive when tasks are placed. The weight is used to distribute the available capacity proportionally among the Capacity Providers.

Base:
Base is a fixed value assigned to a Capacity Provider. It represents the minimum guaranteed capacity reserved for a specific Capacity Provider. This ensures that the Capacity Provider always has a minimum amount of capacity allocated to it, regardless of the weight or the current resource availability.

Let’s illustrate the concept of weight and base with an example to provide a clearer understanding:
Suppose you have three Capacity Providers: A, B, and C, configured as follows:

  • Capacity Provider A has a weight of 4 and a base of 3.
  • Capacity Provider B has a weight of 3 and a base of 1.
  • Capacity Provider C has a weight of 1 and no base value.

Now, consider that you have 10 tasks to be placed within your ECS cluster. Here’s how the allocation works:

Weighted Share:

  • Capacity Provider A, with a weight of 4, gets the largest share of tasks. It receives 4 tasks (40% of 10) because it has the highest weight.
  • Capacity Provider B, with a weight of 3, receives the second-largest share. It gets 3 tasks (30% of 10) based on its weight.
  • Capacity Provider C, with a weight of 1, gets the smallest share. It receives 1 task (10% of 10) based on its weight.

The weighted shares ensure that resources are distributed proportionally according to the weight of each Capacity Provider. However, base values play a crucial role in providing a minimum guaranteed allocation:

Base Guarantee:

  • Capacity Provider A, with a base of 3, always has a minimum of 3 tasks, regardless of its weighted share. This guarantees a stable baseline allocation for Capacity Provider A.
  • Capacity Provider B, with a base of 1, ensures that it always has at least 1 task, even if its weighted share would provide more. This safeguards a basic allocation for Capacity Provider B.
  • Capacity Provider C does not have a base value, so it relies solely on its weighted share. It does not have a guaranteed minimum allocation.

Factors to Keep in Mind with Capacity Providers:

  • You can specify a maximum of six capacity providers when defining a capacity provider strategy.
  • You cannot change a service that uses an Auto Scaling group capacity provider to utilize a Fargate capacity provider, and vice versa.
  • When you define multiple capacity providers within a capacity provider strategy, it is required that at least one of the capacity providers has a weight value greater than zero.
  • Within a capacity provider strategy, it’s important to note that only one capacity provider can have a defined base value. If no base value is specified, the default value of zero is used.

Conclusion:

In summary, Capacity Providers enhance the capabilities of Amazon ECS and are a valuable tool for optimizing containerized workloads in the cloud. The capacity provider also offers a flexible and scalable resource management solution for modern applications. It provides a means to optimize costs by allocating resources based on actual needs, preventing over-provisioning and unnecessary expenses.

Blog Pundits: Prakash Jha and Sandeep Rawat

OpsTree is an End-to-End DevOps Solution Provider.

Connect with Us

Leave a Reply