It's not easy to explain what the problem really is, but I try to ;-).
Here's some data:
- Microsoft Server with IIS7 (not RC2)
- 3GB Ram
- Only this application is on this server
- SQL 2008 Express
- Repository Pattern
- SimpleInjector
- MVCSitemapProvider
Ok now to the problem. It's not the startup because the site is loaded in 2sec. after app pool recycling. After the startup the pages are loaded in 200ms or less (or more), but sometimes (I cannot say when, because it's randomly and its NOT after the recycling) they need up to 2 minutes or more.
I tried glimpse to find the problem. It shows something like:
- ASP.NET begin request: 121456ms (this is randomly)
- Filter: 2ms
- Controller: 26ms
- Views: 298ms
- ASP.NET end request: 0ms
It's like a request stacking, I don't know.
EDIT:
So I've removed the whole MVC SiteMap Provider but the phantom perfomance issue was still here.
Then I've checked the IIS Configuration and noticed that the AppPool was a NetworkService instead of ApplicationPoolIdentity (the other MVC solutions run on ApplicationPoolIdentity) and now it seems even faster as before (page loads < 50ms)! If the problem still occurs I'll write in this thread.
I had a very similar issue on an MVC3 project with a somewhat similar architecture to what you're describing above. Our issue turned out to be tied to the MVCSitemapProvider. I will look for my notes as to what the specific issue was, but we found that if we disabled the SiteMap creating the menus, just as a test, everything was lightning fast, then when we turned that back on it would get slow.
I would recommend that as a next step for debugging the issue.
Okay, I talked to one of my co-workers from the project and I recall now. There are a couple problems. First of all, the MVC Sitemap Provider swallows all of its exceptions; this is not entirely bad but does make trouble-shooting difficult. We found two different scenarios that caused two slightly different issues, both causing a slowdown. First of all I do assume that in your _Layout.cshtml or whatever layout file, you are including a call to the provider to generate your menu and perhaps breadcrumbs as well.
- If you have a controller action that you have not defined in the sitemap, any time you go to that page, the attempt to generate the menu and breadcrumbs throws exception after exception and you never see them; this is highly costly and slows that page down.
- If you have a node defined in your sitemap that points to a controller action that is misspelled or just does not exist, every single time the sitemap tries to render the menu and/or the breadcrumbs, it will throw and swallow many exceptions, for every single page.
Because of these two and other issues we had with the sitemap, I would really recommend scouring your sitemap file and making sure that you are representing all your controller actions within there, and that you don't have any nodes incorrectly defined. If you cannot be entirely sure, you may want to even put some breakpoints in the sitemap code and step through it to see if it's throwing exceptions for you and then trace backwards from there.