为什么Azure功能需要花费大量时间来“唤醒"? [英] Why do Azure Functions take an excessive time to "wake up"?

查看:92
本文介绍了为什么Azure功能需要花费大量时间来“唤醒"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个简单的Azure函数,可以进行DocumentDB查询.好像是我们第一次调用它时,要等待很长时间才能完成,然后连续调用就非常快.

We have a simple Azure Function that makes a DocumentDB query. It seems like the first time we call it there is a long wait to finish, and then successive calls are very fast.

例如,我刚刚打开我们的应用程序,并且第一个Function调用耗时10760ms,任何最终用户都绝对可以注意到.此后,所有Function调用大约需要100毫秒来处理,并且几乎不可察觉.

For example, I just opened our app and the first Function call took 10760ms, definitely noticeable by any end user. After this, all Function calls take approximately 100ms to process and are nearly imperceptible.

在Azure Functions中似乎有一些唤醒"周期.有什么方法可以减少这种情况,或者更好的方法是在某个地方进行记录,以便我们可以了解这里的实际情况?

It seems as though there is some "wake up" cycle in Azure Functions. Is there some way to minimize this, or better yet is this documented somewhere so we can understand what's really going on here?

推荐答案

根据消费计划运行的功能应用确实确实有一个空闲时间,在此之后它们会有效地进入睡眠状态.正如您所观察到的,并且人们在评论中提到的那样,需要下一次调用才能唤醒它们".

Function apps running on a consumption plan do indeed have an idle time after which they effectively go to sleep. The next invocation is required to "wake them up" as you've observed and people have mentioned in the comments.

关于发生这种情况的原因,是为了使Microsoft能够最佳地在多租户环境中分配计算工作负载,同时确保仅在功能实际运行时就按秒计费.这就是无服务器的魅力.

As to why this happens, it's so that Microsoft can most optimally distribute compute workloads in a multi-tenant environment while ensuring that you're only billed to the second for the time where your function is actually doing work. This is the beauty of serverless.

对于这是无法接受的行为的工作负载,您可以考虑将其从消费计划移至实际的App Service计划.另外,您可以实现一个计时器触发的功能,例如每分钟关闭一次,并通过ping不想睡觉的功能将其用作保持活动"机制.

For workloads where this is not acceptable behavior, you could consider moving off of the consumption plan and on to the actual App Service plan. Alternatively, you could implement a timer triggered function that goes off every minute for example and use that as a "keep alive" mechanism by pinging the function that you don't want to go to sleep.

这篇关于为什么Azure功能需要花费大量时间来“唤醒"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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