By default, an IIS application pool (or “AppPool”) recycles on a regular time interval of 1740 minutes, or 29 hours. One reason for this time interval is that application pools don’t recycle at the same moment every day (every day at 07.00 for example). However, sometimes you want to change this regular time interval to specific times. And when you try to configure this in IIS Manager, it gives you an error. Luckily, AppCmd and PowerShell come to the rescue!
Recycling means the worker process that handles requests for an application pool is terminated and a new worker process is started.
Why is IIS’ default application pool recycling set to 1740 minutes? One reason for this time interval is that application pools don’t recycle at the same moment every day, and 29 hours for the simple reason that it’s the smallest prime number over 24. A staggered and non-repeating pattern that doesn’t occur more frequently than once per day, “you don’t get a resonate pattern” (Source: Scott Forsyth’s Blog).
Imagine your IIS application pool (AppPools) are configured to recycle on a regular time interval of 1740 minutes, and you want to change this setting through Internet Information Services (IIS) Manager to a time interval. You either browse to an application pool and its Advanced Settings, or you try to set Application Pool Defaults.
When you set the Regular Time Interval (minutes) to 0, an error message pops up:
The ‘Idle Time-out (minutes)’ property of the application pool’s process model must be less than the Regular Time Interval (minutes)’ property of the application pool’s period restart.
Setting the AppPool Idle Time-out property to zero (0) -because you want to set the Regular Time Interval to 0- may result in unwanted AppPool and website behavior… This is a known bug in the IIS Manager GUI.
Configure a periodicRestart
Fortunately you can use AppCmd to configure these Regular Time Interval and Specific Times Application Pool Defaults settings. First you have to set the Regular Time Interval to 0:
AppCmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.recycling.periodicRestart.time:"00:00:00" /commit:apphost
Next, you’ll configure a Periodic Restart Schedule (4 A.M):
AppCmd set config -section:system.applicationHost/applicationPools "/+applicationPoolDefaults.recycling.periodicRestart.schedule.[@0,value='04:00:00']" /commit:apphost
@0 numeric index is used so more than one periodic restart schedules can be created (not sure this is necessary). This makes all application pools to recycle at 4 A.M in the morning, suppose you would want this.
If you want to use a more PowerShell solution to set an application pool to recycle on a specific time (in stead of a regular interval), you can use the following PS snippets:
Set-WebConfiguration ` /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart ` -value "0"
And then you add a specific time for the application pool to recycle on (note the
Add-WebConfiguration ` /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule ` -value (New-TimeSpan -h 4 -m 00)
Verify your newly made settings:
Get-WebConfiguration ` /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule/add ` | select value
If you have set one or more specific times recycle values for an application pool, use the following PowerShell command to get the values:
(Get-ItemProperty ('IIS:\AppPools\example.org') -Name Recycling.periodicRestart.schedule.collection) | select value
The output is for example set to every 6 hours on the hour, starting at midnight:
value ----- 00:00:00 06:00:00 12:00:00 18:00:00
recycling.periodicRestart.schedule using appcmd:
appcmd.exe list apppool example.com /config
The appcmd command above will list the current application pool ‘example.com’ configuration, including its scheduled periodicRestart. Substitute
/text:* for all configuration settings for that pool.
After setting the regular time interval to 0, you may use the IIS Manager GUI to configure Application Pool Defaults and a Periodic Restart schedule.
If you want to reset your application pool recycling defaults back to periodicRestart (Regular Time Interval), you can do so with the following appcmd command:
# Set applicationPoolDefaults.recycling.periodicRestart.time # to 29 hours, 1 minute, or 1741 minutes AppCmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.recycling.periodicRestart.time:"29:01:00" /commit:apphost
# Set applicationPoolDefaults.recycling.periodicRestart.time # to 29 hours, or 1740 minutes AppCmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.recycling.periodicRestart.time:"29:00:00" /commit:apphost
Note: If the Regular Time Interval default is set to 41760 minutes / 29 days, you must reset this to a non-default value. For example 1741. When that’s saved to
applicationHost.config, you can reset it back to it’s original regular time interval of 1740 minutes.
My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, WordPress, websites & optimization. Want to support me and donate? Use this link: https://paypal.me/jreilink.