> | > IIS - Continuous Running Service - Recycling vs Idle Timeout

IIS - Continuous Running Service - Recycling vs Idle Timeout

Posted on Saturday, September 19, 2015 | No Comments

Hosting a Continuous Running Service in IIS

Generally when a .NET service or application is deployed to IIS under a new application pool, the Idle Timeout is set as 20 for the app pool and the recycling is enabled every 1740 minutes.

Idle Timeout

Time after which, if no requests are received, the app pool would release all memory and become idle. The app pool still remains active, and can start processing requests as soon as they arrive.

Recycling

Recycling defines the conditions that will trigger a release of the app pool's worker process resources, such as memory, threads etc. Recycling internally creates a new application pool and continues to process old requests using the old application pool till the new one is ready to accept requests. Once the new application pool is ready, the old application pool is gracefully shutdown, after all executing requests are done while any new requests are sent only to the new application pool.


Continuous Running Service

In case the service or application is to be kept alive forever, regardless of whether there are any requests coming in or not, these settings need to be changed to:

Idle Timeout: 0
Recycling: Off or based on memory consumption (recommended)

For example, services that are performing background tasks, like generating scheduled reports, processing data, etc. should keep running 24/7 irrespective of whether any requests are arriving for processing or not.

Recycling based on memory provides the advantage of having a continuous running application without worrying about memory leaks, in which case a continuous running application would keep consuming more and more memory and will finally start throwing unpredictable exceptions. In my case, these exceptions ranged from weird Win32 exceptions from 3rd party DLLs to OutOfMemory exceptions that were more intelligible.

Is Recycling the Solution?

Although recycling does solve the purpose of never having to find the service entirely stopped or memory choked, it is not really a solution, its is more of a checkpoint. It keeps the pool clean and does it gracefully for incoming requests, but it also stops running background threads unexpectedly. However, even if there are no background thread running, the application should be healthy and well coded enough to not need a recycle everyday.

This blog post focuses on how to identify issues with applications hosted in IIS that make them need frequent recycles to function correctly.

Leave a Reply

Powered by Blogger.