是否可以禁用Azure CosmosDB存储过程的5秒时间限制 [英] Is it possible to disable the 5 second time limit for Azure CosmosDB stored procedures

查看:152
本文介绍了是否可以禁用Azure CosmosDB存储过程的5秒时间限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在使用Azure的CosmosDB中的存储过程来完成一些工作,以更新一些文档.这些文档有点笨拙(5000多个行的文档,大约要处理1000个文档),并且存储过程需要5秒钟以上才能运行. 5秒的限制会停止sproc的运行,并抛出超过时间限制的错误.所以,我问这是否可以关闭或配置?

I have recently been doing some work using a stored procedure in Azure's CosmosDB to update some documents. The Documents are a bit chunky (5000+ lines documents and dealing with about a 1000 of them) and the sproc takes more than 5 seconds to run. The 5 second limit stops the sproc from running, throwing the time limit exceeded error. So, I am asking if this can be turned off or configured?

我已阅读这个问题,关于一些可能的解决方法,我正在与其他一些想法一起探讨,但是,很清楚,这个问题的目的是确定是否可以关闭或配置这5秒限制我可以解决它.

I have read this question about some possible work arounds, which I am looking at along with some other ideas, but, to be clear, the purpose of this question is to establish if this 5 second limit can be turned off or configured not if I can work around it.

我一直在尝试在官方文档中找到说明这一点的地方,因此,如果有人知道那在哪里,那会很棒.

I have been trying to find somewhere in the official docs that says this, so if anyone knows where that is that would be great.

我也尝试增加集合的吞吐量以减少运行时间.这有帮助,但是存储过程仍然达到极限.

I have also tried increasing the throughput on the collection to reduce the time it takes to run. This helps, but the sproc still hits the limit.

推荐答案

那么,我问这是可以关闭还是配置?

So, I am asking if this can be turned off or configured?

很明显,正如@David Makogon所说,无法关闭或配置cosmos db存储过程运行时的限制.

Clearly, as @David Makogon said the limitation of cosmos db stored procedure runtime can't be turned off or configured.

所以,我建议您在线程中采用解决方法:连续令牌批量处理数据.您可以参考以下pseudo-code:

So , I recommand you adopt workaround in the thread :What happens when 5 second execution time limit exceeds in Azure DocumentDb Stored Procedures. Please use continuation tokens to process data in batchs. You could refer to the pseudo-code as below :

function updateArticlesDetailsX() {

       var collection = getContext().getCollection();
       var collectionLink = collection.getSelfLink();
       var response = getContext().getResponse();
       var docCount = 0;
       var counter = 0;

       tryQueryAndUpdate();

       function tryQueryAndUpdate(continuation) {
            var query = {
                query: "select * from root r"
            };

            var requestOptions = {
                continuation: continuation
            };

            var isAccepted =
                collection
                .queryDocuments(collectionLink,
                                query,
                                requestOptions,
                                function queryCallback(err, documents, responseOptions) {
                                         if (err) throw err;
                                         if (documents.length > 0) {
                                            // If at least one document is found, update it.
                                            docCount = documents.length;
                                            for (var i=0; i<docCount; i++){
                                                tryUpdate(documents[i]);
                                            }
                                            response.setBody("Updated " + docCount + " documents");
                                          }
                                          else if (responseOptions.continuation) {
                                              // Else if the query came back empty, but with a continuation token; 
                                              // repeat the query w/ the token.
                                            tryQueryAndUpdate(responseOptions.continuation);
                                          } else {
                                                 throw new Error("Document not found.");
                                                 }
                                });

            if (!isAccepted) {
                throw new Error("The stored procedure timed out");
            }
        }

        function tryUpdate(document) {
            //Optimistic concurrency control via HTTP ETag.
            var requestOptions = { etag: document._etag };

            //Update statement goes here:
            document.x = "some new value";

            var isAccepted = collection
                             .replaceDocument(document._self,
                                              document,
                                              requestOptions,
                                              function replaceCallback(err, updatedDocument, responseOptions) {
                                                       if (err) throw err;
                                                       counter++;
                                               });

            // If we hit execution bounds - throw an exception.
            if (!isAccepted) {
                throw new Error("The stored procedure timed out");
            }
        }
    }

此外,如果您的文档太大,以致每批次只能处理几个文件(通常不能,因为文档的大小限制为2M),那么也许您应该优化数据结构以使文档快速.

In addition, if your document is too large so that you could just handle only a few per batch (usually not, because the size of document has a 2M limit) , maybe you should optimize your data structure to make your document snappy.

希望它能对您有所帮助.

Hope it help you.

这篇关于是否可以禁用Azure CosmosDB存储过程的5秒时间限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