How do I turn on "always-on" for an Azure Function?

21,491

Solution 1

This answer applies to all Azure Function scenarios with the exception of those that are triggered by an http request.

There are 3 cases to look at:

  1. You have a Function App running in a Free/Shared App Service Plan: Always On is not available, and those scenarios are simply not supported.
  2. You have a Function App running in a Basic/Standard/Premium App Service Plan: Always On is available and can be turned on. In fact it is on by default, and you'll get a warning in the Functions UI if you turn it off.
  3. You have a Function App using a Consumption Plan: there is no need for Always On as the system takes care of waking up your functions whenever they need to run. This is the recommended approach for most users.

Solution 2

You can do a small hack if you're in free/shared app service plan & it works perfectly. Use the pinging service like freshping.io that pings your function url every 5 secs/custom interval which prevents your app from being idle. Freshping.io gives you 5 free urls to ping.

Note: pinging url doesn't count towards the CPU run time, unless you ping the actual function. So it doesn't affect your time limit.

Hope this helps.

Solution 3

Azure Functions are managed together by Azure App Service which restricts always on to modes that are Basic or above (no free or shared)

In Basic or Standard mode, you can enable Always On to keep the app loaded all the time.

Share:
21,491
Mathias
Author by

Mathias

I was a quantitative models guy, but California turned me into a software developer. I primarily write code in F#, with origins in C#, and, even further back, VBA for Excel.

Updated on August 03, 2020

Comments

  • Mathias
    Mathias over 3 years

    I have a Function App with 3 functions, one of them timer-triggered every 2 minutes. I observed that after a while, the function stops being triggered, but restarts when I go to the portal.

    As I understand it, the reason is that by default, "Always On" is turned off. However, when I go to Application Settings / General Settings, I cannot activate the "On" state, which is grayed out. I can un-check "Off", which doesn't seem to stick or activate "On".

    enter image description here

    Am I missing something obvious? Is Always-On the solution to my problem, or is there something else I should do?

    Note: the functions are written in F#; I doubt it matters, but I thought I would mention it just in case.

  • Mathias
    Mathias over 7 years
    Thank you, that helps. As a follow-up, my understanding then is that for a timer trigger on Classic to work, I need to pay a fixed cost attached to the cheapest Basic option. Is that correct?
  • David Ebbo
    David Ebbo over 7 years
    Yes, that's correct in Basic mode. However, if you use Dynamic mode, everything is free until you hit a high usage level. See pricing page for details.
  • Mathias
    Mathias over 7 years
    Got it now, thank you. I re-wrote my app using the Dynamic option (couldn't figure out how to convert), everything works like a charm :)
  • Iain
    Iain over 6 years
    "App Service Plan: Always On is available ... In fact it is on by default"; that's not what I found, not when deploying from ARM. You do have to set "alwaysOn": true in the template. Per docs.microsoft.com/en-us/azure/azure-functions/…
  • David Ebbo
    David Ebbo over 6 years
    @Iain indeed, I was referring to Portal creation. With ARM you have to explicitly set it.
  • Akash Shrivastava
    Akash Shrivastava about 4 years
    what is the approach for http request triggered functions then?
  • SamiR
    SamiR almost 4 years
    Has something changed? Because I deployed functions app from template to a premium plan not defining always on at all and it set it to false. Also the option can't be found in the portal. Only shows: Platform Managed pipeline version FTP state HTTP version This is v3