执行存储过程时Cosmos DB内存不足异常 [英] Cosmos DB out of Memory exception while executing stored procedure

查看:127
本文介绍了执行存储过程时Cosmos DB内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure Cosmos DB SQL API.我编写的存储过程将获取数据并保持响应API提要.

I am using Azure Cosmos DB SQL API . I have written stored procedure will get the data and keeps in response API feed .

无法执行存储过程testProcedure进行收集 iotcollection: {代码":400,正文":"{\"代码\:\" BadRequest \,\"消息\:\"消息: {\\错误\\":[\\执行功能时遇到异常. 异常=错误:内存不足\\ r \\ n堆栈跟踪: undefined \\]} \ r \ nActivityId:c286cbb6-34c1-4929-a148-915544b20ce6, 请求URI: /apps/59d3b9ef-17ca-4bbf-8a11-39d0199a8d29/services/1b26e00f-1f51-4d34-88ec-4090b8e7db00/partitions/45a313b7-2cf2-419e-9885-48bf9cfe6277/replicas/131862936473830809p/, RequestStats:\ r \ nRequestStartTime:2018-11-10T05:46:36.4852333Z, 尝试的区域数:1 \ r \ n,SDK: Microsoft.Azure.Documents.Common/2.1.0.0 \}","activityId":"c286cbb6-34c1-4929-a148-915544b20ce6"}

Failed to execute stored procedure testProcedure for collection iotcollection: {"code":400,"body":"{\"code\":\"BadRequest\",\"message\":\"Message: {\\"Errors\\":[\\"Encountered exception while executing function. Exception = Error: Out of memory\\r\\nStack trace: undefined\\"]}\r\nActivityId: c286cbb6-34c1-4929-a148-915544b20ce6, Request URI: /apps/59d3b9ef-17ca-4bbf-8a11-39d0199a8d29/services/1b26e00f-1f51-4d34-88ec-4090b8e7db00/partitions/45a313b7-2cf2-419e-9885-48bf9cfe6277/replicas/131862936473830809p/, RequestStats: \r\nRequestStartTime: 2018-11-10T05:46:36.4852333Z, Number of regions attempted: 1\r\n, SDK: Microsoft.Azure.Documents.Common/2.1.0.0\"}","activityId":"c286cbb6-34c1-4929-a148-915544b20ce6"}

我的存储过程非常简单,我只想看看在给定的时间我可以从cosmos DB中获取多少记录并作为响应发送.

My stored procedure is very simple one I just wanted to see how many records i can fetch from cosmos DB at given time and send as response.

    // SAMPLE STORED PROCEDURE
function sample(prefix) {
    var collection = getContext().getCollection();

    // Query documents and take 1st item.
    var isAccepted = collection.queryDocuments(
        collection.getSelfLink(),
        'SELECT r.data FROM root r',
    function (err, feed, options) {
        if (err) throw err;

        // Check the feed and if empty, set the body to 'no docs found', 
        // else take 1st element from feed
        if (!feed || !feed.length) {
            var response = getContext().getResponse();
            response.setBody('no docs found');
        }
        else {
            var response = getContext().getResponse();
            var body = { prefix: prefix, feed: feed[0] };
            var str = 'str';
            for ( var i =0 ; i < 100 ; i = i +1 ){
                    str = str + str ;
                    body .str = feed[0];
            }

            response.setBody(JSON.stringify(body));
        }
    });

    if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

推荐答案

我确定Out-Of-Memory错误的原因是循环期间str字符串太长.看来str字符串对您的测试没有用,它没有添加到响应中.

I'm sure the reason of Out-Of-Memoryerror is the str string is too long during your loop. It seems that the str string is useless for your test which is not added into response.

请删除它,示例存储过程将正常运行.

Please remove it and the sample stored procedure will work fine.

这篇关于执行存储过程时Cosmos DB内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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