

# PERF02-BP05 动态扩展计算资源
<a name="perf_compute_hardware_scale_compute_resources_dynamically"></a>

 利用云的弹性根据需求动态增减计算资源，避免为工作负载预置的容量过多或者不足。

 **常见反模式：**
+  通过手动增加容量来对警报做出反应。
+  使用本地所用的规模调整指南（通常是静态基础设施）。
+  在扩展事件之后保留增加的容量，而不是缩减容量。

 **建立此最佳实践的好处：**配置和测试计算资源的弹性将有助于您节省资金、维护性能基准，以及在流量变化时提高可靠性。

 **在未建立这种最佳实践的情况下暴露的风险等级：**高 

## 实施指导
<a name="implementation-guidance"></a>

 AWS 让您能够通过各种扩展机制灵活地动态扩展或缩减资源，以便满足不断变化的需求。动态扩展结合计算相关的指标，可使工作负载自动响应变化，并利用一系列最优的计算资源来实现目标。

 您可以使用大量不同方法来实现资源的供需匹配。
+  **目标跟踪方法**：监控您的扩缩指标，并根据需要自动增加或减少容量。
+  **预测性扩缩**：根据每日和每周的趋势进行扩缩。
+  **基于计划的方法**：根据可预测的负载变化设置自己的扩缩计划。
+  **服务扩缩**：选择可根据设计自动扩缩的服务（如无服务器）。

 您必须确保工作负载部署可以处理扩展事件和缩减事件。

### 实施步骤
<a name="implementation-steps"></a>
+  计算实例、容器和函数都能够与自动扩缩服务相结合或作为此服务的一项功能来提供可实现弹性的机制。以下是自动扩缩机制的一些示例：    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/wellarchitected/latest/framework/perf_compute_hardware_scale_compute_resources_dynamically.html)
+  扩缩通常与计算服务（如 Amazon EC2 实例或 AWS Lambda 函数）相关。此外，务必考虑配置非计算服务（如 [AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/auto-scaling.html)）来满足需求。
+  验证扩缩指标是否与正在部署的工作负载的特性相匹配。如果您正在部署一个视频转码应用程序，预计 CPU 利用率为 100%，但不应将此作为主要指标，而应使用转码作业队列的深度。如果需要，可以对扩缩策略使用[自定义指标](https://aws.amazon.com/blogs/mt/create-amazon-ec2-auto-scaling-policy-memory-utilization-metric-linux/)。要选择正确的指标，请考虑以下关于 Amazon EC2 的指导：
  +  指标应该是有效的利用率指标，并描述实例的繁忙程度。
  +  指标值必须随着自动扩缩组中的实例数按比例增加或减少。
+  确保对自动扩缩组使用[动态扩缩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scale-based-on-demand.html)而不是[手动扩缩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-manual-scaling.html)。我们还建议在动态扩缩中使用[目标跟踪扩缩策略](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-target-tracking.html)。
+  确认工作负载部署可以同时处理扩展事件和缩减事件。例如，可以使用[活动历史记录](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-verify-scaling-activity.html)来验证自动扩缩组的扩缩活动。
+  评估工作负载，得出可预测的模式，从而在预期需求会发生预测性的计划内变化时主动扩缩。预测性扩缩可以避免过度预置容量。有关更多详细信息，请参阅 [Predictive Scaling with Amazon EC2 Auto Scaling](https://aws.amazon.com/blogs/compute/introducing-native-support-for-predictive-scaling-with-amazon-ec2-auto-scaling/)。

## 资源
<a name="resources"></a>

 **相关文档：**
+  [使用 AWS 进行云计算](https://aws.amazon.com/products/compute/) 
+  [Amazon EC2 实例类型](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) 
+  [Amazon ECS 容器：Amazon ECS 容器实例](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_instances.html) 
+  [Amazon EKS 容器：Amazon EKS Worker 节点](https://docs.aws.amazon.com/eks/latest/userguide/worker.html) 
+  [函数：Lambda 函数配置](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html#function-configuration) 
+  [Amazon EC2 实例的处理器状态控制](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/processor_state_control.html) 
+  [Deep Dive on Amazon ECS Cluster Auto Scaling](https://aws.amazon.com/blogs/containers/deep-dive-on-amazon-ecs-cluster-auto-scaling/) 
+  [Introducing Karpenter – An Open-Source High-Performance Kubernetes Cluster Autoscaler](https://aws.amazon.com/blogs/aws/introducing-karpenter-an-open-source-high-performance-kubernetes-cluster-autoscaler/) 

 **相关视频：**
+  [AWS re:Invent 2023 – AWS Graviton: The best price performance for your AWS workloads](https://www.youtube.com/watch?v=T_hMIjKtSr4) 
+  [AWS re:Invent 2023 – New Amazon EC2 generative AI capabilities in AWS Management Console](https://www.youtube.com/watch?v=sSpJ8tWCEiA) 
+  [AWS re:Invent 2023 – What's new with Amazon EC2](https://www.youtube.com/watch?v=mjHw_wgJJ5g) 
+  [AWS re:Invent 2023 – Smart savings: Amazon EC2 cost-optimization strategies](https://www.youtube.com/watch?v=_AHPbxzIGV0) 
+  [AWS re:Invent 2021 – Powering next-gen Amazon EC2: Deep dive on the Nitro System](https://www.youtube.com/watch?v=2uc1vaEsPXU) 
+  [AWS re:Invent 2019 – Amazon EC2 foundations](https://www.youtube.com/watch?v=kMMybKqC2Y0) 

 **相关示例：**
+  [Amazon EC2 Auto Scaling Group Examples](https://github.com/aws-samples/amazon-ec2-auto-scaling-group-examples) 
+  [Amazon EKS 研讨会](https://www.eksworkshop.com/) 
+  [Scale your Amazon EKS workloads by running on IPv6](https://catalog.us-east-1.prod.workshops.aws/workshops/3b06259f-8e17-4f2f-811a-75c9b06a2807/en-US) 