How to prevent an Azure website from going to sleep? [closed]
Asked Answered
G

2

37

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?
Grantgranta answered 18/11, 2015 at 20:38 Comment(1)
Btw, does anyone know exactly how long until an azure free tier server falls asleep?Whisper
A
47

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

Anthe answered 18/11, 2015 at 22:8 Comment(12)
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.Pansir
@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.Anthe
AlwaysOn is also important to ensure any WebJobs runIncus
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.Grantgranta
Why is this not the default!Bread
@ComethTheNerd ;)Bread
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)Excalibur
It certainly doesn't work for Node applications using IIS-Node. Azure is so great!Pharynx
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.Idem
@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).Anthe
@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.Anthe
@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.Idem
S
27

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.

Soapbark answered 11/7, 2018 at 10:23 Comment(2)
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.Chlor
Sounds like this is a good solution. Within Azure 'Always On' does not prevent the app from shutting down every 29hours.Idem

© 2022 - 2024 — McMap. All rights reserved.