

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 4 - 超過隨需輸送量上限
<a name="throttling-ondemand-capacity-exceeded-mitigation"></a>

當您設定[隨需](on-demand-capacity-mode.md)資料表或 GSI 時，可選擇在資料表或索引層級設定最大輸送量上限 ([https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxReadRequestUnits](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxReadRequestUnits) 和 [https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxWriteRequestUnits](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxWriteRequestUnits))，以防止成本失控，或避免下游系統因流量過大而超載。如需最大輸送量上限的詳細資訊，請參閱 [DynamoDB 隨需資料表的最大輸送量](on-demand-capacity-mode-max-throughput.md)。

 當讀取或寫入耗用量超出這些自訂限制時，超出部分的其他請求會收到即時限流回應。DynamoDB 會傳回含有 `MaxOnDemandThroughputExceeded` 限流原因類型的例外狀況，用以指出已達輸送量界限的資源。

## 超出限流的隨需輸送量上限
<a name="throttling-ondemand-maximum-exceeded"></a>

本節提供超出限流案例的隨需最大輸送量的解析指引。使用本指南前，請先從應用程式的例外狀況處理中確認具體的限流原因，並確定受影響資源的 Amazon Resource Name (ARN)。如需了解如何擷取限流原因並識別遭限流的資源，請參閱 [DynamoDB 限流診斷架構](throttling-diagnosing-workflow.md#throttling-diagnosing)。

在深入分析特定限流情境前，請先評估是否真的需要採取行動：
+ **評估您的最大輸送量上限設定：**這些限制是為了控制成本或保護下游系統而刻意設定的。如果您收到 `MaxOnDemandThroughputExceeded` 限流事件，代表您的限制正在依設計運作。評估提高這些限制是否符合原先的成本控制或系統保護目標。
+ **評估應用程式影響：**確認限流是否確實影響您的應用程式或使用者。若您的應用程式能有效處理重試，且在偶發限流下仍符合效能需求，維持現有限制可能是最佳選項。
+ **檢視流量模式：**分析限流是否屬於預期的流量行為或異常高峰。對於可預測且持續超出限制的週期性流量模式，建議調整最大輸送量上限設定。若為暫時性高峰，實作更佳的請求分散策略可能比提升限制更為合宜。

若評估後確認需調整最大輸送量上限設定，請參閱以下特定限流情境，以取得對應的修正方案：
+ [TableReadMaxOnDemandThroughputExceeded](#throttling-diagnostic-table-read-max-ondemand) 
+ [TableWriteMaxOnDemandThroughputExceeded](#throttling-diagnostic-table-write-max-ondemand)
+ [IndexReadMaxOnDemandThroughputExceeded](#throttling-diagnostic-index-read-max-ondemand) 
+ [IndexWriteMaxOnDemandThroughputExceeded](#throttling-diagnostic-index-write-max-ondemand) 

### TableReadMaxOnDemandThroughputExceeded
<a name="throttling-diagnostic-table-read-max-ondemand"></a>

**發生這種情況時**  
您的隨需模式資料表已超出其設定的最大讀取輸送容量上限。可透過 [常見診斷與監控](#ondemand-capacity-exceeded-diagnosis-monitoring) 監控 CloudWatch 指標，以分析限流事件。

**修正方案**  
可參考以下步驟處理限流事件：
+ **提高最大輸送量上限：**使用 [DynamoDB 主控台](https://console.aws.amazon.com/dynamodb)、[AWS CLI](/amazondynamodb/latest/developerguide/AccessingDynamoDB.html#Tools.CLI) 或 DynamoDB `[UpdateTable](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_UpdateTable.html)` API 來提高受影響資料表的 [https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxReadRequestUnits](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxReadRequestUnits) 值，再進行監控與調整。這可讓資料表在發生限流前處理更高的讀取輸送量。
+ **移除上限：**將 `MaxReadRequestUnits` 設定為 `-1`，以移除上限，允許依需求擴展至帳戶層級輸送量配額。這將移除自訂限制，但仍保留 AWS的帳戶層級防護機制。不過，移除此限制後請密切監控支出，因為資料表在達到帳戶層級配額前可能耗用顯著更多的容量。

### TableWriteMaxOnDemandThroughputExceeded
<a name="throttling-diagnostic-table-write-max-ondemand"></a>

**發生這種情況時**  
您的隨需模式資料表已超出其設定的最大寫入輸送容量上限。可透過 [常見診斷與監控](#ondemand-capacity-exceeded-diagnosis-monitoring) 監控 CloudWatch 指標，以分析限流事件。

**修正方案**  
可參考以下步驟處理限流事件：
+ **提高最大輸送量上限：**使用 [DynamoDB 主控台](https://console.aws.amazon.com/dynamodb)、[AWS CLI](/amazondynamodb/latest/developerguide/AccessingDynamoDB.html#Tools.CLI) 或 DynamoDB `[UpdateTable](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_UpdateTable.html)` API 來提高受影響資料表的 [https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxWriteRequestUnits](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxWriteRequestUnits) 值，再進行監控與調整。
+ **移除上限：**將 `MaxWriteRequestUnits` 設定為 `-1`，以移除上限，允許依需求擴展至帳戶層級輸送量配額。這將移除自訂限制，但仍保留 AWS的帳戶層級防護機制。不過，移除此限制後請密切監控支出，因為資料表在達到帳戶層級配額前可能耗用顯著更多的容量。

### IndexReadMaxOnDemandThroughputExceeded
<a name="throttling-diagnostic-index-read-max-ondemand"></a>

**發生這種情況時**  
在隨需模式中，對 GSI 的讀取請求已超出其設定的最大讀取輸送容量上限。可透過 [常見診斷與監控](#ondemand-capacity-exceeded-diagnosis-monitoring) 監控 CloudWatch 指標，以分析限流事件。

**修正方案**  
可參考以下步驟處理限流事件：
+ **提高 GSI 最大輸送量上限：**使用 [DynamoDB 主控台](https://console.aws.amazon.com/dynamodb)、[AWS CLI](/amazondynamodb/latest/developerguide/AccessingDynamoDB.html#Tools.CLI) 或 DynamoDB `[UpdateTable](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_UpdateTable.html)` API 來提高受影響 GSI 的 [https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxReadRequestUnits](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxReadRequestUnits) 值，然後進行監控與調整。
+ **移除 GSI 上限：**將 GSI 的 `MaxReadRequestUnits` 設定為 `-1`，以移除上限，允許依需求擴展至帳戶層級輸送量配額。這會移除您的自訂限制，但仍維持 AWS帳戶層級的保護。不過，移除此限制後請密切監控支出。

### IndexWriteMaxOnDemandThroughputExceeded
<a name="throttling-diagnostic-index-write-max-ondemand"></a>

**發生這種情況時**  
當基礎資料表項目的更新在隨需模式下觸發對 GSI 的寫入，超出其設定的最大寫入輸送容量上限時，會導致[背壓限流](gsi-throttling.md)。可透過 [常見診斷與監控](#ondemand-capacity-exceeded-diagnosis-monitoring) 監控 CloudWatch 指標，以分析限流事件。

**修正方案**  
可參考以下步驟處理限流事件：
+ **提高 GSI 最大輸送量上限：**使用 [DynamoDB 主控台](https://console.aws.amazon.com/dynamodb)、[AWS CLI](/amazondynamodb/latest/developerguide/AccessingDynamoDB.html#Tools.CLI) 或 DynamoDB `[UpdateTable](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_UpdateTable.html)` API 來提高受影響 GSI 的 [https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxWriteRequestUnits](https://docs.aws.amazon.com//amazondynamodb/latest/APIReference/API_OnDemandThroughput.html#DDB-Type-OnDemandThroughput-MaxWriteRequestUnits) 值，然後進行監控與調整。
+ **移除 GSI 上限：**將 GSI 的 `MaxWriteRequestUnits` 設定為 `-1`，以移除上限，允許依需求擴展至帳戶層級輸送量配額。這會移除您的自訂限制，但仍維持 AWS帳戶層級的保護。不過，移除此限制後請密切監控支出。

## 常見診斷與監控
<a name="ondemand-capacity-exceeded-diagnosis-monitoring"></a>

當對隨需輸送量超過限流事件進行疑難排解時，數個 CloudWatch 指標有助於識別根本原因和擴展模式。

**主要 CloudWatch 指標**  
監控這些關鍵指標，以診斷超出限流的隨需最大輸送量：
+ **最大輸送量限流事件：**[https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#ReadMaxOnDemandThroughputThrottleEvents](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#ReadMaxOnDemandThroughputThrottleEvents) 與 [https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#WriteMaxOnDemandThroughputThrottleEvents](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#WriteMaxOnDemandThroughputThrottleEvents) 用於追蹤因超出上限而被限流的請求；[https://docs.aws.amazon.com//amazondynamodb/latest/developerguide/metrics-dimensions.html#ReadThrottleEvents](https://docs.aws.amazon.com//amazondynamodb/latest/developerguide/metrics-dimensions.html#ReadThrottleEvents) 與 [https://docs.aws.amazon.com//amazondynamodb/latest/developerguide/metrics-dimensions.html#WriteThrottleEvents](https://docs.aws.amazon.com//amazondynamodb/latest/developerguide/metrics-dimensions.html#WriteThrottleEvents) 則追蹤任何超出佈建容量的讀寫請求。
+ **資料表或全域次要索引目前設定的最大輸送量上限：**[https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#OnDemandMaxReadRequestUnits](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#OnDemandMaxReadRequestUnits) 與 [https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#OnDemandMaxWriteRequestUnits](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#OnDemandMaxWriteRequestUnits) 顯示現行的最大容量限制。
+ **實際容量耗用情形：**[https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#ConsumedReadCapacityUnits](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#ConsumedReadCapacityUnits) 與 [https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#ConsumedWriteCapacityUnits](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#ConsumedWriteCapacityUnits) 顯示實際使用模式。

**分析步驟**  
請依照下列步驟確認隨需輸送量超過診斷上限：

1. 比較已耗用容量與最大容量上限，檢查耗用量是否持續接近或超出上限。

1. 檢視限流事件的頻率與發生時間，以辨識模式。檢查是否有與限流事件同時出現的耗用容量急增。

1. 使用 [CloudWatch Contributor Insights](contributorinsights_HowItWorks.md) 以識別耗用容量最高的項目或分割區索引鍵。