How to prevent an Azure website from going to sleep?

13,204

Solution 1

Azure Web Apps have an 'Always on' option (with basic/standard tiers) which keep your app (and associated web jobs) loaded.

Look under Settings, and you'll see 'Application settings':

Application settings

Then look for the 'Always on' setting (which will be disabled for Free tier):

Always on

Solution 2

I know this post is a little old, but the issue is still relevant.

I use a free service called Uptime Robot - https://uptimerobot.com/

Even on the free tier, you can create up to 50 monitors to call your web site, at least every 5 minutes, which is certainly regularly enough to keep your site alive.

As well as keeping the site alive (without any knock-on consequences of using 'Always On') it also serves as a monitor for your site, letting you know if it's down.

You can create monitors that alert you if specific words are in or not in the response, so it's quite easy to check the content is correct. You could even create a 'test' page that just returns 'OK' after checking various functionality on your site.

Share:
13,204
AngryHacker
Author by

AngryHacker

Updated on June 17, 2022

Comments

  • AngryHacker
    AngryHacker almost 2 years

    I deployed an ASP.NET 5, MVC 6 web application to Azure. It seems that if I don't hit the site for 10-15 minutes, it goes to sleep and it takes a good 10-15 seconds for it to wake up.

    I am not sure whether its the website that's falling asleep, or the database that it's connecting to.

    So 2 questions.

    1. How do I prevent the site from going to sleep so soon.
    2. Is there a way to have visibility into what's going on in Azure with the website and the database. Are they kicked out of memory?
  • Brad Christie
    Brad Christie over 8 years
    Though I believe this is the correct answer, these is also the option of using a service like pingdom, though this is a paid service.
  • David Makogon
    David Makogon over 8 years
    @BradChristie - the Always On feature does more than just keepalive pings. It also disables the mechanism that tears down a site if needed (e.g. if you have hundreds of Web apps running within your Web App service plan). You can then selectively choose which Web apps (within your app service plan) to keep 'Always on' vs allowing to be torn down when need be.
  • Matt Watson
    Matt Watson over 8 years
    AlwaysOn is also important to ensure any WebJobs run
  • AngryHacker
    AngryHacker over 8 years
    Thanks. That did it. It's worth pointing out that this feature is not available to the free tier. I had to switch to basic to gain this functionality.
  • Jorge Aguirre
    Jorge Aguirre almost 8 years
    Why is this not the default!
  • Jorge Aguirre
    Jorge Aguirre about 7 years
    @ComethTheNerd ;)
  • Michal B.
    Michal B. over 6 years
    It does not work for me either...I have this setting set to "On" and still my app takes around 15s to load for the first time after some time of being inactive. Second load and all next ones withing some period of time are very fast (less than a second)
  • Sagar Kulkarni
    Sagar Kulkarni over 5 years
    "Uptime Robot" is nice tool
  • George Beier
    George Beier about 5 years
    I was also frustrated with Azure falling asleep, despite the "always on" setting. I put some monitors on UptimeRobot and it was very interesting. My landing page, which normally takes about 1/2 second to load would fall asleep and take about 10 seconds to load. I've been pinging it every half an hour and that seems like enough to keep it awake. The longitudinal tracking of the response times is great.
  • SSH This
    SSH This over 4 years
    It certainly doesn't work for Node applications using IIS-Node. Azure is so great!
  • Nouman Qaiser
    Nouman Qaiser about 3 years
    Sounds like this is a good solution. Within Azure 'Always On' does not prevent the app from shutting down every 29hours.
  • Nouman Qaiser
    Nouman Qaiser about 3 years
    This solution does NOT work. I set my WebApp to Always On and had a periodic Background that to post a message to a database, the web App turned off exactly 29 hours later. So this solution likely doesn't keep your app alive indefinitely.
  • David Makogon
    David Makogon about 3 years
    @NoumanQaiser - my solution, posted here, is six years old. The settings aren't even in the same place anymore (completely different portal experience). I have no idea what issue you're running into, that you have something happen after 29 hours, but AlwaysOn deals with an issue measured in minutes, not hours (or days). And it's really odd that you posted a comment claiming (kinda yelling) this solution doesn't work, given the circumstances of your issue aren't necessarily addressed by this answer. This answer has helped many people, and (at least at the time of writing) was very accurate).
  • David Makogon
    David Makogon about 3 years
    @NoumanQaiser - you also haven't explained what "the web App turned off" means: what did you discover? How did you resolve it (or maybe you haven't resolved it)? Did the app eventually start working again or did you have to take a specific action? That would make for a great question to post here, with all of the specifics.
  • Nouman Qaiser
    Nouman Qaiser about 3 years
    @DavidMakogon I completely didn't mean to yell, Completely Apologize if it felt that way. So I have an ASP.NET Core 5 Web app, I use background tasks to run some tasks automatically every few minutes. To see if the background task is running, I log its execution in a database. Post ~29hours, the logging stops, which means the webApp has been recycled and the background task would not re initiate unless the website is accessed. I used the option for AlwaysOn but it didnot help. What eventually worked for me was CyberSpy's answer, it just stays as a workaround to keep the application alive.