本文說明如何在 Azure Cosmos DB for NoSQL 容器中配置標準(手動)吞吐量。 你可以在單一容器上配置吞吐量,或是在資料庫中配置 吞吐量 ,並在資料庫內的容器間共享。 你可以使用 Azure portal、Azure CLI 或 Azure Cosmos DB SDK 在容器上配置吞吐量。
如果你用的是不同的 API,請參考 API for MongoDB、 API for Cassandra、 API for Gremlin 文章來設定吞吐量。
Azure 入口網站
登入 Azure 入口網站。
建立一個新的 Azure Cosmos DB 帳號,或選擇一個現有的 Azure Cosmos DB 帳號。
開啟 [資料總管] 窗格,然後選取 [新增容器]。 接下來,提供下列詳細資料:
- 請說明你是建立新資料庫還是使用現有資料庫。
- 輸入 [容器識別碼]。
- 輸入 [分割區索引鍵] 值 (例如
/ItemID)。 - 選取 [自動調整] 或 [手動] 輸送量,然後輸入所需的 [容器輸送量] (例如,1000 RU/秒)。 輸入您要佈建的輸送量 (例如 1000 RU)。
- 請選擇 [確定]。
Azure CLI or PowerShell
要建立具有專用吞吐量的容器,請參見,
.NET SDK
備註
使用 Azure Cosmos DB SDK for API for NoSQL 來為所有 Azure Cosmos DB API 配置吞吐量,除了 Cassandra 和 API for MongoDB。
// 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 中的吞吐量配置: