I'm developing sites based on .NET platform. I usually deploy these sites on my local IIS, so that I can test them and see their functionality before going live. However, each time I restart windows, it seems that sites take a long time to run for the first time.

I know about JIT and I'm also aware of this question, but it doesn't answer my question.

Does JIT happens every time you restart windows? Is it related to creation of w3wp.exe process? Why sites are so slow for the first request after each restart?

  • 3
    This is known as "cold start" or something. The system has to load the w3wp into memory, which also needs all related dlls, probably JIT stuff, process import tables, read data from disk, as it's not in RAM cache, etc.
    – Coder
    Aug 1 '11 at 10:15
  • @Coder, +1 for your comment. But could you please explain more in an answer, so that I and other developer would use benefit. :) Aug 1 '11 at 10:19
  • IIS is not my speciality, so I hope someone will give a better answer. Here is a similar topic I started a while ago stackoverflow.com/questions/3807791/cold-startup-optimization Maybe it'll help some more.
    – Coder
    Aug 1 '11 at 10:32
  • 4
    This question appears to be off-topic because it is about an implementation issue and not a conceptual programming problem.
    – user53019
    Mar 24 '14 at 11:20

This problem is the JIT compile. The application pool needs time to build the libraries before it can begin processing them. This can be sped up by using a warmup script, but it's something that needs to happen. It also depends on whether you're using a website or a web application project. A website is JIT for every page so the very first hit is slow and each new page hit has an extra compile time as well. Web application projects are precompiled so should not suffer this hit as badly, but the libraries still need to be loaded up. The more libraries/tools you have the worse this hit tends to be. Here are some links that discuss the warm up:

http://weblogs.asp.net/gunnarpeipman/archive/2010/01/22/iis-application-warm-up-module.aspx http://blogs.iis.net/steveschofield/archive/2009/05/30/application-pool-warm-up.aspx https://stackoverflow.com/questions/2063461/iis-web-applications-warmup http://sharepoint.smayes.com/2011/06/application-pool-specific-warm-up-scripts/

  • 6
    This is mostly correct but there's a difference between compiling and jitting that isn't clear in this answer. Jitting is compiling the .NET bytecode to machine code. ASP.NET is actually compiling those web pages, even in a Web Application Project (unless you use the aspnet_compiler). All that compile/build time, plus the jitting and library load time, is why it's so slow.
    – Aaronaught
    Aug 1 '11 at 12:37
  • JIT just stands for just-in-time. There is no difference between "jitting" and "compiling", beyond the timing and amount of code that is compiled. Also, JIT compilation only happens for each unvisited code, not necessarily for each page. If they use the same template, e.g., compilation isn't necessary. The remark that more libraries lead to more time taken to compile is completely true, of course.
    – Cornelius
    Jan 28 '15 at 16:39

The slow reaction on your first request is because IIS only starts/loads a site or application pool on it's first incoming request. And after a fixed amount of time no new incoming requests arrive at the server IIS stops the site again (app pool recycling).

ASP.NET 4.0 has a new feature called auto-start. With this feature you can set an application pool or individual site to start itself before any requests. This is triggered on boot time (when IIS starts) or when you update an ASP.NET site (which stops the site).

    <add name="MyAppPool" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />

    <site name="MySite" id="1">
        <application path="/" serviceAutoStartEnabled="true" />

You need IIS 7.5 to use this.

There's also an option to perform certain extra tasks when the auto-start kicks in, ex. to preload data into cache.

  • Normally you compile your full site before you put it on the web server, so the code doesn't need to been compiled any more on the first request. JIT is only used for sites using the App_code folder where you publish your source code with the website.
    – Stief
    Aug 19 '11 at 13:31

Part of the problem is also the GAC. Libraries places there will need to be security checked everytime they are loaded up - that means a whole load of encryption type work being carried out, and this slows things down a lot. There was a talk about WPF performance a while back from MS that described this problem - their answer was "don't put stuff in the GAC if you can't help it"

  • 1
    That should be "can help it" to avoid a double negative Mar 18 '14 at 21:03

IIS has an annoying (sometimes) feature for low traffic websites. It recycles unused worker processes – which cause the first user to the site; sometimes extremely long delay (30+ seconds). http://dotnettimes.wordpress.com/2014/03/24/fixing-slow-initial-load-for-iis-web-site/

Not the answer you're looking for? Browse other questions tagged or ask your own question.