tags:

views:

285

answers:

4

After years of ASP.NET development I'm actually quite surprised that I can't seem to find a satisfying solution for this.

Why does an IIS ASP.NET site always seem to fall asleep (for 2-6 seconds) after a certain time of inactivity (after several hours), during which no HTTP response is sent from server to client. This happens on any type of site, one page or many, db or not, regardless the settings. How can I fix this?

During the wait time, the server is not busy and there are no high peaks or (.NET) memory shortages. My guess is, it has to do with Windows moving the IIS process to the background and its memory to the page file, but I'm not sure. Anybody any idea?

EDIT: one solution is to send some HTTP request once an hour or so, but I hope for something more constructive.
EDIT: what I meant is: after hours of inactivity, it pauses several seconds on any new HTTP request.

+3  A: 

The default timeout for IIS is 20 minutes. What this means is if your ASP.NET application does not receive any new requests for 20 minutes, it will shut down the worker process. It can take a considerable amount of time to warm up the process from nothing - loading assemblies into memory, precompilation, etc.

(Edit: I put together a simple helper class that resolves the standard timeout issue - basically the web application "pokes" itself every so often to keep the process alive. The ideal approach is to change the setting in IIS, but for servers where this is not possible, my class works quite well.)

While the worker process is still alive, it should not be deprioritized. Certainly not as quickly as you're describing. It is possible you could relying on items that are cached for a very short period of time, and are falling out when they've not been requested for more than a few seconds. Without knowing more about the details of your application, it's impossible to say.

As usual, profiling your application is the only way to yield concrete information. Using a product like ANTS will help you determine where in the code your application is spending the most time, so you can isolate where the "hang" is occurring.

Rex M
You point at some interesting thoughts. I always assumed it never got to the `Application_Start`, but what do I know, perhaps it gets there, loads libs etc, and then resumes. Please note that the time is not 20min (session timeout time), it chokes for a little while after approx 3+ hours, but I'm not sure. The time may be variable. It's not just "a site", it's "all sites" on many systems and IIS / Windows versions. All are .NET 3.5 though.
Abel
On *"but what do I know"* >>> meant to say: I should log, or turn Trace on or whatever. I know ANTS but not sure it can help here: the blocking seems to happen before anything is loaded, which would include ANTS.
Abel
Just noticed same comment here http://www.eggheadcafe.com/software/aspnet/30548981/slow-site-startup.aspx, which mentions this idle timeout. It doesn't happen locally, only remote on configurations I do not always manage. It shouldn't take long to figure out whether it's all in this setting.
Abel
+2! That's an excellent little class, with a very nice technique! My own approach so far was with a background thread, but if you know the troubles of threads in ASP.NET I rather avoid them. Using cached objects and its timeouts is excellent. Q. should stay on SO now :P
Abel
A: 

I have faced with this slow loading problem and found a kind of way of tackling it. It has a drawback but can be considered.

Murat Yasar
Your blog post is mainly about recompilation when an edit occurs. But thanks for the effort.
Abel
+1  A: 

If you're using IIS 7 there is an IIS plugin call Application Warm Up from the IIS team that will help keep everything toasty

I've written a blog post about my experiences using it.

Doug
Interesting plugin. Also, the 20 min timeout can be set on the application pool. I set it to 24 hours on most servers, which helps (PS: your site is unresponsive...)
Abel
Hilarious - i'm assuming the blog was rebuilding haha - how ironic
Doug
A: 

If you are only compiling your code behind at the moment, then you might also want to look at pre-compiling your aspx files at complile time (rather than runtime, which is the default). I believe that this on the fly compilation is what takes up most of the time when a dormant ASP.NET site is woken up. You can read more about it here.

Update:

The application pool gets killed when the IdleTime-Out value is reached - this defaults to 20mins (you can change this value). Are you sure that UI isn't getting recompiled after the app is restarted in this case? (I'm not sure if it forces a UI recompile or not).

UpTheCreek
While your statement is correct, compiling pages only happens once, even if you do not choose precompiling (which I prefer if I have a say in a project). The issue mentioned in the question is caused after any 20 minutes of inactivity and could be considered the "sleep mode" of the application pool. Check your logs if you have a small local website: when the first customers arrive at 4AM, you will see a long wait time for the very first requests.
Abel
What version of IIS are you using? and Do you have Admin access to IIS?
UpTheCreek