Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

ASP.NET app is slow at the first load

Hi,

I have an ASP.NET app that's hosted on webhost4life.com. This app uses some 3rd party libraries to create PDF files.

I have noticed that it takes a long time to load the app the first time. Next time it will be very fast. After maybe 5 minutes of inactivity it takes a long time to load again.

I think the reason for this is that after some inactivity the session gets terminated and next time all the DLLs have to be loaded again.

Any ideas how to avoid this? I have maybe 20 visitors/day so it's very likely that the app gets unloaded after each visit. Will a dedicated server perform better?

Max
Thursday, June 23, 2005

==>next time all the DLLs have to be loaded again

I imagine your issue is not the load time, but the compile time. The first time it's run, it's gotta compile everything.

Sgt. Sausage
Thursday, June 23, 2005

That's very possible. Although load times are faster when I leave out the reporting DLLs.

The big question is: How do I load the page faster? I have heard of people who will ping their site every minute. Maybe that will help?

Max
Thursday, June 23, 2005

http://winfx.msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_aspnetcon/html/aa75655b-4d5d-45c2-97b2-9bd364325879.asp

Google for "precompile asp.net" and you'll get some other techniques as well.

!
Thursday, June 23, 2005

Can I precompile the site when it's on shared hosting?

Also: I am using codebehind classes so everything shlould be compiled already. Or does the JIT do something funky?

Max
Thursday, June 23, 2005

Let's see if I remember this correctly...

Source files (*.cs, *.vb, etc.) are compiled to an IL (intermediate language) assembly using VS.NET (or command line).  This is what you deploy with your web app (MyApp.dll) in the /bin directory.  When a request is made to your app it needs to be loaded by aspnet_wp.exe and there is an intermediate step whereby your IL assembly needs to be compiled down to machine code.  This compilation is called 'Just In Time' compilation (or JIT).  It's the JIT process that is taking so long.  It's occurring because the ASP.NET worker process (aspnet_wp.exe) for your app will only keep itself alive if it's getting a certain amount of requests.  If it get's no requests in a specified amount of time (I think the default is 30 minutes) it will shutdown.  Then when the next person comes along and requests your page the whole process of loading a new worker process, JIT'ing, and processing need to happen which causes the lag time.

You'll have to ask your host if they can do anything for you as far as changing either the shutdown time of their worker processes or doing a precompile of your site for you.

!
Thursday, June 23, 2005

That makes sense. Thanks for the explanation.

I guess there are 2 things I can do:
- Get a dedicated server
- Ping the website every minute or so to keep it in memory.

Max
Thursday, June 23, 2005

The issues isn't that IIS/ASP has to load your DLL's, its that it has to turn your ASPX file into a IL file. Remember, ASPX pages with codebehinds are just another class that inherits from the codebehind itself, which in turn inherits from the Page class.

Just like JSP, the ASPX has to be turned into MSIL so that it can be run and understood.

Take a look at "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\" some time. Under each app name, you'll find a ton of xml and dll files that are created the first time your ASPX page is compiled.

A good workaround for things like this is to make sure debug is set to false in your web.config, in which case ASP_NET will compile all ASPX files in the same directory the first time a single one of them is loaded.

Matt B
Saturday, June 25, 2005

*  Recent Topics

*  Fog Creek Home