在 Azure Cosmos DB 中的数据库上预配吞吐量Provision throughput on a database in Azure Cosmos DB

本文介绍如何在 Azure Cosmos DB 中的数据库上预配吞吐量。This article explains how to provision throughput on a database in Azure Cosmos DB. 可以为单个容器预配吞吐量,也可以为数据库预配吞吐量,并在数据库中的容器之间共享吞吐量。You can provision throughput for a single container, or for a database and share the throughput among the containers within it. 若要了解何时使用容器级和数据库级吞吐量,请参阅在容器和数据库上预配吞吐量的用例一文。To learn when to use container-level and database-level throughput, see the Use cases for provisioning throughput on containers and databases article. 可以使用 Azure 门户或 Azure Cosmos DB SDK 来预配数据库级别吞吐量。You can provision database level throughput by using the Azure portal or Azure Cosmos DB SDKs.

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

SQL(核心)APISQL (Core) API

  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 Database. 提供以下详细信息:Provide the following details:

    • 输入数据库 ID。Enter a database ID.
    • 选择“预配吞吐量”。 Select Provision throughput.
    • 输入吞吐量(例如 1000 RU)。Enter a throughput (for example, 1000 RUs).
    • 选择“确定” 。Select OK.

    “新建数据库”对话框屏幕截图

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

若要创建具有共享吞吐量的数据库,请参阅:To create a database with shared throughput see,

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

Note

使用适用于 SQL API 的 Cosmos SDK 为所有 API 预配吞吐量。You can use Cosmos SDKs for SQL API to provision throughput for all APIs. 也可以选择将以下示例用于 Cassandra API。You can optionally use the following example for Cassandra API as well.

所有 APIAll APIs

.NET V2 SDK.NET V2 SDK

//set the throughput for the database
RequestOptions options = new RequestOptions
{
    OfferThroughput = 500
};

//create the database
await client.CreateDatabaseIfNotExistsAsync(
    new Database {Id = databaseName},  
    options);

.NET V3 SDK.NET V3 SDK


//create the database with throughput
string databaseName = "MyDatabaseName";
await this.cosmosClient.CreateDatabaseIfNotExistsAsync(
        id: databaseName,
        throughput: 1000);

Cassandra APICassandra API

// Create a Cassandra keyspace and provision throughput of 400 RU/s
session.Execute(CREATE KEYSPACE IF NOT EXISTS myKeySpace WITH cosmosdb_provisioned_throughput=400);

后续步骤Next steps

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