【问题标题】:azure download node.js timeout天蓝色下载node.js超时
【发布时间】:2016-11-29 14:32:56
【问题描述】:

我在 Azure Functions 中运行了以下代码(代码来自 Stack Overflow here),大部分时间都按预期下载大文件。但是,有时它只是停止将数据添加到文件中并且永远不会重新开始。文件越大,发生的频率越高。我没有收到任何错误,什么都没有。有没有什么方法可以在 10 秒后再次唤醒这个过程,比如 10 秒没有进展,或者有什么其他的方法来关注这个过程?

var azure = require('azure-storage');
var fs = require('fs');

module.exports = function (context, input) {

context.done();

var accessKey = 'myaccesskey';
var storageAccount = 'mystorageaccount';
var containerName = 'mycontainer';

var blobService = azure.createBlobService(storageAccount, accessKey);

var recordName = "a_large_movie.mov";
var blobName = "standard/mov/" + recordName;

var blobSize;
var chunkSize = (1024 * 512) * 8; // I'm experimenting with this variable
var startPos = 0;
var fullPath = "D:/home/site/wwwroot/myAzureFunction/input/";
var blobProperties = blobService.getBlobProperties(containerName, blobName,   null, function (error, blob) {
    if (error) {
        throw error;
    }
    else    {
        blobSize = blob.contentLength;
        context.log('Registered length: ' + blobSize);
        fullPath = fullPath + recordName;
        console.log(fullPath);
        doDownload();
    }
}
);

function doDownload() {
var stream = fs.createWriteStream(fullPath, {flags: 'a'});
var endPos = startPos + chunkSize;
if (endPos > blobSize) {
    endPos = blobSize;
    context.log('Reached end of file endPos: ' + endPos);
}

context.log("Downloading " + (endPos - startPos) + " bytes starting from " + startPos + " marker.");

blobService.getBlobToStream(
    containerName, 
    blobName, 
    stream, 
    { 
        "rangeStart": startPos, 
        "rangeEnd": endPos-1 
    }, 
    function(error) {
        if (error) {
            throw error;
        }
        else if (!error) {
            startPos = endPos;
            if (startPos <= blobSize - 1) {
                doDownload();
            }
        }
    }
);
}

};

【问题讨论】:

  • 您是否尝试过将 chunkSize 从 4MB 减少到 1MB?
  • 不是 1 MB。不过,我从 512 KB 的块大小开始,它给出了与上面提到的相同的偶尔超时
  • 嗨@GauravMantri - 我将块更改为1MB,它确实使它变得更好。但是,有时大文件仍然会超时,因此问题并没有消失。但它确实改善了它。块大小和可能的超时之间有什么联系?
  • 块大小和超时可能与您的 Internet 连接有关。如果您的连接速度较慢,则上传 4MB 的块会失败,而较小的块会成功。

标签: node.js azure


【解决方案1】:

目前,Function 应用有短暂的空闲超时,因此如果它们在下一个请求 5 分钟内没有收到请求,服务器将被卸载。

所以,您遇到了问题:

有时它只是停止将数据添加到文件中而不再开始。文件越大,发生的频率越高。

您还可以在 https://docs.microsoft.com/en-us/azure/azure-functions/functions-best-practices#avoid-large-long-running-functions 找到有关 Azure Functions 最佳实践的建议。

因此,您可以尝试使用WebJobs 作为解决方法,并在 Azure 应用服务的应用程序设置中启用 Always On 配置。

如有任何疑问,请随时告诉我。

【讨论】:

  • 嗨@Gary - 5 分钟非常有趣。但是,我的下载功能似乎在 5 分钟过去之前停止工作。有什么方法可以监控一个进程的活动,如果在 30 秒内什么都没有发生,重新发送对块的请求或重新开始文件的下载?另外,当没有错误响应时,我将如何错误记录类似超时的内容?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-17
  • 1970-01-01
  • 2018-05-27
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多