34

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?

Saeed Neamati
  • 18,318

4 Answers4

35

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/

Joel Etherton
  • 11,684
  • 7
  • 47
  • 55
10

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).

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

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

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.

Stief
  • 101
2

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"

gbjbaanb
  • 48,749
  • 7
  • 106
  • 173
1

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/

S_007
  • 11