ASP.NET Core with IIS: Prevent Slow Startup & Cold Boot

Posted on 13th June 2020

When I first started deploying ASP.NET Core web apps to IIS, I found that if the site wasn't accessed for about 20 minutes, there would be an extremely slow load time. These cold boots would take around 10-15x longer than standard page loads.

Cold boots are usually not a problem for sites accessed on a regular basis, however it's a big inconvenience when someone tries to access the app for the first thing in the morning, for example on an intranet or a company's internal backend. There's also times when you might have an infrequently used API which must always have fast load times.

You can apply a fix for the slow start times by editing some values for the site from IIS Manager.

Why IIS Terminates The App

There's a good reason why IIS terminates apps that have not had any recent activity. Some people may have many sites running on a single server and by terminating the process of apps that have not been used for a while, the system is able to free up hardware resources for other apps.

Terminating the app also helps deal with "potential memory leaks" however in the real world this doesn’t really seem to be a problem that most users of C# / ASP.NET Core will experience.

So the termination of apps may not be useful for your use-case, so feel free to alter the timeout by following the below instructions.

Instructions

Start by opening IIS manager, navigating to Application Pools and then clicking on the application pool used by your website or API. Then click on the Advanced Settings button.

IIS App pool advanced settings

Scroll down until you see Idle Timeout (Minutes) and change this to whatever integer you want. I usually set mine to 1440 minutes which is 24 hours.

IIS app pool inactivity timeout

And that should be it. IIS should now wait longer before terminating the current process running your app due to inactivity.


Article Categories: # .net # c# # iis

About

A tech blog by Andy P. I talk about coding, enterprise software development, tech, games design & other things that interest me.

Signup To The Newsletter

I try to post a new interesting article every saturday.