为什么 Azure Functions 需要过长的时间才能“唤醒"? [英] Why do Azure Functions take an excessive time to "wake up"?

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

问题描述

我们有一个简单的 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.

例如,我刚刚打开我们的应用程序,第一次函数调用耗时 10760 毫秒,任何最终用户都可以注意到这一点.在此之后,所有 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.

对于这种行为不可接受的工作负载,您可以考虑退出消耗计划并转向实际的应用服务计划.或者,您可以实现一个计时器触发功能,例如每分钟关闭一次,并通过 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 Functions 需要过长的时间才能“唤醒"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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