

# SUS02-BP01 扩缩基础设施以匹配用户负载
<a name="sus_sus_user_a2"></a>

 确定利用率低或无利用率的时段，缩减资源以消除过剩容量并提高效率。 

**常见反模式：**
+ 您没有扩缩基础设施以匹配用户负载。
+ 您一直在手动扩缩基础设施。
+ 在扩展事件之后，您将保留增加的容量，而不是缩减容量。

 **建立此最佳实践的好处：** 配置和测试工作负载弹性将有助于减小工作负载环境影响，节省资金，并维护性能基准。您可以利用云中的弹性，在用户负载峰值期间和之后自动扩缩容量，以确保只使用满足客户需求所需的确切数量的资源。

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

## 实施指导
<a name="implementation-guidance"></a>
+  弹性可根据对您拥有的资源的需求来提供这些资源。实例、容器和函数都能够与自动扩展功能相结合或作为此服务的一项功能来提供可实现弹性的机制。在架构中使用弹性，以确保在用户负载较低的时期，可以快速轻松地缩减工作负载： 
  +  使用 [Amazon EC2 Auto Scaling](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html) 验证您拥有适量的 Amazon EC2 实例，可处理您应用程序的用户负载。 
  +  使用 [Application Auto Scaling](https://docs.aws.amazon.com/autoscaling/application/userguide/what-is-application-auto-scaling.html) 自动扩缩 Amazon EC2 以外的各项 AWS 服务的资源，比如 Lambda 函数或 Amazon Elastic Container Service (Amazon ECS) 服务。 
  +  使用 [Kubernetes Cluster Autoscaler](https://aws.amazon.com/blogs/aws/introducing-karpenter-an-open-source-high-performance-kubernetes-cluster-autoscaler/) 自动扩缩 AWS 上的 Kubernetes 集群。 
+  验证衡量扩展或缩减的指标已根据所部署的工作负载类型进行了验证。如果您正在部署一个视频转码应用程序，CPU 利用率预计为 100%，并且不应将此作为您的主要指标。如果需要，您可以为您的扩缩策略使用一个 [自定义指标](https://aws.amazon.com/blogs/mt/create-amazon-ec2-auto-scaling-policy-memory-utilization-metric-linux/) （如内存利用率）。要选择正确的指标，请考虑以下关于 Amazon EC2 的指导： 
  +  该指标应该是有效的利用率指标，并描述实例的繁忙程度。 
  +  该指标值必须随 Auto Scaling 组中的实例数量成比例地增加或减少。 
+  使用 [动态扩展](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) （对于 Auto Scaling 组）。我们还建议您在动态扩展中使用 [目标跟踪扩缩策略](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-target-tracking.html) 。 
+  验证工作负载部署可以处理扩展事件和缩减事件。创建缩减事件的测试方案，以确保工作负载按预期方式运行。您可以使用 **活动历史记录** 来测试和验证 Auto Scaling 组的扩缩活动。 
+  评估您的工作负载以获得可预测的模式，并在您预期需求会发生预测和计划的变化时主动扩缩。使用 [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>

 **相关文档：** 
+  [开始使用 Amazon EC2 Auto Scaling](https://docs.aws.amazon.com/autoscaling/ec2/userguide/GettingStartedTutorial.html) 
+  [由机器学习提供支持的 EC2 预测式扩缩](https://aws.amazon.com/blogs/aws/new-predictive-scaling-for-ec2-powered-by-machine-learning/) 
+  [使用 Amazon OpenSearch Service、Amazon Data Firehose 和 Kibana 分析用户行为](https://aws.amazon.com/blogs/database/analyze-user-behavior-using-amazon-elasticsearch-service-amazon-kinesis-data-firehose-and-kibana/) 
+  [什么是 Amazon CloudWatch？](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 
+  [什么是 AWS X-Ray？](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html) 
+  [VPC 流日志](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html) 
+  [在 Amazon RDS 上使用 Performance Insights 监控数据库负载](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PerfInsights.html) 
+  [介绍对 Amazon EC2 Auto Scaling 预测式扩缩的原生支持](https://aws.amazon.com/blogs/compute/introducing-native-support-for-predictive-scaling-with-amazon-ec2-auto-scaling/) 
+  [如何基于内存利用率指标创建 Amazon EC2 Auto Scaling 策略（Linux）](https://aws.amazon.com/blogs/mt/create-amazon-ec2-auto-scaling-policy-memory-utilization-metric-linux/) 
+  [介绍 Karpenter - 高性能开源 Kubernetes Cluster Autoscaler](https://aws.amazon.com/blogs/aws/introducing-karpenter-an-open-source-high-performance-kubernetes-cluster-autoscaler/) 

 **相关视频：** 
+  [更好、更快、更便宜的计算：Amazon EC2 成本优化（CMP202-R1）](https://www.youtube.com/watch?v=_dvh4P2FVbw) 

 **相关示例：** 
+  实验室：Amazon EC2 Auto Scaling 组示例 
+  [实验室：使用 Karpenter 实施自动扩展](https://www.eksworkshop.com/beginner/085_scaling_karpenter/) 