Reputation: 139
We have about 200 DLLs (150MB+ in size) in our ASP.NET MVC 3.0 app, and the startup time in development, is about ~60 seconds.
Every time we modify a project and rebuild it to get a new DLL to be deployed, once we chuck that new DLL into "webapp\bin" folder, IIS re-JIT every other DLLs as well (which has not changed) and this maxes out 1 CPU core and takes about 60 seconds.
What can I do to speed this loading time up?
Upvotes: 4
Views: 1231
Reputation: 31
Just to add to @Zverev Evgeniy's answer: instead of type="CAssemblyResolveHttpModule", I had to use the fully qualified type name to make it work.
Upvotes: 0
Reputation: 3719
The easiest way is not to put all the application DLLs into the webapp\bin which is watched by IIS. You can utilize dynamic DLL load from a custom location using the AppDomain.AssemblyResolve Event.
For that you will need to register an HttpModule
in the web.config
</configuration>
</system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="CAssemblyResolveHttpModule"/>
<add name="CAssemblyResolveHttpModule"
type="CAssemblyResolveHttpModule"/>
</modules>
</system.webServer>
</configuration>
And an implementation for it:
public class CAssemblyResolveHttpModule : IHttpModule
{
public void Init(System.Web.HttpApplication iContext)
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
private Assembly CurrentDomain_AssemblyResolve(
object iSender,
ResolveEventArgs iArgs)
{
return Assembly.LoadFrom(...);
}
}
Besides that you can prevent IIS from recycling the ASP.NET Application when bin folder changes via IIS settings:
Can I prevent IIS from recycling if /bin changes It is simple:
In the Application Pool > Advanced Settings > Recycling
section, set the Disable Recyling for Configuation Changes
to True
.
If you move most of your DLLs out of the app bin folder the IIS application pool recycling will take not more than a few moments. In order to catch up another new DLL version you will need to recycle the application pool.
If you still wish to avoid app pool recycling altogether you can use the strategy of a custom app domain pool. Here you can get code samples: Create custom AppDomain and add assemblies to it
Upvotes: 4
Reputation: 22281
If most of the DLLs do not get used immediately, you can place them in the GAC. This prevents ASP.Net from loading them on startup and also elides signing verification when they are actually loaded.
Upvotes: 0