Technical Deep Dive: Why IIS Worker Process Defaults to 29-Hour Recycling Instead of 24/48 Hours


1 views

In IIS configuration, you'll notice the worker process (w3wp.exe) defaults to recycling every 1740 minutes (29 hours) rather than the more intuitive 24-hour cycle. This isn't arbitrary - it's a deliberate design choice by Microsoft's IIS team to avoid predictable recycling patterns.

Consider what would happen with 24-hour recycling:

// Typical 24-hour recycling scenario
var recycleTime = DateTime.Today.AddDays(1); // Midnight

If all IIS servers recycled at midnight:

  • Service disruptions would cluster during peak maintenance windows
  • Monitoring systems might miss patterns seeing identical timestamps
  • Load balancers would receive simultaneous restart requests

The 29-hour cycle creates staggered recycling across server farms.

The extended period accommodates:

// Memory usage pattern over 29 hours
MemoryCache.Default.Add("cacheKey", bigObject, 
    DateTime.Now.AddHours(29)); // Aligns with recycle
  1. Allows full daily traffic patterns to complete (24h)
  2. Adds buffer for long-running processes (+5h)
  3. Prevents overlap with common backup schedules

While 29 hours works well for most scenarios, you might want custom settings:

// PowerShell to modify recycling
Set-ItemProperty IIS:\AppPools\DefaultAppPool 
    -Name Recycling.periodicRestart.time 
    -Value "00:05:00" # Test with shorter intervals

Consider overriding when:

  • Using memory-intensive applications
  • Running in containerized environments
  • Debugging memory leaks

Track recycling programmatically:

// C# to log recycling events
EventLog.GetEventLogs().First(x => x.Log == "Application")
    .EntryWritten += (sender, e) => 
    {
        if (e.Entry.Source == "IIS")
            Logger.Log($"Recycle at {DateTime.Now}");
    };

When you deploy a website on IIS, the worker process (w3wp.exe) is configured to recycle every 1740 minutes (29 hours) by default. This behavior often raises eyebrows among developers who expect round numbers like 24 or 48 hours. Let's break down why Microsoft chose this specific interval.

The 29-hour cycle serves two primary purposes:

  • Preventing simultaneous recycling: If all IIS servers recycled at exactly 24 hours, they might sync up over time and cause performance spikes.
  • Avoiding peak traffic periods: The odd interval ensures recycling doesn't consistently occur during business hours or maintenance windows.

Here's how you can modify this setting in applicationHost.config:

<applicationPools>
    <add name="MyAppPool">
        <recycling periodicRestart="time">
            <schedule>
                <add value="29:00:00" />
            </schedule>
        </recycling>
    </add>
</applicationPools>

While you can change the interval, consider these factors:

// PowerShell command to check current recycling settings
Get-ItemProperty IIS:\AppPools\DefaultAppPool -Name Recycling.periodicRestartTime

For mission-critical applications, you might want to implement custom recycling logic:

// C# example for manual recycling
using (ServerManager serverManager = new ServerManager())
{
    ApplicationPool appPool = serverManager.ApplicationPools["MyAppPool"];
    appPool.Recycle();
    serverManager.CommitChanges();
}

Track recycling events in Event Viewer with this XPath query:

<QueryList>
    <Query Id="0" Path="System">
        <Select Path="System">
            *[System[Provider[@Name='Microsoft-Windows-IIS-W3SVC'] 
            and (EventID=1074 or EventID=1076)]]
        </Select>
    </Query>
</QueryList>