IIS Application Initialization and Idle Timeout: Eliminating the First-Request Penalty

The first request to an IIS application after a period of inactivity is slow, and the reason is structural rather than incidental. The worker process recycles after the idle timeout, the application pool empties, the .NET runtime unloads, and the first request afterwards pays for everything at once: runtime initialization, compilation of views and Razor files, EF model building, connection pool warm-up, and any startup cache population. On a cold application that can be five to twenty seconds. Every user who arrives first pays it, and on a low-traffic site every user may be the first user.

IIS Application Initialization exists to move that cost off the user’s critical path. It keeps application pools warm, runs requests against the application after a recycle or a server reboot, and can be driven by a health-check probe so the worker only receives real traffic once it is actually ready. This guide covers the configuration that makes it work, the interaction with idle timeout and recycling, and the failure modes that make it appear not to work. For baseline IIS and hosting prerequisites, see the deployment notes in our hosting comparison.

Why the Idle Timeout Bites Low-Traffic Sites

The default application pool idle timeout is 20 minutes. When it expires, the worker process is shut down and the application domain is unloaded. The next request starts a new worker, which re-runs Application_Start, re-compiles anything not precompiled, and rebuilds every in-process cache. There is no way for the first request to be fast, because the work it is waiting on has not happened yet.

Raising the idle timeout to zero — never time out — is the common first reaction, and it is a partial fix with a real cost. An application pool that never idles never releases its memory, so a server hosting several applications loses the benefit of memory reclamation during quiet periods. On a small instance that is exactly when you need the headroom. The better pattern is to leave the idle timeout at a meaningful value and use Application Initialization to make the restart cheap and hidden.

Preload, AlwaysRunning, and the Two Switches

Two settings must both be on, and they live in different places. On the application itself, set preloadEnabled to true so IIS sends a synthetic request to the application after startup; without it, the pool starts but the application never does. On the application pool, set startMode to AlwaysRunning so the pool starts with the service rather than on first request. Setting only one produces the classic symptom where the pool is running but the application is still cold.

The web.config equivalent for the application side is straightforward, and configuration via appcmd or the administration API is more reliable than the IIS Manager UI because the UI can update one setting and not the other without any warning:

<system.webServer>
  <applicationInitialization
      remapManagedRequestsTo="app-starting.htm"
      skipManagedModules="false"
      doAppInitAfterRestart="true" />
</system.webServer>

doAppInitAfterRestart is the setting people omit. Without it, Application Initialization runs after a recycle but not after a service restart or a reboot, which is precisely the case where the first user after a maintenance window hits a cold site. Set it explicitly on every application that benefits from warm-up, and verify the effective value with appcmd list config rather than trusting the file on disk.

Warm-Up Probes and Initialization Pages

A preload request against the site root is often not enough. If the expensive work happens on a controller action or behind a route that requires authentication, the root page warms the pipeline but not the application. Define explicit initialization pages through the applicationInitialization element’s initializationPage collection, each with a hit count and a URL — hit the known-expensive endpoints two or three times so that the first hit can trigger compilation and the second can populate whatever cache the first one fills.

Point the probes at unauthenticated endpoints that exercise the real dependency chain: a health endpoint that touches the database, reads from the cache, and resolves the dependency injection container is worth more than twenty hits on a static page. The synthetic request arrives from the loopback address, so any IP-based authorization will reject it — and if the rejection is a redirect to a login page, the probe succeeds trivially without warming anything. Check your authorization rules against loopback before you trust the result.

Recycling: The Overlap Trap

Scheduled recycling is the other source of cold starts, and its interaction with Application Initialization is where most deployments get it wrong. When a pool recycles, the old worker drains while a new one starts; Application Initialization sends preload requests to the new worker, but IIS only routes real traffic to it after the warm-up completes if you have configured the application to require initialization. Without that routing discipline, users land on the half-initialized worker and see the same slow first request.

Set the recycling schedule to a fixed daily time rather than a memory threshold alone, and set disallowOverlappingRotation to false so that the drain can complete. Then set startupTimeLimit and pingMaximumResponseTime generously enough that a genuinely slow warm-up is not mistaken for a hung worker — the default ping response maximum of 90 seconds is fine, but the startup time limit of 90 seconds is short for applications that compile large view assemblies on first start.

Verifying That It Actually Works

Measure rather than assume. With warming enabled, the first response time to a cold-start-triggering request should be within a few hundred milliseconds of the steady-state response time. Test by recycling the pool deliberately with appcmd recycle apppool, waiting five seconds, and issuing a timed request with curl -w "%{time_total}\n". Compare against the same test with warming disabled; if the two numbers are identical, the warm-up is not running.

The IIS logs tell you whether the synthetic requests arrived. Preload requests appear in the site log with the loopback source address and the configured user agent, and the Application Host Helper Service log records the initialization state transitions. If you see the requests and still see slow first responses, the probes are hitting endpoints that do not exercise the expensive path; if you see no requests at all, one of the two switches is unset.

Idle Timeout, Memory, and the Right Balance

With Application Initialization in place, the idle timeout becomes a memory-management decision rather than a performance decision. A ten-minute idle timeout on an application pool that warms in under a second is fine; a ten-minute timeout on one that takes eight seconds to warm is a user-facing problem regardless of when it recycles. Size the timeout to how much you value the reclaimed memory against the cost of the warm-up, and remember that AlwaysRunning and a non-zero idle timeout are compatible — the pool preloads on start and still idles out later.

Watch private bytes per worker over a week to find the leak-shaped growth that justifies frequent recycling, and set the memory limit slightly above the observed peak rather than at an arbitrary number. If you are sizing an instance for a set of application pools with warm-up enabled, the capacity notes in our setup guide explain how private working set maps to the memory you actually need to reserve. Warming trades memory for latency, and the trade is only worth making when you know the numbers.

Leave a Comment