Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimize startup time for asp.net

I have multiple web services (WCF) running in IIS. When the services are warm (loaded), typical requests take about 0.5 seconds to complete. However, when the application is not warm (cold start), the first hit takes some 20 seconds before the service is up and running. The same happens when an app pool recycle occurs.

I'm looking to reduce the cold start times for this web service. Some actions i have already performed are:

  • Configured the application pool so that it doesn't recycle after 20 min, idle time (so that the application stays warm). This minimizes the occurence of cold starts, but doesn't make cold starts faster. app pool recycles are now limited, but do stil occur.

  • Modified the machine.config,

like this:

<runtime>
    <!-- see http://msdn.microsoft.com/en-us/library/bb629393(v=vs.90).aspx -->
    <generatePublisherEvidence enabled="false"/>
</runtime>

This reduces startup times from 20 secs to about 10 secs.

  • I've tried using NGEN to precompile the assemblies,

like this

for %d in (*.dll) do ngen install %d

This doesn't reduce startup times (only adds complexity to deployment).

I would really like to reduce the cold start times even further. What options do i have to do this?

(on a side note: what is the best way to find out where the time is spend during startup? how do i monitor what's going on?)

like image 734
oɔɯǝɹ Avatar asked Apr 05 '11 16:04

oɔɯǝɹ


People also ask

How do I Make my ASP NET application start up faster?

To make your ASP.NET applicationstart up faster, simply upgrade your server to ASP.NET 4.5. If you want to turn Multicore JIT off in your ASP.NET 4.5 applications, use the new profileGuidedOptimizations flag in the web.config file as follows:

How to fix the slow start up time in IIS?

You can apply a fix for the slow start times by editing some values for the site from IIS Manager. There's a good reason why IIS terminates apps that have not had any recent activity.

How can I improve the performance of my ASP web application?

ASP.NET Core apps with complex front-ends frequently serve many JavaScript, CSS, or image files. Performance of initial load requests can be improved by: Bundling, which combines multiple files into one. Minifying, which reduces the size of files by removing whitespace and comments.

How do I improve launch performance of a managed application?

Large managed applications require JIT (just-in-time) compilation at launch time, so improving launch performance can be challenging. . NET Framework developers have been able to use Ngen.exe (Native Image Generator) to move code generation from application startup time to installation time.


2 Answers

Update

I've done some further testing with procmon. There doesn't seem to be one single cause of the start up time, it's a whole lot of little timeslices (proces start, loading ,net runtime, reading configuration, loading assemblies, etc..) that add up to the total time.

like image 139
oɔɯǝɹ Avatar answered Oct 18 '22 00:10

oɔɯǝɹ


I've had decent luck with the strategy found in this article. It keeps the application alive so that once it's running, you just won't have any cold starts (unless IIS or the machine is actually restarted intentionally or as the result of a significant error). The app keeps itself alive regardless of any activity.

The article is about scheduling something to happen every so-often, but you can skip that part if your only goal is to keep the app alive.

like image 36
Joe Enos Avatar answered Oct 18 '22 00:10

Joe Enos