是否可以使AWS Lambda函数保持温暖? [英] Is it possible to keep an AWS Lambda function warm?

查看:81
本文介绍了是否可以使AWS Lambda函数保持温暖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一些应用程序无法承受Lambda函数在新的或未使用的一段时间内经历的冻结-解冻"周期所导致的额外1-2秒延迟.

There are a few pieces of my app that cannot afford the additional 1-2 second delay caused by the "freeze-thaw" cycle that Lambda functions go through when they're new or unused for some period of time.

如何使这些Lambda函数保持温暖,以便AWS不必一直重新配置它们?这适用于1)不常用的功能和2)最近部署的功能.

How can I keep these Lambda functions warm so AWS doesn't have to re-provision them all the time? This goes for both 1) infrequently-used functions and 2) recently-deployed functions.

理想情况下,我错过了一个称为保持温暖"的设置,该设置增加了Lambda函数的成本,但是始终保持函数处于温暖状态并准备好响应,但是我敢肯定这不存在.

Ideally, there is a setting that I missed called "keep warm" that increases the cost of the Lambda functions, but always keeps a function warm and ready to respond, but I'm pretty sure this does not exist.

我想一个选择是经常使用CloudWatch计时器ping这些功能...但这对我来说是错的.另外,我不知道AWS将Lambda函数置于冰上的时间间隔.

I suppose an option is to use a CloudWatch timer to ping the functions every so often... but this feels wrong to me. Also, I don't know the interval that AWS uses to put Lambda functions on ice.

推荐答案

BBC在

BBC has published a nice article on iPlayer engineering where they describe a similar issue.

他们选择每隔几分钟使用 CloudWatch预定事件调用该函数.

They have chosen to call the function every few minutes using CloudWatch Scheduled Events.

因此,从理论上讲,它应该留在那里,除非它可能不会.因此,我们设置了一个计划中的事件来使容器保持温暖".我们每隔几分钟调用一次该函数,无需进行任何处理,但要确保我们已准备好模型.这仅占调用的很小一部分,但可以帮助我们减轻模型下载中的竞争条件.(我们还人为地限制了并行调用多少个lambda作为附加措施).

So in theory, it should just stay there, except it might not. So we have set up a scheduled event to keep the container ‘warm’. We invoke the function every couple of minutes not to do any processing, but to make sure we’ve got the model ready. This accounts for a very small percentage of invocations but helps us mitigate race conditions in the model download.(We also limit artificially how many lambdas we invoke in parallel as an additional measure).

这篇关于是否可以使AWS Lambda函数保持温暖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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