我注意到我的 Nodejs Lambda 函数在 Cloud watch 日志中存在持续时间与函数运行时间问题。我正在使用无服务器插件来部署/编码我的功能。
这是我的 lambda 函数代码:
module.exports.handler = function (event, context, cb) {
console.time("function_run_time");
myFunction(function (callback) {
console.timeEnd("function_run_time");
return cb(null, callback)
});
};
在云监视日志中,我收到以下内容
2016-05-25T00:18:58.881Z 45cd0785-ccce-11e6-818f-cb61404e173c function_run_time: 477ms
REPORT RequestId: 45cd0785-ccce-11e6-818f-cb61404e173c Duration: 1866ms Billed Duration: 1900 ms Memory Size: 1024 MB Max Memory Used: 39 MB
我想知道为什么函数运行时间为 477 毫秒,但持续时间为 1866 毫秒。
我的代码中是否需要调用某些内容才能提前结束 Lamdba 函数?
谢谢
最佳答案
检查调用回调后是否有代码在运行 参见这里:aws lambda
By default, the callback will wait until the Node.js runtime event loop is empty before freezing the process and returning the results to the caller. You can set this property to false to request AWS Lambda to freeze the process soon after the callback is called
此外,如果您使用 older version您应该调用带有 Lambda 的 Node
context.succeed();
和 context.fail(error)
结束函数。
关于javascript - AWS Lambda 持续时间与函数运行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37426088/