

# 運算與硬體
<a name="a-compute-hardware"></a>

**Topics**
+ [

# PERF 2. 如何在工作負載中選取和使用運算資源？
](perf-02.md)

# PERF 2. 如何在工作負載中選取和使用運算資源？
<a name="perf-02"></a>

 特定工作負載的最佳運算選擇會根據應用程式設計、使用模式和組態設定而有所不同。架構會針對不同元件使用不同運算選擇，並採用不同功能以提升效能。若選錯運算資源，可能使架構的效能達成效率降低。

**Topics**
+ [

# PERF02-BP01 選取最適合您工作負載的運算選項
](perf_compute_hardware_select_best_compute_options.md)
+ [

# PERF02-BP02 了解可用的運算組態和功能
](perf_compute_hardware_understand_compute_configuration_features.md)
+ [

# PERF02-BP03 收集運算相關指標
](perf_compute_hardware_collect_compute_related_metrics.md)
+ [

# PERF02-BP04 設定運算資源並適當調整大小
](perf_compute_hardware_configure_and_right_size_compute_resources.md)
+ [

# PERF02-BP05 動態擴展您的運算資源
](perf_compute_hardware_scale_compute_resources_dynamically.md)
+ [

# PERF02-BP06 使用最佳化的硬體型運算加速器
](perf_compute_hardware_compute_accelerators.md)

# PERF02-BP01 選取最適合您工作負載的運算選項
<a name="perf_compute_hardware_select_best_compute_options"></a>

 為工作負載選擇最合適的運算選項，可讓您改善效能、減少不必要的基礎設施成本，並降低維護工作負載所需的作業工作量。

 **常見的反模式：**
+  您使用曾用於內部部署的同一個運算選項。
+  缺乏對雲端運算選項、特徵以及解決方案，以及那些解決方案可以如何改善運算效能的認識。
+  您在替代運算選項更精確地符合工作負載特性時，過度佈建現有運算選項以符合擴展或效能需求。

 **建立此最佳實務的優勢：**可以透過找出運算需求並根據可用選項進行評估，提高工作負載的資源效率。

 **未建立此最佳實務時的曝險等級：**高 

