Introduction
The Application Warm-Up module for Internet Information Services 7 (IIS 7) lets you improve the responsiveness of your Web sites by loading the Web applications before the first request arrives. By proactively loading and initializing all the dependencies (such as database connections, compilation of PHP code, and loading of modules), you can ensure your Web sites are responsive at all times, even if your Web sites use a custom request pipeline or if the application pool is recycled.
With the IIS Application Warm-Up module, you can:
- Decrease the response time for first requests by pre-loading worker processes. The IIS Application Warm-Up module lets you configure the Web application to be pre-loaded before the first request arrives so that the worker process responds to the first Web request more quickly.
- Increase reliability by pre-loading worker processes when overlapped recycling occurs. Because the recycled worker process in an overlapped recycling scenario only communicates its readiness and starts accepting requests after it finishes loading and initializing the resources as specified by the configuration, pre-loading the dependencies reduces the response times for the first requests.
- Customize the pre-loading of applications. You can configure the IIS Application Warm-Up module to initialize Web applications by using specific Web pages and user identities. This makes it possible to create specific initialization processes that can be executed synchronously or asynchronously, depending on the initialization logic. In addition, these procedures can use specific identities to ensure a proper initialization.
The IIS Application Warm-Up module is integrated with the IIS Manager; configuration settings are stored in the shared configuration file.
IIS Application Warm-Up Architecture
IIS executes Web requests in worker processes, which are also called application pools. Multiple Web applications can be executed in an application pool, which can be recycled at any time by the IIS Admin service. To conserve system resources, application pools are started on demand—the system only starts an IIS worker process when there is a request for the Web application it is hosting. Initialization costs are therefore incurred not only when IIS is started (for example, on system reboot), but also when IIS recycles an application pool. With the IIS Application Warm-Up module, initialization occurs before the IIS application pool informs the WAS that it is ready to receive requests from the network. You can thus improve the customer experience by simply specifying a warm-up URL that gets executed on system restart or on application pool recycle.
- Warm up during application pool recycling. During application pool recycling, the worker process that is shutting down continues to process requests until the new worker process has finished the warm-up stage and reported to the WAS that it is ready to receive requests. The WAS then shuts down the old worker process.
- Warm up after service restart. If the applications pools must be warmed-up immediately when the IIS World Wide Web publishing service (W3SVC) is started (for example, at system boot), set the startMode configuration property to "Always" (the default is "OnDemand"); the application pool starts immediately and the configured warm-up URLs are executed.
Prerequisites
To use the IIS Application Warm-Up module, you must have IIS 7.5, which is included in the Windows® 7 and Windows Server® 2008 R2 operating systems. For the steps described in the following sections, you must have the full IIS 7.5 installation and Microsoft® ASP.NET (select ASP.NET when installing IIS 7.5).
Install the IIS Application Warm-Up Module
Download the IIS Application Warm-Up module. The installation procedure also extends the IIS user interface, letting you configure the IIS Application Warm-Up module via IIS Manager.
Use the IIS Application Warm-Up Module
To demonstrate use of the IIS Application Warm-Up module, a sample application to be “warmed up” can be created. The following steps use Windows PowerShell™ to create the sample application. You must have ASP.NET and the IIS PowerShell Snap-In (included in the full installation of IIS 7.5).
Create a Sample Warm-Up Application
1. To start a PowerShell session, click the Start button, point to All Programs, Accessories, Windows PowerShell, and then click on the Windows PowerShell icon.
2. Add the IIS PowerShell Snap-In to the current PowerShell session with the script:
Import-Module WebAdministration
3. If this fails with a security exception, you must set your execution policy to a less restrictive setting. See the help file for the cmdlet Set-ExecutionPolicy for more information.
4. Make a backup of your current configuration with the command:
Backup-WebConfiguration BeforeAppWarmupWalkthrough
5. To restore the configuration, use:
Restore-WebConfiguration BeforeAppWarmupWalkthrough
6. Create a root folder for the application with the following command:
New-Item c:\inetpub\WarmUpTest –type Directory
7. Add a new application to the default site.
New-WebApplication -site 'Default Web Site' -name WarmUpTest -physicalpath c:\inetpub\WarmUpTest
8. You now need an ASPX page for the application. Use the PowerShell here-string to add a code file that returns a page that shows the current time and the worker process ID:
$txt = @"
<%@ Page Language="C#" %>
<%@ import Namespace="System.Diagnostics" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
DateTime time = DateTime.Now;
Response.Write(String.Format("Time: {0}:{1}:{2}", time.Hour, time.Minute, time.Second) +
"\tCurrent process: " + Process.GetCurrentProcess().Id.ToString());
}
</script>
<html>
<head>
<title>ASP.NET Simple Page</title>
</head>
<body bgcolor="#FFFFFF">
<p><asp:label id="Message" runat="server" /></p>
</body>
</html>
"@
9. Save this code into a code file with the following command:
New-Item c:\inetpub\WarmUpTest\default.aspx –type file –value $txt
10. Check that the application works by using the Get-WebUrl cmdlet.
Get-WebUrl -url http://localhost/WarmUpTest/ -content
11. You should see the following output:
ResponseUri Status Description Content
----------- ------ ----------- -------
http://localhost/WarmUpTest/ OK OK Time: 12:37:11 Current ...
12. You now need code that emulates an initialization (warm-up) activity. For this sample, use a routine that sleeps for a few seconds. Create the directory WarmUpFolder under the application root directory:
New-Item c:\inetpub\WarmUpTest\WarmUpFolder –type Directory
13. Add the file with the script:
$txt = @"
<%@ Page Language="C#" %>
<%@ import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.Threading" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Thread.Sleep(20000);
Response.Write("Done");
}
</script>
<html>
<head>
<title>ASP.NET Simple Page</title>
</head>
<body bgcolor="#FFFFFF">
<p><asp:label id="Message" runat="server" /></p>
</body>
</html>
"@
14. Save the here-string as Default.aspx in the WarmUpFolder directory:
New-Item c:\inetpub\WarmUpTest\WarmUpFolder\default.aspx –type File –value $txt
15. You should now have a Web page that emulates a warm up by taking 20 seconds to execute. Send another request using the IIS PowerShell cmdlet Get-WebUrl to test this URL:
Get-WebUrl -url http://localhost/WarmUpTest/WarmUpFolder/default.aspx -content
16. After 20 seconds, you should see the following output:
ResponseUri Status Description Content
----------- ------ ----------- -------
http://localhost/WarmUpTest/Warm... OK OK Done...
Enable Application Warm-Up
1. Enable the application to be warmed-up with the PowerShell command:
Set-WebConfigurationProperty /system.webServer/httpWarmupGlobalSettings -pspath "IIS:\sites\Default Web Site\WarmUpTest" -name httpWarmupEnabled -value true
2. Alternately, you can use the IIS Manager:
a. Start IIS Manager.
b. Expand Default Web Site, and then select the sample application WarmUpTest.
c. In the Configure section on the right, click Application Warm-Up.
3. The Settings dialog box appears. Select the Enable Application Warm-Up and Start Application Pool 'DefaultAppPool' when service started check boxes.

