11

I have quite a slow Application_Start due to having a lot of IoC stuff happen at start up.

The problem I'm trying to solve is, how do I avoid passing that start up time to the end user?

Assumptions

My apps are hosted on AppHarbor so I have no access to IIS. However even if I did, my understudying is that it's best practice to let the app pool recycle, so there's no way to avoid having the Application_Start run regularly (I think it's every 20 minutes on AppHarbor).

My idea to solve it

Initially I thought I'd hit it every minute or something, but that seems too brute force and it may not even stop a user from experiencing the slow start up.

My current solution is to handle the Application_End event, and then immediately hit the App so that it starts up again, thus hopefully not impacting any users.

Is there a better way to solve this issue?

4

2 回答 2

5

Unfortunately, a longer session timeout will not prevent an IIS app pool recycle when you're using InProcess session state.

Have you considered lazy loading (some of) your dependencies? SimpleInjector has documentation on how to do this, which should be adaptable to most other IoCs:

Simple Injector \ Documentation \ How To \ Register Factory Delegates \ Working With Lazy Factories

于 2012-07-27T17:14:54.497 回答
3

In my understanding, to prevent the propagation of startup time to users, you should avoid recycling the App Pool, for which you can use IIS App pool timeout settings,these can be tuned through web.config, not just through IIS console. Additionally you can read more of it here on this SO qurestion. You might not need Application_End hacks to achieve this.

Update : I found another interesting thing that may help you on this, check this IIS Application Initialization Extension that can be used to preload dependencies as soon as worker process starts. It may help you improve customer experience. Check it out.

于 2012-07-25T07:55:19.380 回答