

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

# 為 Amazon Keyspaces 中的資料表設定預熱
<a name="warm-throughput"></a>

Amazon Keyspaces 會根據隨需或佈建的輸送量自動擴展儲存分割區，但對於新資料表或突然的輸送量峰值，配置所需的儲存分割區可能需要更長的時間。若要確保新的或現有的資料表有足夠的容量來支援預期的尖峰輸送量，您可以手動設定特定的*暖輸送量*值來*預先暖機*資料表。

*暖輸送量*是指 Amazon Keyspaces 資料表可立即支援的讀取和寫入操作數量。這些值預設為適用於所有新的和現有的資料表。如果您使用隨需模式，或更新佈建輸送量，Amazon Keyspaces 會確保您的應用程式能夠立即發出高達這些值的請求。

Amazon Keyspaces 會在用量增加時自動調整暖輸送量值。若要調整即將到來的尖峰事件的輸送量容量，例如當您從另一個資料庫遷移資料時，可能需要在短時間內載入 TB 的資料時，您可以手動增加資料表的暖輸送量值。這適用於計劃的尖峰事件，其中請求率可能會增加 10 倍、100 倍或更多。首先，評估目前的暖輸送量是否足以處理預期的流量。然後，如果您需要為計劃的尖峰工作負載預先暖機資料表，您可以手動增加暖輸送量值，而無需變更輸送量設定或[容量模式](ReadWriteCapacityMode.md)。

