本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用更高的暖輸送量建立新的 Amazon Keyspaces 資料表
您可以使用 主控台、CQL 或 ,在建立 Amazon Keyspaces 資料表時調整暖輸送量值 AWS CLI。
- Console
-
如何使用熱輸送量設定建立新的資料表
-
登入 AWS 管理主控台,並在 https://https://console.aws.amazon.com/keyspaces/home
開啟 Amazon Keyspaces 主控台。 -
在導覽窗格中,選擇 Tables (資料表),然後選擇 Create table (建立資料表)。
-
在資料表詳細資訊區段的建立資料表頁面上,選取金鑰空間,並提供新資料表的名稱。
-
在資料欄區段中,建立資料表的結構描述。
-
在主索引鍵區段中,定義資料表的主索引鍵,然後選取選用的叢集資料欄。
在資料表設定區段中,選擇自訂設定。
-
繼續讀取/寫入容量設定。
-
對於容量模式,您可以選擇隨需或佈建。
-
在資料表預暖區段中,您可以視需要增加每秒讀取單位和每秒寫入單位的值,以準備資料表來處理規劃的尖峰事件。
Amazon Keyspaces 根據隨需用量或佈建容量調整的暖輸送量值,預設適用於所有資料表,無需額外費用。請注意,如果您手動增加預設暖傳輸量值來為尖峰流量事件預熱資料表,則需支付額外費用。
-
視需要設定其他選用的資料表功能。然後選擇建立資料表。
-
- 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 資料表的暖輸送量。
-
-
- CLI
-
-
使用下列其中一種方法,使用 建立具有暖輸送量的資料表 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
命令的輸出會傳回資料表的 ARN,如下列範例所示。
{ "resourceArn": "arn:aws::cassandra:us-east-1:111122223333:/keyspace/catalog/table/book_awards>" }若要確認資料表的容量設定,請參閱 檢視 Amazon Keyspaces 資料表的暖輸送量。
-
- 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()); } }