Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Azure Functions take an excessive time to "wake up"?

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.

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.

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?

like image 918
Graham Avatar asked Aug 01 '17 21:08

Graham


People also ask

What are the disadvantages of azure Functions?

Vendor-lock is the biggest drawback of this functions. It is very difficult to run code deployed in Azure function outside the azure environment. As the language used in function app such as java, NodeJS, etc are not specialized but code to establish a connection between resources is specific to azure.

Are azure Functions slow?

After further investigation, I realized that the following: Azure Function scripts sometimes takes anywhere between 10 seconds to more than 1 minutes to connect to SQL database. Sometimes the scripts will run in few millisecond and sometimes it will take more than 3 minutes to completely run the script.

How do I wake up azure function?

Azure Functions are automatically woken up based on their triggers (e.g. timer, http). There is no requirement to do this manually.

How long do azure Functions stay warm?

Once your Function executed, it will stay 'warm' for the next 20 minutes or so, to execute subsequent requests.


1 Answers

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.

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.

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.

like image 151
Jesse Carter Avatar answered Oct 11 '22 02:10

Jesse Carter