Figure 1: Settings dialog box
Note that IIS worker processes usually start on demand (for example, when a request from the network arrives). Starting the worker process immediately ensures that your application is warmed up after a system reboot or a service restart. If you do not select Start Application Pool 'DefaultAppPool' when service started, warm up occurs when the application pool is recycled, but not after a system reboot or IIS service restart.
The PowerShell commands to enable the automatic start of the IIS worker process are:
Set-WebConfigurationProperty '/system.applicationHost/applicationPools/add[@name="DefaultAppPool"]' -pspath machine/webroot/apphost -name startMode -value AlwaysRunning
Add Warm-Up Requests to the Application
1. Add warm-up requests using PowerShell commands:
Add-WebConfigurationProperty /system.webServer/httpWarmup/requests -pspath 'iis:\Sites\Default Web Site\WarmUpTest' -name collection -value @{requestUrl='WarmUpFolder/default.aspx'}
2. This command adds request with all properties except the name set to the default values. View the requests with all of the parameters using the command:
Get-WebConfigurationProperty /system.webServer/httpWarmup/requests -pspath 'iis:\Sites\Default Web Site\WarmUpTest' -name collection
3. The following is the output of this command:
requestUrl : WarmupFolder/default.aspx
allowedResponseCodes : 200-399
warmupContext :
sendMode : Asynchronous
reportWarmupFailure : False
…
4. To update request attributes to non-default values, use the command set-webconfigurationproperty. For example, to set the warmupContext (a server variable that is set by the IIS Application Warm-Up module to check whether the current request is a warm-up request), use the command:
Set-WebConfigurationProperty "/system.webServer/httpWarmup/requests/add[@requestUrl='WarmUpFolder/default.aspx']" -pspath 'iis:\sites\Default Web Site\WarmUpTest' -name warmupContext -value MyWarmUpContext
Now, add warm-up requests via IIS Manager.
1. Double-click Application Warm-Up in the Feature View.
2. Click Add Request on the Actions pane. In the dialog box, type the request URL: WarmUpFolder/default.aspx, and then click OK.

