首页 > 解决方案 > 减少 CosmosDB 的预置吞吐量

问题描述

我有一个 cosmosDB,它在数据库级别配置了 4 个容器和 400RU。我添加了 2 个容器,并且在没有警告的情况下,预配的 RU 增加到了 600。

下面的文档解释了为什么会发生这种情况。4 号以上的每个容器至少需要额外的 100RU。我有严格的预算限制,所以我删除了 2 个容器,但我找不到降低最低预配吞吐量的方法,因为预配吞吐量的下拉菜单只允许增加。有没有办法降低吞吐量?

https://docs.microsoft.com/en-us/azure/cosmos-db/set-throughput

标签: azure-cosmosdb

解决方案


文档中所述,您可以使用 cosmos db sdk 降低吞吐量设置。例如,我测试 java sdk 以降低我的容器吞吐量设置。请参考以下代码:

import com.microsoft.azure.documentdb.*;

import java.util.Iterator;

public class ChangeRUTest {

    static private String YOUR_COSMOS_DB_ENDPOINT = "https://***.documents.azure.com:443/";
    static private String YOUR_COSMOS_DB_MASTER_KEY="***";

    public static void main(String[] args) throws DocumentClientException {

        DocumentClient client = new DocumentClient(
                YOUR_COSMOS_DB_ENDPOINT,
                YOUR_COSMOS_DB_MASTER_KEY,
                new ConnectionPolicy(),
                ConsistencyLevel.Session);

        String collectionLink = "dbs/test/colls/one";

        String collectionResourceId = client.readCollection(collectionLink, null).getResource().getResourceId();

        // find offer associated with this collection
        Iterator<Offer> it = client.queryOffers(
                String.format("SELECT * FROM r where r.offerResourceId = '%s'", collectionResourceId), null).getQueryIterator();

        Offer offer = it.next();

        System.out.println(offer.getContent().getInt("offerThroughput"));

        // update the offer
        int newThroughput = 400;
        offer.getContent().put("offerThroughput", newThroughput);
        client.replaceOffer(offer);

    }
}

推荐阅读