1

I have this administration site that is using (Fluent) NHibernate for data access. As has been stated elsewhere the initialization of the SessionFactory is slow due to creation of the Configuration object. The suggested solution is to serialize the Configuration object to disk and then reuse this untill the entity assembly or fluent initialization assembly changes.

In theory these sound very elegant and appealing. In practice even with a 1-entity model, deserializing the Configuration takes about 500ms and creating the SessionFactory another 500ms. (This is comparable to the startup time with no serialization, but I suspect the gain will be apparent once I put more entities in there.)

After IIS recycles my Application Pool, it doesn't start it up again untill a new request comes in. So with default recycle management of IIS (every 29h), and a probable scenario of an administrator logging into my administration site once a day, that 1s delay will happen almost every time this admin logs in, giving the impression of a slow starting site.

So, I wonder if there is any way to tell IIS/WAS to actually start the replacement Application Pool as part of the recycling instead of waiting untill the next request comes in? I realize this goes against the idea of WAS trying to keep as few concurrent application pools running at any given time, but it would solve my problem (as I assume my ServiceHostFactory+ServiceHost would be created as soon as the Application Pool starts up).

Gaute Løken
  • 7,522
  • 3
  • 20
  • 38
  • Hmm.. 9 views in a full day. I guess my lack of reputation is not serving me well. Any alternative solutions would be most welcome as well. Would you consider caching the config somewhere in memory, on a windows service or a com object for instance? – Gaute Løken Nov 01 '11 at 08:18

1 Answers1

0

Will IIS 7 autostart feature help you? Also, you can implement System.Web.Hosting.IProcessHostPreloadClient interface to make sure the application is up when the pool is up (see this blog post for an example).

UserControl
  • 14,766
  • 20
  • 100
  • 187
  • This feature makes sure the app pool starts up, but it doesn't load my application into a new app domain containing an instance of my service host untill a request comes in. So unless there is a way to also configure this feature to start its applications it won't help me. – Gaute Løken Nov 02 '11 at 11:24
  • Thank you UserControl, that seems to work beautifully. It will only work for hosting on Windows Server 2008 R2 and newer, which is fine with me. I hit a few snags along the way, but was able to resolve them. For example, running cmd as admin and then opening applicationHost.config with notepad++ was a very bad idea, since it allowed me to save without actually saving the file making me believe nothing was working for a long time. :) – Gaute Løken Nov 02 '11 at 16:41
  • Yes, this is very weird bug. Because 2008 R2 is x64 only you should open applicationHost.config with x64 text editor even if you have administrative privileges. It has something to do with NTFS protection. – UserControl Nov 02 '11 at 16:54