Windows Azure Web MVC app Application_Start rerunning after no activity - asp.net-mvc-3

I have a Windows Azure hosted MVC3 application. In the Application_Start, I call all of my bootstrappers that need to run before the application loads and that is working great. One of the bootstrappers that runs, hits up some web service APIs to preload and cache a bunch of data. This process can take 10-15 seconds which is fine because it's in Application_Start and is a one time hit after I deploy and hit up the site myself.
The site isn't launched yet and I've found that once I deploy and click around for a bit everything is fine and really quick, then if I leave the site alone for 45 mins or so and go back to it, there is a long delay when loading the page. Through logging I've found that the Application_Start is getting fired and I'm having to wait for the site to fire back up and run all my bootstrappers.
My question is, is it normal for an Azure WebRole to "go to sleep" if there is inactivity? And if so, how can I stop that from happening so that my lucky user that accesses the site that time doesn't have a long wait time and bad experience.

By default, IIS has a 20-minute timeout on idle applications before it unloads them. Consider using a startup task to disable this timeout: http://blog.smarx.com/posts/controlling-application-pool-idle-timeouts-in-windows-azure.

Related

Is it normal to experience long load time accessing your website on heroku?

When I try to access https://boiling-bastion-xxxx.herokuapp.com/, it takes about 5 seconds or more to load. Is that normal?
Once it loads, it runs fine. I'm talking about actually accessing the link for the first time. Is this the same for others as well?
Yes, this is completely normal.
There's information about it on devcenter.heroku.com: https://devcenter.heroku.com/articles/dynos#dyno-idling
If your application has one hour of inactivity your web dyno will idle out. If you access your application after one hour the web dyno will wake up again, causing a few seconds of delay.
Important:
This is only a problem when you have one (free) web dyno. If you have more then 1 web dyno running you will never face these troubles.

MVC3 Speed on production iis7

I have an MVC3 application which is working fast in my dev environment (even when pointed at the production database). However, when I publish the application and move it onto the production iis7 environment it runs at a snails pace. I understand that the inital load can take a few seconds as the application pool starts up, but this is taking 20+ seconds. Then will be fast for a few clicks and the next click will again take 20+ seconds.
I've put in the MVCMiniPorifler and it doesn't look like the database is causing problems. But, I also can't see what is causing the problem. I can hit the same page multiple times and it comes back in a second or 2 and then suddenly that same page will take 20+ seconds to respond.
Has anyone seen this sort of behaviour before? Any help would be greatly appreciated and I'm not sure what to try next.
It's possible that the other web apps running on your production server are locking required resources. Is there a common file or folder that multiple sites utilize? Are you sharing the app pool between any of the sites?

What exactly happens when I change number of Azure role instances?

I observe the following weird behavior. I have an Azure web role which is deployed on love Azure cloud. Now I click "Configure" in the Azure Management Portal and change the number of instances - the portal shows some "activity". Now I open the browser and navigate to the URL assigned to my deployment and start refreshing the page something like once per two seconds. The page reloads fine many times and then fro some time it will stop reloading - the request will be rejected, then after something like half a minute the requests are handled normally.
What is happening? Is the web server temporarily stopped? How do I change number of instances so that HTTP requests to the role are handled at all times?
When you change the configuration file, your current instance might be restarted. This might be the reason you met with, which your website didn't response in about 30 seconds.
Please have a look http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.changing.aspx and check if it 's because of the role restarting.
What you are doing is manual. Have you looked at the SDK for autoscaling Azure?
http://channel9.msdn.com/posts/Autoscaling-Windows-Azure-applications
Check out the demo at the 18 minute mark. It doesn't answer your question directly, but its a much more configurable/dynamic way of scaling Azure.
Azure updates your roles one update domain at a time, so in theory you should see no downtime when updating the config (provided you have at least two instances). However, if you refresh the browser every couple of seconds, it's possible that your requests go always to the same instance due to keep-alive.
It would be interesting to know what the behavior is if you disable keep-alives for your webrole. Note that this will have a performance impact, so you'll probably want to re-enable keep-alives after the exercise.

Simulating background task on AppHarbor

I'm using System.Runtime.Caching.MemoryCache to simulate a repeated task on a running .NET MVC application deployed on AppHarbor.
Entries in the cache are added using a CacheItemPolicy which contains an AbsoluteExpiration offset and a RemovedCallback that calls a method and retriggers the adding of the item in the cache (as described here)
MemoryCache is populated first time in Application_Start. It works fine locally, but doesn't seem to work once deployed on AppHarbor (tried also with HttpRuntime.Cache, same result).
My application is running under a CANOE (free) account on AppHarbor that only has one worker. Does this mean that I won't be able to simulate the background task until I upgrade to some paid plan?
Thanks!
Your application has to have visitors every once in a while for this to work. Other than StillAlive, Pingdom is also a good bet for generating requests to your app. You should also take a look at MomentApp. We expect to have background tasks ready shortly.
I don't think upgrading will help, they are working on adding background jobs to AppHarbor but to my knowledge they available yet.
What about using a service like https://stillalive.com/ to periodically hit a page on your site that then spins up a new thread and starts running your background task? Its available as a free add-on.
I was thinking of doing something like this while waiting for the background task functionality to be available.

ASP.NET Worker process getting killed when web app is inactive

My hosted ASP.NET MVC app takes long time (10-20 secs) when it launches. And after ASP.NET worker process is running, everything is normal. Problem is that the worker process is getting killed when the web site is inactive (i.e., no user). This will give the next user very long wait time to load the web site.
I know there is commercial or free services on the web that makes your web worker process alive. But I need to do that myself with simple timer windows service. No problem there. But my question is what is effective way to makes it alive? Would a simple ping do it or is downloading from the web site necessary?
I'd recommend you set up an empty aspx page on the site and see if requesting it occasionally will fulfill your requirement. You should only have to make a request to keep the worker alive.

Resources