Lambda 冷启动可能的解决方案? [英] Lambda cold start possible solution?

查看:32
本文介绍了Lambda 冷启动可能的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 CloudWatch 安排 lambda 函数每 20 分钟调用一次是摆脱 lambda 冷启动时间的最佳方法吗?(没有完全摆脱)...

Is scheduling a lambda function to get called every 20 mins with CloudWatch the best way to get rid of lambda cold start times? (not completely get rid of)...

这会变得昂贵还是我遗漏了什么,因为我现在已经设置好了并且我认为它正在工作.

Will this get pricey or is there something I am missing because I have it set up right now and I think it is working.

在我的冷启动时间大约为 10 秒之前,每个后续调用将在大约 80 毫秒内完成.现在,无论多么频繁,每次调用都在 80 毫秒左右.这是一个好方法,直到你的用户群增长,然后你可以关闭它吗?

Before my cold start time would be like 10 seconds and every subsequent call would complete in like 80 ms. Now every call no matter how frequent is around 80 ms. Is this a good method until say your userbase grows, then you can turn this off?

我的第二个选择是使用 beanstalk 并让服务器 24/7 全天候运行,但这听起来很昂贵,所以我不喜欢它.

My second option is just using beanstalk and having a server running 24/7 but that sounds expensive so I don't prefer it.

推荐答案

据我所知,这是目前保持函数热度的唯一方法.只有当你拥有很多这些功能时,它才会变得昂贵.

As far as I know this is the only way to keep the function hot right now. It can get pricey only when you have a lot of those functions.

考虑到您有多少个函数、每次运行它们需要多长时间以及您需要多少内存,您必须计算自己为保持函数存活需要支付多少费用.

You'd have to calculate yourself how much do you pay for keeping your functions alive considering how many of them do you have, how long does it take to run them each time and how much memory do you need.

但是每 20 分钟一次大约是每月 2000 次,所以如果您使用例如128MB 并使它们在 100 毫秒内完成,那么您可以在 20 分钟的间隔内保持相当多的此类功能处于活动状态,并且仍然处于免费层 - 每个功能每月需要 20 秒.在获得更大的负载后,您甚至不需要将其关闭,因为此时它无关紧要.此外,您永远无法确保始终获得一致的负载,因此即使这样您也可以保持心跳代码处于活动状态.

But once every 20 minutes is something like 2000 times per month so if you use e.g. 128MB and make them finish under 100ms then you could keep quite a lot of such functions alive at 20 minute intervals and still be under the free tier - it would be 20 seconds per month per function. You don't even need to turn it off after you get a bigger load because it will be irrelevant at this point. Besides you can never be sure to get a uniform load all the time so you might keep your heart beating code active even then.

虽然我的猜测是,因为保持一个函数处于活动状态非常便宜(特别是如果你有一个特殊的参数让它们立即返回)并且差异非常大(10 秒对 80 毫秒)那么几乎每个人都会这样做——几乎没有理由不这样做.在这种情况下,我希望亚马逊要么与这种做法作斗争(通过使其变得更难或更贵——这不是明智之举),要么使其在未来不再需要.如果热启动和冷启动之间的差异是 100 毫秒,那么没有人会打扰.如果是 10 秒,那么每个人都需要解决它.

Though my guess is that since it is so cheap to keep a function alive (especially if you have a special argument that makes them return immediately) and that the difference is so great (10 seconds vs. 80 ms) then pretty much everyone will do it - there is pretty much no excuse not to. In that case I expect Amazon to either fight that practice (by making it hard or more expensive than it currently is - which wouldn't be a smart move) or to make it not needed in the future. If the difference between hot and cold start was 100ms then no one would bother. If it is 10 seconds than everyone needs to work around it.

运行一秒钟前运行的代码和一个月前运行的代码之间总是有区别的,因为将它们全部放在 RAM 中并准备好运行会浪费大量资源,但是我看不出有什么理由不能使这种差异变得不那么明显,甚至可以增加一些步骤,而不仅仅是热启动和冷启动.

There would always have to be a difference between running a code that was run a second ago and a code that was run a month ago, because having all of them in RAM and ready to go would waste a lot of resources, but I see no reason why that difference couldn't be made less noticeable or even have few more steps instead of just hot and cold start.

这篇关于Lambda 冷启动可能的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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