Figure 2: Add Request dialog box
3. The new request appears in the list on the Application Warm-Up page.

Figure 3: Application Warm-Up page
Note that there are some restrictions for URLs you can configure:
- The warm-up URL must be relative to the application URL. This means that you cannot send request to another application or another site.
- Requests for default documents have to end with ‘/’.
Note also that the other fields in the Add Request dialog box configure parameters of the request.
- Status code(s). You can define status code(s) that you expect in the response. If the response is outside the defined range, the IIS Application Warm-Up module logs this in the Application Eventlog and continues with the next request.
- Request context parameter. You can define a string that will be added to the request as server variable; this lets you check for this request variable in your application code, which in turn lets you distinguish requests that were sent from the Warm-Up module from regular requests.
- Request send mode. You can send requests either synchronously or asynchronously. The Warm-Up module processes requests by first sending all asynchronous requests (using separate threads) and then sending synchronous requests. The Warm-Up module waits for the responses from each synchronous request before it sends the next request. The Warm-Up module then waits for responses from outstanding asynchronous requests before returning control to the server.
Demonstrate Use of the IIS Application Warm-Up Module
Since the Warm-Up module works when a worker process is started, create conditions where a worker process starts often. Instruct the application pool to recycle every 10 requests. Note that this is not a realistic setting.
1. Use the PowerShell command:
Set-ItemProperty IIS:\AppPools\DefaultAppPool -Name recycling.periodicrestart.requests -value 10
2. In IIS Manager, select DefaultAppPool in the Application Pools view, and then click Recycling in the Actions pane.
3. In the dialog box, type: 10 for the limit of the number of requests.
4. Now, recycle the default application pool with the PowerShell command:
Restart-WebAppPool DefaultAppPool
5. Execute the following script in the PowerShell console:
foreach ($i in (1..100)) {
$s = $i.ToString() + "`t" + (Get-WebUrl -url http://localhost/WarmUpTest -content).Content;
$s.Substring(0, $s.IndexOf("`n"))
sleep 1
}
This script sends 100 requests to the sample application (one per second), and prints the first line from the response content with the request number. Because of the previously configured warm-up URL (the code which sleeps for 20 seconds), there is a 20-second delay before the responses start coming.
The output should resemble the following:
1 Time: 14:6:14 Current process: 5936
2 Time: 14:6:15 Current process: 5936
3 Time: 14:6:16 Current process: 5936
…
9 Time: 14:6:22 Current process: 5936
10 Time: 14:6:24 Current process: 5936
11 Time: 14:6:25 Current process: 5936
12 Time: 14:6:26 Current process: 5936
…
23 Time: 14:6:37 Current process: 5936
24 Time: 14:6:38 Current process: 5936
25 Time: 14:6:39 Current process: 5432
26 Time: 14:6:40 Current process: 5432
27 Time: 14:6:41 Current process: 5432
…
34 Time: 14:6:48 Current process: 5432
35 Time: 14:6:49 Current process: 5432
36 Time: 14:6:50 Current process: 5432
37 Time: 14:6:51 Current process: 5432
38 Time: 14:6:52 Current process: 5432
…
This simple demonstration shows the main benefits of using the Warm-Up module.
- When application pool is restarted, IIS keeps using the existing worker process until new one is warmed up. In the sample, the application pool is recycled after 10 requests.
Without the IIS Application Warm-Up module, you would have a 20-second gap between request 10 and 11 in the list above, because the 11th request will cause a warm-up delay in the fresh worker process. IIS would queue at least 10 requests while the worker process is starting up.
With the IIS Application Warm-Up module, the first request is sent internally before the worker process is set into the processing loop, so there is no delay in processing of incoming requests. Responses are received once per second from the existing process, and the new process starts working at the 25th request after the 20-second delay that was added to the warm-up routine.
- You can control when you incur the warm-up expenses. For example, you can set up an application pool recycle once per day when traffic to your site is low (for example, at 3:00 A.M.).
Without the IIS Application Warm-Up module, the worker process will be warmed-up only when the first request arrives for your application, (for example, at 7:00 A.M.). The customer who issues the first request will experience a delay in the processing of the request the application pool is warming up.
With the IIS Application Warm-Up module, you can automatically send warm-up requests immediately after application pool is restarted (for example, right at 3:00 A.M.).
Troubleshoot
The responses of the IIS Application Warm-Up module are not returned to a browser or saved to disk. Use the IIS 7.5 Request Tracing feature to troubleshoot issues. For more information, see Troubleshooting Failed Requests Using Tracing in IIS 7.0.
Advanced Scenarios
The IIS Application Warm-Up module can be used in some advanced scenarios.
Use the User Context for Warm-Up Requests
Some applications process requests only if they are authenticated (for example, if the code is executed as a user who is different from the process identity that the IIS application pool is using, or if the user context is populated).
Windows® SharePoint® Services (WSS), for example, does not accept a request without a set user name; instead, WSS redirects to the SharePoint logon page. This would keep warm-up requests from executing.
For such scenarios, the IIS Application Warm-Up module lets you configure the user context for the request so that the IIS Application Warm-Up module simulates a successfully logged on user.
You can use PowerShell to configure the user context.
1. Use the following PowerShell command to configure the setting for a username for the warm-up requests:
Set-WebConfiguration /system.webServer/httpWarmup/userContext -pspath 'IIS:\Sites\Default Web Site\WarmUpTest' -value @{username="myWarmUpUser";authMode="SetUserOnly"}
2. To change a password without typing it in the command line or in a script as clear text, use a PowerShell command to obtain credentials from the user, and then pass the input data to the configuration:
$cred = get-credential myWarmUpUser
Set-WebConfigurationProperty /system.webServer/httpWarmup/userContext -pspath 'IIS:\Sites\Default Web Site\WarmUpTest' –name Password –value $cred.GetNetworkCredential().Password
Note that the variable $cred will have a password as a secure string.
Alternately, you can use the IIS Manager:
1. Open the Feature page for the IIS Application Warm-Up module, and then click Edit user context.
2. The Edit user context dialog box appears. Type the user name and password that are used for warm-up requests.
3. In the Type box, enter the authentication type that warm-up requests should simulate.
4. In the Authentication Mode dialog box, specify if you want to set the user to be used for the warm-up requests or if you want a Windows® access token to be created and used for the warm-up requests.
Use the Warm-Up Context for Requests
To differentiate warm-up requests from regular requests, set a warm-up context with the server variable WARMUPCONTEXT, which you can use within the application code. You can specify the value of the WARMUPCONTEXT server variable in the configuration. For example, you can add a request with a warm-up context through the following PowerShell command:
Set-WebConfigurationProperty "/system.webServer/httpWarmup/requests/add[@requestUrl='WarmUpFolder/default.aspx']" -pspath 'iis:\sites\Default Web Site\WarmUpTest' -name warmupContext -value "This is a warmup request"
Links for Further Information
IIS Extensions.
Application Warm-Up.
Installing IIS 7.0.
Related Content