您可以預熱讀取操作、寫入操作或兩者的資料表。您可以為新的和現有的單一區域資料表和多區域資料表增加此值，而且您設定的暖輸送量設定會自動套用至多區域資料表的所有複本。您可以隨時預先暖機的 Amazon Keyspaces 資料表數量沒有限制。完成預熱的時間取決於您設定的值和資料表的大小。您可以同時提交預熱請求，這些請求不會干擾任何資料表操作。您可以將資料表預熱到該區域中帳戶的資料表配額限制。使用 [Service Quotas 主控台](https://console.aws.amazon.com/servicequotas)來檢查您目前的配額，並視需要增加配額。

Amazon Keyspaces 根據隨需用量或佈建容量調整的暖輸送量值，預設適用於所有資料表，無需額外費用。不過，如果您手動將預設暖輸送量值增加到尖峰流量事件的預暖資料表，則需支付額外費用。如需詳細資訊，請參閱 [Amazon Keyspaces 定價](https://aws.amazon.com/keyspaces/pricing/)。

以下是預暖 Amazon Keyspaces 資料表時可能會考慮的一些不同案例和最佳實務。

## 暖輸送量與非均勻存取模式
<a name="warm-throughput-scenarios-uneven"></a>

資料表的暖輸送量可能是每秒 30，000 個讀取單位和每秒 10，000 個寫入單位，但在達到這些值之前，您仍然可能會在讀取或寫入時遇到超過事件的容量。這通常是因為存在熱分割區造成。雖然 Amazon Keyspaces 可以繼續擴展以支援幾乎無限制的輸送量，但每個分割區每秒僅限 1，000 個寫入單位和每秒 3，000 個讀取單位。如果您的應用程式對資料表的一小部分分割區驅動太多流量，即使達到資料表的暖輸送量值，容量也會超過事件。我們建議您遵循 [Amazon Keyspaces 最佳實務](bp-partition-key-design.md)，以確保無縫的可擴展性並避免熱分割區。

## 佈建資料表的暖輸送量
<a name="warm-throughput-scenarios-provisioned"></a>

假設佈建資料表的暖輸送量為每秒 30，000 個讀取單位和每秒 10，000 個寫入單位，但目前佈建輸送量為 4，000 RCUs 和 8，000 WCUs。您可以透過更新佈建的輸送量設定，立即將資料表的佈建輸送量擴展到 30，000 RCUs 或 10，000 個 WCUs。當您增加佈建輸送量超過這些值時，暖輸送量會自動調整為新的更高值，因為您已建立新的尖峰輸送量。例如，如果您將佈建的輸送量設定為 50，000 個 RCU，暖輸送量會提高到每秒 50，000 個讀取單位。

```
"ProvisionedThroughput": 
    {
        "ReadCapacityUnits": 4000,
        "WriteCapacityUnits": 8000 
    }
"WarmThroughput": 
    { 
        "ReadUnitsPerSecond": 30000,
        "WriteUnitsPerSecond": 10000
    }
```

## 隨需資料表的暖輸送量
<a name="warm-throughput-scenarios-ondemand"></a>

新建立的隨需資料表初始暖輸送量為每秒 12,000 個讀取單位與每秒 4,000 個寫入單位。資料表可立即支援持續流量，最高可達上述層級。當您的請求超過每秒 12，000 個讀取單位或每秒 4，000 個寫入單位時，暖輸送量會自動調整為較高的值。

```
"WarmThroughput": 
    { 
        "ReadUnitsPerSecond": 12000,
        "WriteUnitsPerSecond": 4000
    }
```

## 預熱 Amazon Keyspaces 資料表的最佳實務
<a name="prewarming-best-practices"></a>

為 Amazon Keyspaces 資料表實作預熱時，請遵循下列最佳實務：

準確估計所需的容量  
由於預熱會產生一次性成本，請根據預期的工作負載仔細計算所需的輸送量，以避免過度佈建。

考慮資料表的結構描述  
資料列較大的資料表可能需要更多分割區才能達到相同的輸送量。估算預熱前需求時，請考量平均資料列大小。

監控資料表效能  
預熱後，請使用 CloudWatch 指標來驗證您的資料表是否如預期處理負載。如需詳細資訊，請參閱[使用 Amazon CloudWatch 監控預暖資料表的效能](monitor-prewarming-cloudwatch.md)。

管理配額  
如果您的應用程式需要高於預設配額允許 (40，000 個 RCUs/WCUs或 2，000 個分割區） 的輸送量，則請求配額會在高流量事件之前大幅增加。若要請求提升配額，您可以使用 [Service Quotas 主控台](https://console.aws.amazon.com/servicequotas)。

最佳化成本  
對於暫時高流量事件，請考慮使用預熱，而不是切換到具有高容量的佈建模式，因為它在短期事件中可能更具成本效益。如需定價的詳細資訊，請參閱 [Amazon Keyspaces 定價](https://aws.amazon.com/keyspaces/pricing/)。

**注意**  
在測試階段監控應用程式的效能指標，以驗證預暖組態是否充分支援工作負載需求。

**Topics**
+ [暖輸送量與非均勻存取模式](#warm-throughput-scenarios-uneven)
+ [佈建資料表的暖輸送量](#warm-throughput-scenarios-provisioned)
+ [隨需資料表的暖輸送量](#warm-throughput-scenarios-ondemand)
+ [預熱 Amazon Keyspaces 資料表的最佳實務](#prewarming-best-practices)
+ [建立暖輸送量較高的新 Amazon Keyspaces 資料表](create-table-warm-throughput.md)
+ [提高現有 Amazon Keyspaces 資料表的暖輸送量](update-warm-throughput.md)
+ [檢視 Amazon Keyspaces 資料表的暖輸送量](view-warm-throughput.md)
+ [使用 Amazon CloudWatch 監控預暖資料表的效能](monitor-prewarming-cloudwatch.md)

# 建立暖輸送量較高的新 Amazon Keyspaces 資料表
<a name="create-table-warm-throughput"></a>

您可以使用主控台、CQL 或 ，在建立 Amazon Keyspaces 資料表時調整暖輸送量值 AWS CLI。

------
#### [ Console ]

**如何使用熱輸送量設定建立新的資料表**

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home) 開啟 Amazon Keyspaces 主控台。

1. 在導覽窗格中，選擇 **Tables** (資料表)，然後選擇 **Create table** (建立資料表)。

1. 在**資料表詳細資訊區段的建立**資料表頁面上，選取金鑰空間，並提供新資料表的名稱。 ****

1. 在**資料欄**區段中，建立資料表的結構描述。

1. 在**主索引鍵**區段中，定義資料表的主索引鍵，然後選取選用的叢集資料欄。

1. 在**資料表設定**區段中，選擇**自訂設定**。

1. 繼續**讀取/寫入容量設定**。

1. 對於**容量模式**，您可以選擇**隨需**或**佈建**。

1. 在**資料表的預熱前**區段中，您可以視需要增加**每秒讀取單位**和**每秒寫入單位**的值，以準備資料表來處理規劃的尖峰事件。

   Amazon Keyspaces 根據隨需用量或佈建容量調整的暖輸送量值，預設適用於所有資料表，無需額外費用。請注意，如果您手動增加預設暖傳輸量值來為尖峰流量事件預熱資料表，則需支付額外費用。

1. 視需要設定其他選用的資料表功能。然後選擇**建立資料表**。

------
#### [ Cassandra Query Language (CQL) ]
+ 使用下列其中一種方法建立具有暖輸送量的資料表：
  + 對於佈建模式，請建立資料表，並使用下列 CQL 語法指定讀取和寫入的預期尖峰容量：

    ```
    CREATE TABLE catalog.book_awards (
       year int,
       award text,
       rank int,
       category text,
       book_title text,
       author text,
       publisher text,
       PRIMARY KEY ((year, award), category, rank))
    WITH CUSTOM_PROPERTIES = {  
        'capacity_mode': {
           'throughput_mode': 'PROVISIONED',
           'read_capacity_units': 20000,
           'write_capacity_units': 10000
         },
        'warm_throughput': {  
            'read_units_per_second': 40000,  
            'write_units_per_second': 20000  
         }
    };
    ```
  + 對於隨需模式，請建立資料表，並使用下列 CQL 語法指定預期的讀取和寫入尖峰容量：

    ```
    CREATE TABLE catalog.book_awards (
       year int,
       award text,
       rank int,
       category text,
       book_title text,
       author text,
       publisher text,
       PRIMARY KEY ((year, award), category, rank))
    WITH CUSTOM_PROPERTIES = {  
        'capacity_mode': {
           'throughput_mode': 'PAY_PER_REQUEST'
         },
        'warm_throughput': {  
            'read_units_per_second': 40000,  
            'write_units_per_second': 20000  
         }
    };
    ```

  若要確認資料表的容量設定，請參閱 [檢視 Amazon Keyspaces 資料表的暖輸送量](view-warm-throughput.md)。

------
#### [ CLI ]

1. 使用下列其中一種方法，使用 建立具有暖輸送量的資料表 AWS CLI
   + 在佈建模式中建立新的資料表，並指定新資料表讀取和寫入的預期尖峰容量值。下列陳述式是此範例。

     ```
     aws keyspaces create-table \
     --keyspace-name 'catalog' \
     --table-name 'book_awards' \
     --schema-definition 'allColumns=[{name=year,type=int},{name=award,type=text},{name=rank,type=int},{name=category,type=text},{name=book_title,type=text},{name=author,type=text},{name=publisher,type=text}],partitionKeys=[{name=year},{name=award}],clusteringKeys=[{name=category,orderBy=ASC},{name=rank,orderBy=ASC}]' \
     --capacity-specification throughputMode=PROVISIONED,readCapacityUnits=20000,writeCapacityUnits=10000 \
     --warm-throughput-specification readUnitsPerSecond=40000,writeUnitsPerSecond=20000
     ```
   + 在隨需模式下建立新的資料表，並指定新資料表的讀取和寫入的預期尖峰容量值。下列陳述式是此範例。

     ```
     aws keyspaces create-table \
     --keyspace-name 'catalog' \
     --table-name 'book_awards' \
     --schema-definition 'allColumns=[{name=year,type=int},{name=award,type=text},{name=rank,type=int},{name=category,type=text},{name=book_title,type=text},{name=author,type=text},{name=publisher,type=text}],partitionKeys=[{name=year},{name=award}],clusteringKeys=[{name=category,orderBy=ASC},{name=rank,orderBy=ASC}]' \
     --warmThroughputSpecification readUnitsPerSecond=40000,writeUnitsPerSecond=20000
     ```

1. 命令的輸出會傳回資料表的 ARN，如下列範例所示。

   ```
   {
       "resourceArn": "arn:aws::cassandra:us-east-1:111122223333:/keyspace/catalog/table/book_awards>"
   }
   ```

   若要確認資料表的容量設定，請參閱 [檢視 Amazon Keyspaces 資料表的暖輸送量](view-warm-throughput.md)。

------
#### [ Java ]

**使用適用於 Java 的 開發套件建立新資料表。**
+ 在佈建模式中建立新的資料表，並指定新資料表讀取和寫入的預期尖峰容量值。下列程式碼範例是此範例。

  ```
  import software.amazon.awssdk.services.keyspaces.KeyspacesClient;
  import software.amazon.awssdk.services.keyspaces.model.*;
  
  public class PreWarmingExample {
      public static void main(String[] args) {
          KeyspacesClient keyspacesClient = KeyspacesClient.builder().build();
  
          // Define schema
          List<ColumnDefinition> columns = Arrays.asList(
              ColumnDefinition.builder().name("year").type("int").build(),
              ColumnDefinition.builder().name("award").type("text").build(),
              ColumnDefinition.builder().name("rank").type("int").build(),
              ColumnDefinition.builder().name("category").type("text").build(),
              ColumnDefinition.builder().name("book_title").type("text").build(),
              ColumnDefinition.builder().name("author").type("text").build(),
              ColumnDefinition.builder().name("publisher").type("text").build()
          );
          
          List<PartitionKey> partitionKeys = Arrays.asList(
              PartitionKey.builder().name("year").build(),
              PartitionKey.builder().name("award").build()
          );
          
          List<ClusteringKey> clusteringKeys = Arrays.asList(
              ClusteringKey.builder().name("category").orderBy("ASC").build(),
              ClusteringKey.builder().name("rank").orderBy("ASC").build()
          );
          
          SchemaDefinition schema = SchemaDefinition.builder()
              .allColumns(columns)
              .partitionKeys(partitionKeys)
              .clusteringKeys(clusteringKeys)
              .build();
  
          // Define capacity specification
          CapacitySpecification capacitySpec = CapacitySpecification.builder()
              .throughputMode(ThroughputMode.PROVISIONED)
              .readCapacityUnits(20000)
              .writeCapacityUnits(10000)
              .build();
              
          // Define warm throughput specification
          WarmThroughputSpecification warmThroughput = WarmThroughputSpecification.builder()
              .readUnitsPerSecond(40000L)
              .writeUnitsPerSecond(20000L)
              .build();
  
          // Create table with PreWarming
          CreateTableRequest request = CreateTableRequest.builder()
              .keyspaceName("catalog")
              .tableName("book_awards")
              .schemaDefinition(schema)
              .capacitySpecification(capacitySpec)
              .warmThroughputSpecification(warmThroughput)
              .build();
              
          CreateTableResponse response = keyspacesClient.createTable(request);
          System.out.println("Table created with ARN: " + response.resourceArn());
      }
  }
  ```

------

# 提高現有 Amazon Keyspaces 資料表的暖輸送量
<a name="update-warm-throughput"></a>

您可以使用主控台、CQL 或 來增加 Amazon Keyspaces 資料表目前的暖輸送量值 AWS CLI。

------
#### [ Console ]

**如何使用主控台增加資料表的預熱設定**

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home) 開啟 Amazon Keyspaces 主控台。

1. 在導覽窗格中，選擇**資料表**，然後選擇您要更新的資料表。

1. 在資料表的**容量**索引標籤上，繼續為**資料表預熱**。

1. 在**資料表的預熱區段**中，選擇**編輯**。

1. 在**編輯資料表預暖**頁面上，您可以更新**每秒讀取單位**和**每秒寫入單位**的值。

1. 選擇**儲存變更**。您的資料表正在以指定的預熱前設定進行更新。

------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 增加資料表的暖輸送量設定**
+ 使用 `ALTER TABLE`陳述式來增加資料表的暖輸送量。下列陳述式是此範例。

  ```
  ALTER TABLE catalog.book_awards 
  WITH CUSTOM_PROPERTIES = {
      'warm_throughput': {  
          'read_units_per_second': 60000,  
          'write_units_per_second': 30000  
      }
  };
  ```

  若要確認資料表的更新容量設定，請參閱 [檢視 Amazon Keyspaces 資料表的暖輸送量](view-warm-throughput.md)。

------
#### [ CLI ]

**使用 增加資料表的預熱前設定 AWS CLI**
+ 若要增加資料表的暖通量，您可以使用 `update-table`命令。下列陳述式是此範例。

  ```
  aws keyspaces update-table \
  --keyspace-name 'catalog' \
  --table-name 'book_awards' \
  --warmThroughputSpecification readUnitsPerSecond=60000,writeUnitsPerSecond=30000
  ```

  若要確認資料表的更新容量設定，請參閱 [檢視 Amazon Keyspaces 資料表的暖輸送量](view-warm-throughput.md)。

------
#### [ Java ]

**使用適用於 Java 的 SDK 更新資料表的預熱前設定。**
+ 更新資料表的暖輸送量設定。下列程式碼範例是此範例。

  ```
  import software.amazon.awssdk.services.keyspaces.KeyspacesClient;
  import software.amazon.awssdk.services.keyspaces.model.*;
  
  public class UpdatePreWarmingExample {
      public static void main(String[] args) {
          KeyspacesClient keyspacesClient = KeyspacesClient.builder().build();
  
          // Define new warm throughput specification
          WarmThroughputSpecification warmThroughput = WarmThroughputSpecification.builder()
              .readUnitsPerSecond(60000L)
              .writeUnitsPerSecond(30000L)
              .build();
  
          // Update table with new PreWarming settings
          UpdateTableRequest request = UpdateTableRequest.builder()
              .keyspaceName("catalog")
              .tableName("book_awards")
              .warmThroughputSpecification(warmThroughput)
              .build();
              
          UpdateTableResponse response = keyspacesClient.updateTable(request);
          System.out.println("Table update requested: " + response.resourceArn());
      }
  }
  ```

------

# 檢視 Amazon Keyspaces 資料表的暖輸送量
<a name="view-warm-throughput"></a>

您可以使用主控台、CQL 或 檢視 Amazon Keyspaces 資料表目前的暖輸送量值 AWS CLI。

------
#### [ Console ]

**如何使用主控台檢視資料表的預熱前設定。**

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home) 開啟 Amazon Keyspaces 主控台。

1. 在導覽窗格中，選擇**資料表**，然後選擇您要檢閱的資料表。

1. 在資料表的**容量**索引標籤上，繼續為**資料表預熱**。

------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 檢視資料表的暖通量設定**
+ 若要檢視資料表的暖輸送量設定，您可以使用下列 CQL 陳述式。

  ```
  SELECT custom_properties
  FROM system_schema_mcs.tables 
  WHERE keyspace_name='catalog' and table_name='book_awards';
  
  // Output:
  ...
  custom_properties
  ----------------------------------------------------------------------------------
  {
      'warm_throughput': 
      {
          'read_units_per_second': '40000', 
          'write_units_per_second': '20000', 
          'status': 'AVAILABLE'
      }
  }
  ...
  ```

------
#### [ CLI ]

**使用 檢視資料表的暖通量設定 AWS CLI**
+ 您可以使用 `get-table`命令檢視資料表的暖輸送量設定，如下列範例所示。

  ```
  aws keyspaces get-table \
  --keyspace-name 'catalog' \
  --table-name 'book_awards'
  ```

  以下顯示佈建模式中單一區域資料表的 `get-table`命令範例輸出。

  ```
  {
      "keyspaceName": "catalog",
      "tableName": "book_awards",
      ... Existing Fields ...,
      "capacitySpecificationSummary": {
          "throughputMode": "PROVISIONED",
          "readCapacityUnits": 20000,
          "writeCapacityUnits": 10000
      },
      "warmThroughputSpecificationSummary": {
          "readUnitsPerSecond": 40000,
          "writeUnitsPerSecond": 20000,
          "status": "AVAILABLE"
      }
  }
  ```

  以下顯示隨需模式下單一區域資料表的範例輸出。

  ```
  {
      "keyspaceName": "catalog",
      "tableName": "book_awards_ondemand",
      ... Existing Fields ...,
      "capacitySpecification": {
          "throughputMode": "PAY_PER_REQUEST"
      },
      "warmThroughputSpecificationSummary": {
          "readUnitsPerSecond": 40000,
          "writeUnitsPerSecond": 20000,
          "status": "AVAILABLE"
      }
  }
  ```

------
#### [ Java ]

**使用適用於 Java 的 SDK 讀取資料表的預熱前設定。**
+ 使用 讀取資料表的暖通量值`get-table`。下列程式碼範例是此範例。

  ```
  import software.amazon.awssdk.services.keyspaces.KeyspacesClient;
  import software.amazon.awssdk.services.keyspaces.model.*;
  
  public class GetTableWithPreWarmingExample {
      public static void main(String[] args) {
          KeyspacesClient keyspacesClient = KeyspacesClient.builder().build();
  
          // Get table details including PreWarming specification
          GetTableRequest request = GetTableRequest.builder()
              .keyspaceName("catalog")
              .tableName("book_awards")
              .build();
              
          GetTableResponse response = keyspacesClient.getTable(request);
          
          // Access PreWarming details
          if (response.warmThroughputSpecification() != null) {
              WarmThroughputSpecificationSummary warmThroughputSummary = response.warmThroughputSpecification();
              System.out.println("PreWarming Status: " + warmThroughputSummary.status());
              System.out.println("Read Units: " + warmThroughputSummary.readUnitsPerSecond());
              System.out.println("Write Units: " + warmThroughputSummary.writeUnitsPerSecond());
              
              // Check if PreWarming is active
              if (warmThroughputSummary.status().equals("AVAILABLE")) {
                  System.out.println("Table is fully pre-warmed and ready for high throughput");
              } else if (warmThroughputSummary.status().equals("UPDATING")) {
                  System.out.println("Table PreWarming is currently being updated");
              }
          } else {
              System.out.println("Table does not have PreWarming enabled");
          }
      }
  }
  ```

------

# 使用 Amazon CloudWatch 監控預暖資料表的效能
<a name="monitor-prewarming-cloudwatch"></a>

Amazon Keyspaces 預暖不會引入新的 CloudWatch 指標，但您可以使用現有的 Amazon Keyspaces 指標來監控預暖資料表的效能：

SuccessfulRequestLatency  
監控此指標，以確認預熱的資料表正在處理具有預期延遲的請求。

WriteThrottleEvents 和 ReadThrottleEvents  
對於正確預暖的資料表，這些指標應保持低。如果您在預熱前看到容量不足錯誤，您可能需要調整暖輸送量值。

ConsumedReadCapacityUnits 和 ConsumedWriteCapacityUnits  
這些指標顯示實際的容量使用量，這有助於驗證您的預暖組態是否適當。

ProvisionedReadCapacityUnits 和 ProvisionedWriteCapacityUnits  
對於佈建的資料表，這些指標會顯示目前配置的容量。

您可以在 CloudWatch 主控台中檢視這些指標，或使用 CloudWatch API 進行查詢。如需詳細資訊，請參閱[使用 Amazon CloudWatch 監控 Amazon Keyspaces](monitoring-cloudwatch.md)。