

# 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) 自動將個別 AWS 服務的資源擴展到 Amazon EC2 以外，例如 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 叢集。 
+  確認會對要部署的工作負載類型驗證擴充或縮減規模的指標。如果您要部署影片轉碼應用程式，則預期為 100% CPU 使用率，且不應做為您的主要指標。您可以將 [自訂指標](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 Flow Logs](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/) 