c# - 一系列存储过程(带有连续 token )是否比 Azure DocumentDb 中的单个普通查询慢?

标签 c# azure azure-cosmosdb

我正在一个项目上测试存储过程的性能,但我非常失望。我正在使用 C# SDK 来执行测试。定价等级为标准,吞吐量值为400

在我当前包含约 1500 个项目的数据集上,普通查询 SELECT * FROM Store 需要约 4 秒。

使用以下连续存储过程大约需要 19 秒。

function getPackages(continuationToken, pageSize) {
    var context = getContext();
    var response = context.getResponse();
    var collection = context.getCollection();
    var collectionLink = collection.getSelfLink();
    var nodesBatch = [];
    var lastContinuationToken;
    var responseSize = 0;

    var query = {
        query: 'SELECT * FROM Store'
    };

    getItems(continuationToken);

    function getItems(continuationToken) {
        // Tune the pageSize to fit your dataset.
        var requestOptions = {
            continuation: continuationToken,
            pageSize: 500
        };

        var accepted = collection.queryDocuments(collectionLink, query, requestOptions,
            function (err, documentsRead, responseOptions) {
                // The size of the current query response page.
                var queryPageSize = JSON.stringify(documentsRead).length;

                // DocumentDB has a response size limit of 1 MB.
                if (responseSize + queryPageSize < 1024 * 1024) {
                    // Append query results to nodesBatch.
                    nodesBatch = nodesBatch.concat(documentsRead);

                    // Keep track of the response size.
                    responseSize += queryPageSize;

                        // If there is no continutation token, we are done. Return the response.
                        response.setBody({
                            "length": nodesBatch.length,
                            "message": "Query completed succesfully.",
                            "queryResponse": nodesBatch,
                            "continuationToken": responseOptions.continuation
                        });
                } else {
                    // If the response size limit reached; run the script again with the lastContinuationToken as a script parameter.
                    response.setBody({
                        "length": nodesBatch.length,
                        "message": "Response size limit reached.",
                        "lastContinuationToken": lastContinuationToken,
                        "queryResponse": nodesBatch
                    });
                }
            });

        if (!accepted) {
            // If the execution limit reached; run the script again with the lastContinuationToken as a script parameter.
            response.setBody({
                "length": nodesBatch.length,
                "message": "Execution limit reached.",
                "lastContinuationToken": lastContinuationToken,
                "queryResponse": nodesBatch
            });
        }
    }
}

代码改编自this question以允许外部继续。我想加载批量项目,让用户知道正在发生某些事情。

如果某些存储过程的执行需要更多时间,我没关系,但我对不同的时间感到非常惊讶(几乎 5 次)。

最佳答案

我已收到 DocumentDb 团队的答复。 原因是 SP 与主副本绑定(bind),而查询可以访问其他位置以更快地获取数据。

附加建议:您会注意到 SP 的一件事是不同的“RU”消耗。将 SP 用于大多数需要跨文档发送的“写入”场景。

关于c# - 一系列存储过程(带有连续 token )是否比 Azure DocumentDb 中的单个普通查询慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40068442/

相关文章:

c# - 向事件添加简单的处理程序是否会导致大量开销?

c# - 在没有第 3 方库的情况下使用 C# .net 3.0 或更低版本将 pdf 转换为 tiff?

C# 如何: listening if new record is inserted in a mysql table

sql-server - 作为 Azure 托管 SQL 数据库的报表服务器

python-2.7 - PYTHON - 从 Azure Cosmos DB 中的集合中删除项目

json - 检索部分数组属性

entity-framework - 使用 Cosmos 文档数据库的最佳方式是什么? EF Core 与 Cosmos SDK

c# - LINQ to XML 选择子元素

azure - 我一直在努力在 Azure Synapse Analytics 上找到任何相关文档,以使用 CLI 为 Azure KeyVault 提供链接服务

web-applications - 基于 Azure 的 GPS 数据记录器和 map 查看器