在 Azure Cosmos 容器上预配吞吐量Provision throughput on an Azure Cosmos container

本文介绍如何在 Azure Cosmos DB 中为容器(集合、图形或表)预配吞吐量。This article explains how to provision throughput on a container (collection, graph, or table) in Azure Cosmos DB. 可以为单个容器预配吞吐量,也可以为数据库预配吞吐量,并在数据库中的容器之间共享。You can provision throughput on a single container, or provision throughput on a database and share it among the containers within the database. 可以使用 Azure 门户、Azure CLI 或 Azure Cosmos DB SDK 为容器预配吞吐量。You can provision throughput on a container using Azure portal, Azure CLI, or Azure Cosmos DB SDKs.

使用 Azure 门户预配吞吐量Provision throughput using Azure portal

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 创建新的 Azure Cosmos 帐户,或选择现有的 Azure Cosmos 帐户。Create a new Azure Cosmos account, or select an existing Azure Cosmos account.

  3. 打开“数据资源管理器”窗格,然后选择“新建集合” 。Open the Data Explorer pane, and select New Collection. 接下来,请提供以下详细信息:Next, provide the following details:

    • 表明要创建新数据库还是使用现有数据库。Indicate whether you are creating a new database or using an existing one.
    • 输入容器(或表或图)ID。Enter a Container (or Table or Graph) ID.
    • 输入分区键值(例如 /userid)。Enter a partition key value (for example, /userid).
    • 输入要预配的吞吐量(例如,1000 RU)Enter a throughput that you want to provision (for example, 1000 RUs).
    • 选择“确定” 。Select OK.

    数据资源管理器的屏幕截图,突出显示“新建集合”

使用 Azure CLI 或 PowerShell 预配吞吐量Provision throughput using Azure CLI or PowerShell

若要创建具有专用吞吐量的容器,请参阅To create a container with dedicated throughput see,

Note

若要在 Azure Cosmos DB 帐户(使用用于 MongoDB 的 Azure Cosmos DB API)为容器预配吞吐量,请使用 /myShardKey 作为分区键路径。If you are provisioning throughput on a container in an Azure Cosmos account configured with the Azure Cosmos DB API for MongoDB, use /myShardKey for the partition key path. 若要使用 Cassandra API 在 Azure Cosmos DB 帐户中为容器预配吞吐量,请使用 /myPrimaryKey 作为分区键路径。If you are provisioning throughput on a container in an Azure Cosmos account configured with Cassandra API, use /myPrimaryKey for the partition key path.

使用 .NET SDK 预配吞吐量Provision throughput by using .NET SDK

Note

使用适用于 SQL API 的 Cosmos SDK 为除 Cassandra API 之外的所有 Cosmos DB API 预配吞吐量。Use the Cosmos SDKs for SQL API to provision throughput for all Cosmos DB APIs, except Cassandra API.

SQL、MongoDB、Gremlin 和表 APISQL, MongoDB, Gremlin, and Table APIs

.NET V2 SDK.NET V2 SDK

// Create a container with a partition key and provision throughput of 400 RU/s
DocumentCollection myCollection = new DocumentCollection();
myCollection.Id = "myContainerName";
myCollection.PartitionKey.Paths.Add("/myPartitionKey");

await client.CreateDocumentCollectionAsync(
    UriFactory.CreateDatabaseUri("myDatabaseName"),
    myCollection,
    new RequestOptions { OfferThroughput = 400 });

.NET V3 SDK.NET V3 SDK


// Create a container with a partition key and provision throughput of 1000 RU/s
string containerName = "myContainerName";
string partitionKeyPath = "/myPartitionKey";

await this.cosmosClient.GetDatabase("myDatabase").CreateContainerAsync(
    id: containerName,
    partitionKeyPath: partitionKeyPath,
    throughput: 1000);

Cassandra APICassandra API

// Create a Cassandra table with a partition (primary) key and provision throughput of 400 RU/s
session.Execute(CREATE TABLE myKeySpace.myTable(
    user_id int PRIMARY KEY,
    firstName text,
    lastName text) WITH cosmosdb_provisioned_throughput=400);

后续步骤Next steps

请参阅以下文章,了解如何在 Azure Cosmos DB 中预配吞吐量:See the following articles to learn about throughput provisioning in Azure Cosmos DB: