你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure Cosmos DB 容器上预配标准(手动)吞吐量 - 适用于 NoSQL 的 API

适用于: NoSQL

本文说明了如何在适用于 NoSQL 的 Azure Cosmos DB 的容器中预配标准(手动)吞吐量。 可以为单个容器预配吞吐量,也可以为数据库预配吞吐量,并在数据库中的容器之间共享。 可以使用 Azure 门户、Azure CLI 或 Azure Cosmos DB SDK 为容器预配吞吐量。

如果使用的是其他 API,请参阅 API for MongoDBAPI for CassandraAPI for Gremlin 这几篇文章来预配吞吐量。

Azure 门户

  1. 登录 Azure 门户

  2. 新建 Azure Cosmos DB 帐户,或选择现有的 Azure Cosmos DB 帐户。

  3. 打开“数据资源管理器”窗格,然后选择“新建容器” 。 接下来,请提供以下详细信息:

    • 表明要创建新数据库还是使用现有数据库。
    • 输入容器 ID。
    • 输入分区键值(例如 /ItemID)。
    • 选择“自动缩放”或“手动缩放”吞吐量并输入所需的“容器吞吐量”(例如,1000 RU/秒)。 输入要预配的吞吐量(例如,1000 RU)
    • 选择“确定”

    Screenshot of Data Explorer, with New Collection highlighted

Azure CLI 或 PowerShell

若要创建具有专用吞吐量的容器,请参阅

.NET SDK

注意

使用适用于 API for NoSQL 的 Azure Cosmos SDK 为除 Cassandra 和 API for MongoDB 之外的所有 Azure Cosmos DB API 预配吞吐量。

// 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 });

JavaScript SDK

// Create a new Client
const client = new CosmosClient({ endpoint, key });

// Create a database
const { database } = await client.databases.createIfNotExists({ id: "databaseId" });

// Create a container with the specified throughput
const { resource } = await database.containers.createIfNotExists({
id: "containerId",
throughput: 1000
});

// To update an existing container or databases throughput, you need to user the offers API
// Get all the offers
const { resources: offers } = await client.offers.readAll().fetchAll();

// Find the offer associated with your container or the database
const offer = offers.find((_offer) => _offer.offerResourceId === resource._rid);

// Change the throughput value
offer.content.offerThroughput = 2000;

// Replace the offer.
await client.offer(offer.id).replace(offer);

后续步骤

请参阅以下文章,了解如何在 Azure Cosmos DB 中预配吞吐量: