Cosmos DB存储过程RU收费是否高于通过SDK或门户网站进行的等效查询?

时间:2018-12-28 12:36:34

标签: azure azure-cosmosdb

是否希望通过存储的proc执行的查询的RU费用比通过sdk或门户网站执行的相同查询的RU费用更高(几乎是两倍)?

此测试代码显示两种情况都针对partitionKey和文档ID对单个文档执行查询。

通过存储的proc执行的简单查询

简单的存储proc,用于通过id测试单个文档的执行情况。由于此操作是在单个分区的范围内执行的,因此应导致直接查询分区和文档ID。

for (var i = 0; i < titles.length; i++) {
    node = document.importNode(template.content, true);

    label = node.querySelector(".caption");     // should query here ?

    label.innerHTML = titles[i];
    document.body.appendChild(node);
}

请求费用: 5.68 RU

直接在门户网站中查询

function testProc(id, props) {
    var collection = getContext().getCollection();
    var collectionLink = collection.getSelfLink();
    var response = getContext().getResponse();

    // Validate input.
    if (!id) throw new Error("The id is undefined or null.");
    if (!props) throw new Error("The update is undefined or null.");

    tryQuery();

    function tryQuery() {
         var query = {query: "select * from root r where r.id = @id", parameters: [{name: "@id", value: id}]};

         var isAccepted = collection.queryDocuments(collectionLink, query, function (err, documents, responseOptions) {
             if (err) throw err;

             if (documents.length == 1) {
                 // Update props
             } else {
                 // Else a document with the given id does not exist..
                 throw new Error("Document not found.");
             }
         });

         // If we hit execution bounds - throw an exception.
         // This is highly unlikely given that this is a query by id; but is included to serve as an example for larger queries.
         if (!isAccepted) {
             throw new Error("The stored procedure timed out.");
         }
     }
}

请求费用: 2.890 RUs

我只能根据cosmos request units and throughput documentation认为,这种差异是由于运行存储的proc本身所需的计算资源(CPU /内存)的物理开销而引起的。

对于通过分区和id提取文档的简单查询,它似乎相当高。

0 个答案:

没有答案