views:

3151

answers:

6

I have an ASP.NET 3.5 website running under IIS7 on Windows 2008.

When I restart IIS (iisreset), then hit a page, the initial startup is really slow.

I see the following activity in Process Explorer:

  • w3wp.exe spawns, but shows 0% CPU activity for about 60 seconds
  • Finally, w3wp.exe goes to 50% CPU for about 5 seconds and then the page loads.

I don't see any other processes using CPU during this time either. It basically just hangs.

What's going on during all that time? How can I track down what is taking all this time?

+2  A: 

IL is being converted into machine native code (Assembly) by the Just-In-Time compiler and you get to wait while all the magic happens.

When compiling the source code to managed code, the compiler translates the source into Microsoft intermediate language (MSIL). This is a CPU-independent set of instructions that can efficiently be converted to native code. Microsoft intermediate language (MSIL) is a translation used as the output of a number of compilers. It is the input to a just-in-time (JIT) compiler. The Common Language Runtime includes a JIT compiler for the conversion of MSIL to native code.

Before Microsoft Intermediate Language (MSIL) can be executed it, must be converted by the .NET Framework just-in-time (JIT) compiler to native code. This is CPU-specific code that runs on the same computer architecture as the JIT compiler. Rather than using time and memory to convert all of the MSIL in a portable executable (PE) file to native code. It converts the MSIL as needed whilst executing, then caches the resulting native code so its accessible for any subsequent calls.

source

Ty
If it was JIT compiling, wouldn't I see csc.exe in Process Explorer? I don't see csc.exe running during the 60 seconds wait.
frankadelic
@frankadelic csc.exe is the C# compiler. The JIT is part of .NET and why .NET needs to be installed on machines running C#.
Ty
Whether it was csc or the JIT, you'd see CPU usage.
Sebastian Good
+3  A: 

Thats the compilation of asp.Net pages into intermediate language + JIT compilation - it only happens the first time the page is loaded. (See http://msdn.microsoft.com/en-us/library/ms366723.aspx)

If it really bothers you then you can stop it from happening by pre-compiling your site.

EDIT: Just re-read the question - 60 seconds is very long, and you would expect to see some processor activity during that time. Check the EventLog for errors / messages in the System and Application destinations. Also try creating a crash dump of the w3wp process during this 60 seconds - there is an chance you might recognise what its doing by looking at some of the call stacks.

If it takes exactly 60 seconds each time then its likely that its waiting for something to time out - 60 seconds is a nice round number. Make sure that it has proper connections to the domain controllers etc...

(If there are some IIS diagnostic tools that would do a better job then I'm afraid I'm not aware of them, this question might be more suited to ServerFault, the above is a much more developer-ish approach to troubleshooting :-p)

Kragen
as mentioned in other comments - I don't see any csc.exe running during this delay.
frankadelic
A: 

This hat nothing to do with JIT compiling. The normal C# compiler compiles your code behind files (.aspx.cs) into intermediate language into an assembly at startup if this assembly dont exist or code files have changed. Your web site assembly is located in the "bin" folder of your web site.

In fact the JIT compiling occures after that, but this is very fast and won't take several minutes. JIT Compiling happens on every startup of an .net application and that won't take more than a view seconds.

You can avoid the copmpiling of your web site if you deploy the already compiled website assembly (YourWebsite.dll) into the bin folder. It is also possible to deploy only the aspx files and leave the code behind files (aspx.cs) files away.

Thomas Maierhofer
Actually, even with a pre-compiled site, the .aspx, .ascx, etc are parsed into C# code, compiled and then JIT'd as well. So there is quite a lot of activity when warming up an ASP.NET app for the first time.
Kev
A: 

Greater than 60 seconds sounds fishy. Try running a test.html page to see how long that takes. That will isolate IIS7's role.

Then temporarily rename your web.config, global.asax and application folders and try a test.aspx page (very simple page). That will isolate ASP.NET.

If both of those are fast (i.e. about 10 seconds), then it's your application. But, if either are slow then not the application and something with the server itself.

Scott Forsyth
Test HTML page took about 2 seconds after the iisreset.If IIS was running and I change web.config, it takes maybe 3 seconds to load a test ASPX page.
frankadelic
It sounds like IIS and ASP.NET are doing well then. It must be something in the app that is causing this. If it's only slow on the first load then it's the conversation into native code. Do you have a massive project? I would review your project type and size and see about breaking it into parts or pre-compile before you upload to the server.
Scott Forsyth
A: 

We had a similar problem and it turned out to be Windows timing out checking for the revocation of signing certificates. Check to see if your server is trying to call out somewhere (e.g. crl.microsoft.com). Perhaps you have a proxy setting incorrect? Or a firewall in the way? We ultimately determined we had enough control over the server and did not want to 'call home', so we simply disabled the check. You can do this with .NET 2.0 SP1 and later by adding the following to the machine.config.

<runtime> <generatePublisherEvidence enabled="false"/> </runtime>

I am not sure if you can just put this in your app.config/web.config.

Sebastian Good