减少CosmosDB的预配置吞吐量

时间:2019-04-15 22:31:11

标签: azure-cosmosdb

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

以下文档说明了这种情况的发生原因。高于第4个的每个容器至少需要额外的100RU。我的预算限制很严格,因此我删除了2个容器,但找不到降低最低预配置吞吐量的方法,因为预配置吞吐量的下拉列表仅允许增加。有没有办法降低吞吐量?

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

1 个答案:

答案 0 :(得分:1)

document中所述,您可以使用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);

    }
}