## 實作指引
<a name="implementation-guidance"></a>

 為了最佳化雲端工作負載以提高效能效率，請務必根據使用案例和效能需求選擇最合適的運算選項。AWS 提供多種運算選項，以滿足雲端中不同工作負載的需求。例如，您可以使用 [Amazon EC2](https://docs.aws.amazon.com/ec2/) 來啟動和管理虛擬伺服器，使用 [AWS Lambda](https://docs.aws.amazon.com/lambda/?icmpid=docs_homepage_featuredsvcs) 來執行程式碼，而不必佈建或管理伺服器，使用 [Amazon ECS](https://aws.amazon.com/ecs/) 或 [Amazon EKS](https://aws.amazon.com/eks/) 執行和管理容器，或者使用 [AWS Batch](https://aws.amazon.com/batch/) 平行處理大量資料。根據擴展和運算需求，您應該根據自己的情況選擇並設定最佳的運算解決方案。也可以考慮在單一工作負載中使用多種類型的運算解決方案，因為每種運算解決方案都有自己的優點和缺點。

 下列步驟會引導您選取正確的運算選項，以符合您的工作負載特性和效能需求。

## 實作步驟
<a name="implementation-steps"></a>
+  了解工作負載運算需求。需要考慮的關鍵需求包括處理需求、流量模式、資料存取模式、擴展需求和延遲需求。
+  了解適用於工作負載的不同 [AWS 運算服務](https://docs.aws.amazon.com/whitepapers/latest/aws-overview/compute-services.html)。如需更多詳細資訊，請參閱 [PERF01-BP01 了解並理解可用的雲端服務和功能](perf_architecture_understand_cloud_services_and_features.md)。以下是一些關鍵的 AWS 運算選項、其特性和常見使用案例：    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/wellarchitected/latest/framework/perf_compute_hardware_select_best_compute_options.html)
+  評估與每個運算選項相關聯的成本 (例如每小時費用或資料傳輸) 和管理開銷 (例如修補和擴展)。
+  在非生產環境中執行實驗和基準測試，以確定哪個運算選項最能滿足您的工作負載需求。
+  在您試驗和找出新的運算解決方案，請規劃遷移並驗證效能指標。
+  使用諸如 [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 的 AWS 監控工具，和諸如 [AWS Compute Optimizer](https://aws.amazon.com/compute-optimizer/) 的最佳化服務，根據實際使用模式持續最佳化運算資源。

 

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

 **相關文件：**
+  [使用 AWS 進行雲端運算](https://aws.amazon.com/products/compute/?ref=wellarchitected) 
+  [Amazon EC2 執行個體類型](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html?ref=wellarchitected) 
+  [Amazon EKS 容器：Amazon EKS 工作節點](https://docs.aws.amazon.com/eks/latest/userguide/worker.html?ref=wellarchitected) 
+  [Amazon ECS 容器：Amazon ECS 容器執行個體](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_instances.html?ref=wellarchitected) 
+  [函數：Lambda 函數組態](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html?ref=wellarchitected#function-configuration) 
+ [容器的規範性指引](https://aws.amazon.com/prescriptive-guidance/?apg-all-cards.sort-by=item.additionalFields.sortText&apg-all-cards.sort-order=desc&awsf.apg-new-filter=*all&awsf.apg-content-type-filter=*all&awsf.apg-code-filter=*all&awsf.apg-category-filter=categories%23containers&awsf.apg-rtype-filter=*all&awsf.apg-isv-filter=*all&awsf.apg-product-filter=*all&awsf.apg-env-filter=*all) 
+  [無伺服器的規範性指引](https://aws.amazon.com/prescriptive-guidance/?apg-all-cards.sort-by=item.additionalFields.sortText&apg-all-cards.sort-order=desc&awsf.apg-new-filter=*all&awsf.apg-content-type-filter=*all&awsf.apg-code-filter=*all&awsf.apg-category-filter=categories%23serverless&awsf.apg-rtype-filter=*all&awsf.apg-isv-filter=*all&awsf.apg-product-filter=*all&awsf.apg-env-filter=*all) 

 **相關影片：**
+  [AWS re:Invent 2023 - AWS Graviton：AWS 工作負載的最佳性價比](https://www.youtube.com/watch?v=T_hMIjKtSr4&ab_channel=AWSEvents) 
+  [AWS re:Invent 2023 - 在 AMS 中新建 Amazon Elastic Compute Cloud 生成式 AI 功能](https://www.youtube.com/watch?v=sSpJ8tWCEiA) 
+  [AWS re:Invent 2023 - Amazon Elastic Compute Cloud 的最新消息](https://www.youtube.com/watch?v=mjHw_wgJJ5g) 
+  [AWS re:Invent 2023 - 智慧型節約：Amazon Elastic Compute Cloud 成本最佳化策略](https://www.youtube.com/watch?v=_AHPbxzIGV0) 
+  [AWS re:Invent 2021 - 為新一代 Amazon Elastic Compute Cloud 提供支援：深入研究 Nitro 系統](https://www.youtube.com/watch?v=2uc1vaEsPXU) 
+  [AWS re:Invent 2019 - 最佳化 AWS 運算的效能和成本](https://www.youtube.com/watch?v=zt6jYJLK8sg) 
+  [AWS re:Invent 2019 - Amazon Elastic Compute Cloud 基礎](https://www.youtube.com/watch?v=kMMybKqC2Y0) 
+  [AWS re:Invent 2022 - 以高效能和低成本部署機器學習 (ML) 模型以進行推論](https://www.youtube.com/watch?v=4FqHt5bmS2o) 
+  [AWS re:Invent 2019 - 最佳化 AWS 運算的效能和成本](https://www.youtube.com/watch?v=zt6jYJLK8sg) 
+  [Amazon EC2 基礎](https://www.youtube.com/watch?v=kMMybKqC2Y0) 
+  [以高效能和低成本部署機器學習 (ML) 模型以進行推論](https://www.youtube.com/watch?v=4FqHt5bmS2o) 

 **相關範例：**
+  [遷移 Web 應用程式至容器](https://application-migration-with-aws.workshop.aws/en/container-migration.html) 
+  [執行 Serverless Hello World](https://aws.amazon.com/getting-started/hands-on/run-serverless-code/) 
+  [Amazon EKS 研討會](https://www.eksworkshop.com/) 
+  [Amazon EC2 研討會](https://ec2spotworkshops.com/) 
+  [使用 Amazon Elastic Compute Cloud 自動擴展實現高效且彈性的工作負載](https://catalog.us-east-1.prod.workshops.aws/workshops/20c57d32-162e-4ad5-86a6-dff1f8de4b3c/en-US) 
+  [透過容器服務遷移至 AWS Graviton](https://catalog.us-east-1.prod.workshops.aws/workshops/dcab7555-32fc-42d2-97e5-2b7a35cd008f/en-US/) 

# PERF02-BP02 了解可用的運算組態和功能
<a name="perf_compute_hardware_understand_compute_configuration_features"></a>

 了解運算服務的可用組態選項和特徵，有助您佈建適量的資源並提高效能效率。

 **常見的反模式：**
+  您沒有根據工作負載特性，評估運算選項或可用的執行個體系列。
+  過度佈建運算資源以符合尖峰需求。

**建立此最佳實務的優勢：**熟悉 AWS 運算功能和組態，以便使用最佳化的運算解決方案，以符合您的工作負載特性和需求。

 **未建立此最佳實務時的曝險等級：**中 

## 實作指引
<a name="implementation-guidance"></a>

 每個運算解決方案都有獨特的組態和功能，以支援不同的工作負載特性和需求。了解這些選項如何與您的工作負載互補，並確定哪種組態選項最適合您的應用程式。這些選項的範例包括執行個體系列、大小、特徵 (GPU、I/O)、爆量、逾時、函數大小、容器執行個體，以及並行。如果您的工作負載使用相同的運算選項超過四週，而且您預期這些特性未來將保持不變，則可以使用 [AWS Compute Optimizer](https://aws.amazon.com/compute-optimizer/) 來確定目前的運算選項是否適合 CPU 和記憶體的工作負載。

## 實作步驟
<a name="implementation-steps"></a>
+  了解工作負載需求 (例如 CPU 需求、記憶體和延遲)。
+  審核 AWS 文件和最佳實務，以了解可協助改善運算效能的建議組態選項。以下是一些需要考慮的關鍵組態選項：    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/wellarchitected/latest/framework/perf_compute_hardware_understand_compute_configuration_features.html)

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

 **相關文件：**
+  [使用 AWS 進行雲端運算](https://aws.amazon.com/products/compute/?ref=wellarchitected) 
+  [Amazon EC2 執行個體類型](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html?ref=wellarchitected) 
+  [Amazon EC2 執行個體的處理器狀態控制](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/processor_state_control.html?ref=wellarchitected) 
+  [Amazon EKS 容器：Amazon EKS 工作節點](https://docs.aws.amazon.com/eks/latest/userguide/worker.html?ref=wellarchitected) 
+  [Amazon ECS 容器：Amazon ECS 容器執行個體](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_instances.html?ref=wellarchitected) 
+  [函數：Lambda 函數組態](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html?ref=wellarchitected#function-configuration) 

 **相關影片：**
+  [AWS re:Invent 2023 – AWS Graviton：AWS 工作負載的最佳價格效能](https://www.youtube.com/watch?v=T_hMIjKtSr4) 
+  [AWS re:Invent 2023 – AWS 管理主控台 中的最新 Amazon EC2 生成式 AI 功能](https://www.youtube.com/watch?v=sSpJ8tWCEiA) 
+  [AWS re:Invent 2023 - Amazon EC2 最新消息](https://www.youtube.com/watch?v=mjHw_wgJJ5g) 
+  [AWS re:Invent 2023 - 智慧型節省：Amazon EC2 成本優化策略](https://www.youtube.com/watch?v=_AHPbxzIGV0) 
+  [AWS re:Invent 2021 – 為新一代 Amazon EC2 提供支援：深入探索 Nitro 系統](https://www.youtube.com/watch?v=2uc1vaEsPXU) 
+  [AWS re:Invent 2019 – Amazon EC2 基礎](https://www.youtube.com/watch?v=kMMybKqC2Y0) 
+  [AWS re:Invent 2022 - 在 AWS 上針對效能和成本最佳化 Amazon EKS](https://www.youtube.com/watch?v=5B4-s_ivn1o) 

 **相關範例：**
+  [運算最佳化工具示範程式碼](https://github.com/awslabs/ec2-spot-labs/tree/master/aws-compute-optimizer) 
+  [Amazon EC2 Spot 執行個體研討會](https://ec2spotworkshops.com/) 
+  [使用 Amazon EC2 AWS Auto Scaling 提供有效且彈性的工作負載](https://catalog.us-east-1.prod.workshops.aws/workshops/20c57d32-162e-4ad5-86a6-dff1f8de4b3c/en-US) 
+  [Graviton 開發人員研討會](https://catalog.us-east-1.prod.workshops.aws/workshops/dcab7555-32fc-42d2-97e5-2b7a35cd008f/en-US/) 
+  [AWS for Microsoft workloads immersion day](https://catalog.us-east-1.prod.workshops.aws/workshops/d6c7ecdc-c75f-4ad1-910f-fdd994cc4aed/en-US) 
+  [AWS for Linux workloads immersion day](https://catalog.us-east-1.prod.workshops.aws/workshops/a8e9c6a6-0ba9-48a7-a90d-378a440ab8ba/en-US) 
+  [AWS Compute Optimizer 示範程式碼](https://github.com/awslabs/ec2-spot-labs/tree/master/aws-compute-optimizer) 
+  [Amazon EKS 研討會](https://www.eksworkshop.com/) 

  

# PERF02-BP03 收集運算相關指標
<a name="perf_compute_hardware_collect_compute_related_metrics"></a>

 記錄並追蹤與運算相關的指標，進一步了解運算資源的效能，並改善效能及使用率。

 **常見的反模式：**
+  您只使用手動日誌檔案來搜尋指標。  
+  您只會使用監控軟體記錄的預設指標。
+  您只會在有問題時審查指標。

 **建立此最佳實務的優勢：**收集效能相關指標有助於使應用程式效能與業務需求保持一致，確保符合工作負載需求。這麼做也可以協助您持續改善工作負載中的資源效能和使用率。

 **未建立此最佳實務時的曝險等級：**高 

## 實作指引
<a name="implementation-guidance"></a>

 雲端工作負載可以產生大量資料，例如指標、日誌和事件。在 中 AWS 雲端，收集指標是改善安全性、成本效益、效能和永續性的重要步驟。 使用 [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) 等監控服務 AWS ，提供廣泛的效能相關指標，為您提供寶貴的洞見。CPU 使用率、記憶體使用率、磁碟 I/O 和網路傳入和傳出等指標可以提供使用率層級或效能瓶頸的洞察。將這些指標納入資料驅動的方法，以主動調整和優化工作負載的資源。  在理想的情況下，應該在單一平台中收集與運算資源相關的所有指標，並實作保留政策以支援成本和營運目標。

## 實作步驟
<a name="implementation-steps"></a>
+  識別與您的工作負載相關的效能相關指標。您應該收集與資源使用率和雲端工作負載運作方式有關的指標 (例如回應時間和輸送量)。
  +  [Amazon EC2 預設指標](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html) 
  +  [Amazon ECS 預設指標](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch-metrics.html) 
  +  [Amazon EKS 預設指標](https://docs.aws.amazon.com/prescriptive-guidance/latest/implementing-logging-monitoring-cloudwatch/kubernetes-eks-metrics.html) 
  +  [Lambda 預設指標](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-access-metrics.html) 
  +  [Amazon EC2記憶體和磁碟指標](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html) 
+  為工作負載選擇並設定合適的日誌記錄和監控解決方案。
  +  [AWS 原生可觀測性](https://catalog.workshops.aws/observability/en-US/aws-native) 
  +  [AWS Distro for OpenTelemetry](https://aws.amazon.com/otel/) 
  +  [Amazon Managed Service for Prometheus](https://docs.aws.amazon.com/grafana/latest/userguide/prometheus-data-source.html) 
+  根據工作負載需求，為指標定義必要的篩選條件和彙總。
  +  [使用 Amazon CloudWatch Logs 和指標篩選條件量化自訂應用程式指標](https://aws.amazon.com/blogs/mt/quantify-custom-application-metrics-with-amazon-cloudwatch-logs-and-metric-filters/) 
  +  [使用 Amazon CloudWatch 策略標記收集自訂指標](https://aws.amazon.com/blogs/infrastructure-and-automation/collect-custom-metrics-with-amazon-cloudwatch-strategic-tagging/) 
+  為指標設定資料保留政策，以符合安全性和營運目標。
  +  [ CloudWatch 指標的預設資料保留](https://aws.amazon.com/cloudwatch/faqs/#AWS_resource_.26_custom_metrics_monitoring) 
  +  [ CloudWatch 日誌的預設資料保留](https://aws.amazon.com/cloudwatch/faqs/#Log_management) 
+  如有必要，為指標建立警示和通知，可協助您主動回應效能相關問題。
  +  [使用 Amazon CloudWatch 異常偵測建立自訂指標的警示](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/create-alarms-for-custom-metrics-using-amazon-cloudwatch-anomaly-detection.html) 
  +  [使用 Amazon 為特定網頁建立指標和警示 CloudWatch RUM](https://aws.amazon.com/blogs/mt/create-metrics-and-alarms-for-specific-web-pages-amazon-cloudwatch-rum/) 
+  使用自動化來部署指標和記錄彙總代理程式。
  +  [AWS Systems Manager 自動化](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html?ref=wellarchitected) 
  +  [OpenTelemetry 收集器](https://aws-otel.github.io/docs/getting-started/collector) 

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

 **相關文件：**
+  [監控與可觀測性](https://aws.amazon.com/cloudops/monitoring-and-observability/) 
+  [最佳實務：使用 實作可觀測性 AWS](https://aws.amazon.com/blogs/mt/best-practices-implementing-observability-with-aws/) 
+  [Amazon CloudWatch 文件](https://docs.aws.amazon.com/cloudwatch/index.html?ref=wellarchitected) 
+  [使用 CloudWatch 代理程式從 Amazon EC2執行個體和內部部署伺服器收集指標和日誌](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html?ref=wellarchitected) 
+  [存取 的 Amazon CloudWatch Logs AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-logs.html?ref=wellarchitected) 
+  [將 CloudWatch 日誌與容器執行個體搭配使用](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_cloudwatch_logs.html?ref=wellarchitected) 
+  [發佈自訂指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html?ref=wellarchitected) 
+  [AWS Answers：集中式日誌記錄](https://aws.amazon.com/answers/logging/centralized-logging/?ref=wellarchitected) 
+  [AWS 發佈 CloudWatch 指標的服務](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CW_Support_For_AWS.html?ref=wellarchitected) 
+  [在 EKS上監控 Amazon AWS Fargate](https://aws.amazon.com/blogs/containers/monitoring-amazon-eks-on-aws-fargate-using-prometheus-and-grafana/) 

 **相關影片：**
+  [AWS re：Invent 2023 – 【LAUNCH】 現代工作負載的應用程式監控](https://www.youtube.com/watch?v=T2TovTLje8w) 
+  [AWS re：Invent 2023 – 實作應用程式可觀測性](https://www.youtube.com/watch?v=IcTcwUSwIs4) 
+  [AWS re：Invent 2023 – 建立有效的可觀測性策略](https://www.youtube.com/watch?v=7PQv9eYCJW8) 
+  [AWS re：Invent 2023 – AWS Distro for 的無縫可觀測性 OpenTelemetry](https://www.youtube.com/watch?v=S4GfA2R0N_A) 
+  [上的應用程式效能管理 AWS](https://www.youtube.com/watch?v=5T4stR-HFas&ref=wellarchitected) 

 **相關範例：**
+  [AWS 適用於 Linux Workloads Immersion Day - Amazon CloudWatch](https://catalog.us-east-1.prod.workshops.aws/workshops/a8e9c6a6-0ba9-48a7-a90d-378a440ab8ba/en-US/300-cloudwatch) 
+  [監控 Amazon ECS叢集和容器](https://ecsworkshop.com/monitoring/) 
+  [使用 Amazon CloudWatch 儀表板進行監控](https://catalog.workshops.aws/well-architected-performance-efficiency/en-US/3-monitoring/monitoring-with-cloudwatch-dashboards) 
+  [Amazon EKS研討會](https://www.eksworkshop.com/) 

# PERF02-BP04 設定運算資源並適當調整大小
<a name="perf_compute_hardware_configure_and_right_size_compute_resources"></a>

 設定運算資源及適當調整其大小，以符合工作負載的效能需求，並避免未充分使用資源或過度使用資源的情況。

 **常見的反模式：**
+  您忽略工作負載效能需求，導致過度佈建或佈建不足的運算資源。
+  您只選擇適用於所有工作負載的最大或最小執行個體。
+  為了方便管理，只能使用一個執行個體系列。
+  您可以忽略來自 AWS Cost Explorer 或 Compute Optimizer 的建議，以適當調整大小。
+  您未重新評估工作負載是否適用於新執行個體類型。
+  您只驗證組織的少量執行個體組態。

 **建立此最佳實務的優勢：**透過避免資源的過度佈建和佈建不足，適當調整運算資源的大小可確保雲端中的最佳操作。適當調整運算資源的大小，通常可以提高效能和增強客戶體驗，同時降低成本。

 **未建立此最佳實務時的曝險等級：**中 

## 實作指引
<a name="implementation-guidance"></a>

 適當調整大小可讓組織以有效率且符合成本效益的方式操作雲端基礎架構，同時滿足其業務需求。過度佈建雲端資源可能會導致額外成本，而佈建不足可能會導致效能不佳和負面的客戶體驗。AWS 可提供 [AWS Compute Optimizer](https://aws.amazon.com/compute-optimizer/) 和 [AWS Trusted Advisor](https://aws.amazon.com/premiumsupport/technology/trusted-advisor/) 等工具，這些工具使用歷史資料提供建議，以適當調整運算資源大小。

### 實作步驟
<a name="implementation-steps"></a>
+  選擇最適合您需求的執行個體類型：
  +  [如何為工作負載選擇適當的 Amazon EC2 執行個體類型？](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-choose-type-for-workload/) 
  +  [Amazon EC2 Fleet 的屬性型執行個體類型選取](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-attribute-based-instance-type-selection.html) 
  +  [使用屬性型執行個體類型選取範圍來建立 Auto Scaling 群組](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-instance-type-requirements.html) 
  +  [利用 Karpenter 整合來最佳化 Kubernetes 運算成本](https://aws.amazon.com/blogs/containers/optimizing-your-kubernetes-compute-costs-with-karpenter-consolidation/) 
+  分析工作負載的各種效能特性，以及這些特性與記憶體、網路和 CPU 用量的關係。使用此資料，可以選擇最適合您工作負載描述檔和效能目標的資源。
+  使用 Amazon CloudWatch 之類的 AWS 監控工具，監控資源使用情況。
+  為運算資源選取適合的組態。
  +  對於臨時工作負載，請評估[執行個體 Amazon CloudWatch 指標](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html)，例如 `CPUUtilization`，來確定執行個體是否未充分使用或使用過度。
  +  對於穩定的工作負載，請定期檢查 AWS 適當調整大小的工具 (例如 AWS Compute Optimizer 和 AWS Trusted Advisor)，以找出對運算資源進行最佳化和適當調整大小的機會。
+  在即時環境中實作之前，先測試非生產環境中的組態變更。
+  持續重新評估新的運算供應項目，並且根據工作負載需求進行比較。

## 資源
<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 工作節點](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) 

 **相關影片：**
+  [Amazon EC2 基礎](https://www.youtube.com/watch?v=kMMybKqC2Y0) 
+  [AWS re:Invent 2023 – AWS Graviton：AWS 工作負載的最佳價格效能](https://www.youtube.com/watch?v=T_hMIjKtSr4) 
+  [AWS re:Invent 2023 – AWS 管理主控台 中的最新 Amazon EC2 生成式 AI 功能](https://www.youtube.com/watch?v=sSpJ8tWCEiA) 
+  [AWS re:Invent 2023 – Amazon EC2 的新功能](https://www.youtube.com/watch?v=mjHw_wgJJ5g) 
+  [AWS re:Invent 2023 - 智慧型節省：Amazon EC2 成本優化策略](https://www.youtube.com/watch?v=_AHPbxzIGV0) 
+  [AWS re:Invent 2021 – 為新一代 Amazon EC2 提供支援：深入探索 Nitro 系統](https://www.youtube.com/watch?v=2uc1vaEsPXU) 
+  [AWS re:Invent 2019 – Amazon EC2 基礎](https://www.youtube.com/watch?v=kMMybKqC2Y0) 

 **相關範例：**
+  [AWS Compute Optimizer 示範程式碼](https://github.com/awslabs/ec2-spot-labs/tree/master/aws-compute-optimizer) 
+  [Amazon EKS 研討會](https://www.eksworkshop.com/) 
+  [適當調整大小的建議](https://catalog.workshops.aws/well-architected-cost-optimization/en-US/3-cost-effective-resources/40-rightsizing-recommendations-100) 

# 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_tw/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)) 以符合需求。
+  確認用於擴展的指標符合要部署之工作負載的特性。如果您要部署影片轉碼應用程式，則預期為 100% CPU 使用率，且不應做為您的主要指標。請改用轉碼任務佇列的深度。您可以將[自訂指標](https://aws.amazon.com/blogs/mt/create-amazon-ec2-auto-scaling-policy-memory-utilization-metric-linux/)用於擴展政策 (如有必要)。若要選擇正確的指標，請考量 Amazon EC2 的下列指引：
  +  指標應為有效的使用率指標，並說明執行個體的忙碌程度。
  +  指標值必須與 Auto Scaling 群組中的執行個體數成比例增加或減少。
+  對於 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)。我們也建議您在動態擴展中使用[目標追蹤擴展政策](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)來驗證 Auto Scaling 群組的擴展活動。
+  評估工作負載以取得可預測模式，並在預計發生預測中的變化和隨需規劃變化時主動擴展。透過預測性擴展，可以消除過度佈建容量的需求。如需詳細資訊，請參閱 [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 工作節點](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) 
+  [深入探討 Amazon ECS 叢集自動擴展](https://aws.amazon.com/blogs/containers/deep-dive-on-amazon-ecs-cluster-auto-scaling/) 
+  [介紹 Karpenter - 一個開放原始碼的高效能 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：AWS 工作負載的最佳價格效能](https://www.youtube.com/watch?v=T_hMIjKtSr4) 
+  [AWS re:Invent 2023 – AWS 管理主控台中的全新 Amazon EC2 生成式 AI 功能](https://www.youtube.com/watch?v=sSpJ8tWCEiA) 
+  [AWS re:Invent 2023 – Amazon EC2 的新功能](https://www.youtube.com/watch?v=mjHw_wgJJ5g) 
+  [AWS re:Invent 2023 - 智慧型節省：Amazon EC2 成本優化策略](https://www.youtube.com/watch?v=_AHPbxzIGV0) 
+  [AWS re:Invent 2021 – 為新一代 Amazon EC2 提供支援：深入探索 Nitro 系統](https://www.youtube.com/watch?v=2uc1vaEsPXU) 
+  [AWS re:Invent 2019 – Amazon EC2 基礎](https://www.youtube.com/watch?v=kMMybKqC2Y0) 

 **相關範例：**
+  [Amazon EC2 Auto Scaling 群組範例](https://github.com/aws-samples/amazon-ec2-auto-scaling-group-examples) 
+  [Amazon EKS 研討會](https://www.eksworkshop.com/) 
+  [透過在 IPv6 上執行來擴展您的 Amazon EKS 工作負載](https://catalog.us-east-1.prod.workshops.aws/workshops/3b06259f-8e17-4f2f-811a-75c9b06a2807/en-US) 

# PERF02-BP06 使用最佳化的硬體型運算加速器
<a name="perf_compute_hardware_compute_accelerators"></a>

 使用硬體加速器執行特定功能，比以 CPU 為基礎的替代方案更有效率。

 **常見的反模式：**
+  在工作負載中，您尚未基準化分析一般用途執行個體和專用執行個體，而專用執行個體可以改善效能和降低成本。
+  您使用硬體型運算加速器來執行任務，比起使用以 CPU 為基礎的替代方案更有效率。
+  未監控 GPU 使用率。

**建立此最佳實務的優勢：**透過使用硬體型加速器，例如圖形處理單元 (GPU) 和現場可程式化閘道陣列 (FPGA)，您就可以更有效率地執行特定處理功能。

 **未建立此最佳實務時的曝險等級：**中 

## 實作指引
<a name="implementation-guidance"></a>

 加速運算執行個體可讓您存取硬體型運算加速器，例如 GPU 和 FPGA。這些硬體加速器比基於 CPU 的替代品更有效地執行某些功能，例如圖形處理或資料模式匹配。許多加速的工作負載 (例如轉譯、轉碼和機器學習) 在資源使用方面變化很大。只在需要時執行此硬體，並在不需要時自動停用它們，以提高整體效能的效率。

### 實作步驟
<a name="implementation-steps"></a>
+  確定哪些[加速運算執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/accelerated-computing-instances.html)可以滿足您的需求。
+  針對機器學習工作負載，請利用專供工作負載使用的專用硬體，例如 [AWS Trainium](https://aws.amazon.com/machine-learning/trainium/)、[AWS Inferentia](https://aws.amazon.com/machine-learning/inferentia/) 和 [Amazon EC2 DL1](https://aws.amazon.com/ec2/instance-types/dl1/)。AWS與同類 Amazon EC2 執行個體相比，Inferentia 執行個體 (例如 Inf2 執行個體) [所提供的效能功耗比要高出 50%](https://aws.amazon.com/machine-learning/inferentia/)。
+  收集加速運算執行個體的用量指標。例如，可以使用 CloudWatch 代理程式為您的 GPU 收集 `utilization_gpu` 和 `utilization_memory` 等指標，如[使用 Amazon CloudWatch 收集 NVIDIA GPU 指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-NVIDIA-GPU.html)中所示。
+  優化硬體加速器的程式碼、網路運作和設定，以確保系統會充分利用基礎硬體。
  +  [最佳化 GPU 設定](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/optimize_gpu.html) 
  +  [深度學習 AMI 中的 GPU 監控和最佳化](https://docs.aws.amazon.com/dlami/latest/devguide/tutorial-gpu.html) 
  +  [將 I/O 最佳化以針對 Amazon SageMaker AI 中的深度學習訓練進行 GPU 效能調校](https://aws.amazon.com/blogs/machine-learning/optimizing-i-o-for-gpu-performance-tuning-of-deep-learning-training-in-amazon-sagemaker/) 
+  使用最新的高效能程式庫和 GPU 驅動程式。
+  使用自動化來釋出不使用的 GPU 執行個體。

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

 **相關文件：**
+  [在 Amazon Elastic Container Service 上使用 GPU](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-gpu.html) 
+  [GPU 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/accelerated-computing-instances.html#gpu-instances) 
+  [AWS Trainium 的執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/accelerated-computing-instances.html#aws-trainium-instances) 
+  [AWS Inferentia 的執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/accelerated-computing-instances.html#aws-inferentia-instances) 
+  [開始建構吧！使用自訂晶片和加速器來進行建構](https://aws.amazon.com/blogs/architecture/lets-architect-custom-chips-and-accelerators/) 
+  [加速運算](https://aws.amazon.com/ec2/instance-types/#Accelerated_Computing) 
+  [Amazon EC2 VT1 執行個體](https://aws.amazon.com/ec2/instance-types/vt1/) 
+  [如何為工作負載選擇適當的 Amazon EC2 執行個體類型？](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-choose-type-for-workload/) 
+  [選擇最佳 AI 加速器和模型編譯來以 Amazon SageMaker AI 推斷電腦視覺](https://aws.amazon.com/blogs/machine-learning/choose-the-best-ai-accelerator-and-model-compilation-for-computer-vision-inference-with-amazon-sagemaker/) 

 **相關影片：**
+  AWS re:Invent 2021 - [如何選擇 Amazon Elastic Compute Cloud GPU 執行個體進行深度學習](https://www.youtube.com/watch?v=4bVrIbgGWEA&ab_channel=AWSEvents) 
+  [AWS re:Invent 2022 - [最新發佈！] 介紹基於 AWS Inferentia2 的 Amazon EC2 Inf2 執行個體](https://www.youtube.com/watch?v=jpqiG02Y2H4&ab_channel=AWSEvents) 
+  [AWS re:Invent 2022 - 使用 AWS Trainium 加速深度學習並加快創新速度](https://www.youtube.com/watch?v=YRqvfNwqUIA&ab_channel=AWSEvents) 
+  [AWS re:Invent 2022 - 透過 NVIDIA 在 AWS 上進行深度學習：從訓練到部署](https://www.youtube.com/watch?v=l8AFfaCkp0E&ab_channel=AWSEvents) 

 **相關範例：**
+  [Amazon SageMaker AI 和 NVIDIA GPU Cloud (NGC)](https://github.com/aws-samples/amazon-sagemaker-nvidia-ngc-examples) 
+  [搭配使用 SageMaker AI 與 Trainium 和 Inferentia，進行最佳化的深度學習訓練和推論工作負載](https://github.com/aws-samples/sagemaker-trainium-inferentia) 
+  [使用 Amazon SageMaker AI 中的 Amazon Elastic Compute Cloud Inf1 執行個體最佳化 NLP 模型](https://github.com/aws-samples/aws-inferentia-huggingface-workshop) 