I'm testing performance of stored procedures on a project and I'm surprisingly disappointed. I'm using the C# SDK to execute the tests. Pricing tier is Standard, with throughput value of 400.
On my current dataset of ~1500 items, the plain query SELECT * FROM Store
takes ~4 seconds.
Using the following stored procedure with continuation takes ~19 seconds.
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
});
}
}
}
Code was adapted from this question to allow external continuation. I would like to load batches of items to let the user know that something is going on.
I'm ok if the execution of some stored procedures takes more time, but I'm quite surprised by the different (almost 5 times).