Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid passing slow Application_Start times to the end users in ASP.NET

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?

like image 277
andy Avatar asked Jul 23 '12 05:07

andy


2 Answers

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

like image 174
Facio Ratio Avatar answered Oct 23 '22 00:10

Facio Ratio


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.

like image 43
Furqan Hameedi Avatar answered Oct 22 '22 23:10

Furqan Hameedi