PERF02-BP05 Scale your compute resources dynamically
Use the elasticity of the cloud to scale your compute resources up or down dynamically to match your needs and avoid over- or under-provisioning capacity for your workload.
Common anti-patterns:
-
You react to alarms by manually increasing capacity.
-
You use the same sizing guidelines (generally static infrastructure) as in on-premises.
-
You leave increased capacity after a scaling event instead of scaling back down.
Benefits of establishing this best practice: Configuring and testing the elasticity of compute resources can help you save money, maintain performance benchmarks, and improve reliability as traffic changes.
Level of risk exposed if this best practice is not established: High
Implementation guidance
AWS provides the flexibility to scale your resources up or down dynamically through a variety of scaling mechanisms in order to meet changes in demand. Combined with compute-related metrics, a dynamic scaling allows workloads to automatically respond to changes and use the optimal set of compute resources to achieve its goal.
You can use a number of different approaches to match supply of resources with demand.
-
Target-tracking approach: Monitor your scaling metric and automatically increase or decrease capacity as you need it.
-
Predictive scaling: Scale in anticipation of daily and weekly trends.
-
Schedule-based approach: Set your own scaling schedule according to predictable load changes.
-
Service scaling: Choose services (like serverless) that that automatically scale by design.
You must ensure that workload deployments can handle both scale-up and scale-down events.
Implementation steps
-
Compute instances, containers, and functions provide mechanisms for elasticity, either in combination with autoscaling or as a feature of the service. Here are some examples of automatic scaling mechanisms:
Autoscaling Mechanism Where to use Amazon EC2 Auto Scaling To ensure you have the correct number of Amazon EC2 instances available to handle the user load for your application. Application Auto Scaling To automatically scale the resources for individual AWS services beyond Amazon EC2 such as AWS Lambda functions or Amazon Elastic Container Service (Amazon ECS) services. Kubernetes Cluster Autoscaler/Karpenter To automatically scale Kubernetes clusters. -
Scaling is often discussed related to compute services like Amazon EC2 Instances or AWS Lambda functions. Be sure to also consider the configuration of non-compute services like AWS Glue to match the demand.
-
Verify that the metrics for scaling match the characteristics of the workload being deployed. If you are deploying a video transcoding application, 100% CPU utilization is expected and should not be your primary metric. Use the depth of the transcoding job queue instead. You can use a customized metric
for your scaling policy if required. To choose the right metrics, consider the following guidance for Amazon EC2: -
The metric should be a valid utilization metric and describe how busy an instance is.
-
The metric value must increase or decrease proportionally to the number of instances in the Auto Scaling group.
-
-
Make sure that you use dynamic scaling instead of manual scaling for your Auto Scaling group. We also recommend that you use target tracking scaling policies in your dynamic scaling.
-
Verify that workload deployments can handle both scaling events (up and down). As an example, you can use Activity history to verify a scaling activity for an Auto Scaling group.
-
Evaluate your workload for predictable patterns and proactively scale as you anticipate predicted and planned changes in demand. With predictive scaling, you can eliminate the need to overprovision capacity. For more detail, see Predictive Scaling with Amazon EC2 Auto Scaling
.
Resources
Related documents:
Related videos:
-
AWS re:Invent 2023 – AWS Graviton: The best price performance for your AWS workloads
-
AWS re:Invent 2023 – New Amazon EC2 generative AI capabilities in AWS Management Console
-
AWS re:Invent 2023 – Smart savings: Amazon EC2 cost-optimization strategies
-
AWS re:Invent 2021 – Powering next-gen Amazon EC2: Deep dive on the Nitro System
Related examples: