Precompilation and startup times on ASP.Net
Asked Answered
F

6

6

I am developping a (relatively small) website in ASP.Net 2.0. I am also using nAnt to perform some easy tweaking on my project before delivering executables. In its current state, the website is "precompiled" using

aspnet_compiler.exe -nologo -v ${Appname} -u ${target}

I have noticed that after the IIS pool is restarted (after a idle shutdown or a recycle), the application takes up to 20 seconds before it is back online (and Application_start is reached).

I don't have the same issue when I am debugging directly within Visual Studio (it takes 2 seconds to start) so I am wondering if the aspnet_compiler is really such a good idea.

I couldn't find much on MSDN. How do you compile your websites for production?

Fetus answered 11/9, 2008 at 11:53 Comment(0)
D
4

Make sure that:

  1. You are using a Web Application project rather than a Web Site project, this will result in a precompiled binary for your code behind
  2. You have turned off debug code generation in the web.config file - I guess if this is different to when you used aspnet_compiler the code may be recompiled

If you've tried those, you could maybe try running ngen over your assembly thus saving the JIT time?

Duple answered 11/9, 2008 at 11:56 Comment(0)
K
4

For ultimate reponsiveness, don't allow your app to be shutdown.

The first method is to make sure that it's incredibly popular so that there's always someone using it.

Alternatively, fetching a tiny keep-alive page from somewhere else as a scheduled activity can be used to keep your site 'hot'.

Kramatorsk answered 11/9, 2008 at 12:38 Comment(2)
I find it interesting that two people have voted my answer down without comment, despite the fact that it's a realistic approach used by some very big systems. Note that DotNetNuke includes keepalive.aspx for precisely this purpose.Kramatorsk
Not me, but I would assume the downvotes are because this doesn't reduce startup time. Further, this is unnecessary on IIS7.5/.Net 4, as ASP .Net 4.0 ships with an auto-start feature which accomplishes the same thing.Overword
V
2

If your website is compiled as updatable, you'll see a bunch of .ASPX files in your virtual directory. These must be compiled on startup. That's so you can come in and alter the web UI itself. This is default for both websites and web applications.

Veii answered 11/9, 2008 at 12:19 Comment(0)
T
1

Make sure this is set in web.config <compilation debug=false>. In my case, I also have a batch file which issue Get requests for all the main pages before giving to users (page loading simulation).

Tubb answered 11/9, 2008 at 12:0 Comment(0)
L
1

The key is to make sure the IIS Application Pool never shuts down. This is where the code is actually hosted. Set the "Idle Timeout" (Under Advanced Settings) to something really high, like 1440 minutes (24 hours) to make sure it's not shut down as long as somebody hits your site once a day.

You are still going to have the JIT time whenever you deploy new code, or if this idle timeout period is exceeded witout any traffic.

Configuring IIS 7.x Idle Timeout

Laurentium answered 6/4, 2011 at 21:32 Comment(0)
F
0

@Simon:

  • The project is a Web Application. Websites are then slower to startup (I had no idea it had an incidence, beside the different code organization)?
  • I checked, and while I edit the web.config after aspnet_compiler is called, I don't touch the debug value (I will however check the website is not faster to startup if I don't touch the web.config, just to make sure)

(And I will definitely have a look at ngen, I was not aware of that tool.)

Fetus answered 11/9, 2008 at 12:5 Comment(1)
I think the web applications vs. sites thing may actually be to do with the updatable bit as Will mentions - my apps are not marked updatable. I think you're probably right about the organisation thing, I'd need to have a bit more of a play to confirm.Duple

© 2022 - 2024 — McMap. All rights reserved.