我正在一个项目上测试存储过程的性能,但我非常失望。我正在使用 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/