Overview
When customers are using a Web Farm setup and they need to recycle the application pool for each server once or even multiple times a day. Often, the servers start throwing active sync errors and one of the 2 (or more) web head servers will begin to not load the page correctly.
Instructions
- Open the Internet Information Services (IIS) Manager (examples are in IIS 7):
- If you are using Windows Server 2012 or Windows Server 2012 R2:
- On the taskbar, click Server Manager | Tools | Internet Information Services (IIS) Manager.
- If you are using Windows 8 or Windows 8.1:
- Hold down the Windows key + the letter X, and then click Control Panel.
- Click Administrative Tools
- Double-click Internet Information Services (IIS) Manager.
- If you are using Windows Server 2008 or Windows Server 2008 R2:
- On the taskbar, click Start | Administrative Tools
- Click Internet Information Services (IIS) Manager.
- If you are using Windows Vista or Windows 7:
- On the taskbar, click Start | Control Panel.
- Double-click Administrative Tools
- Double-click Internet Information Services (IIS) Manager.
- If you are using Windows Server 2012 or Windows Server 2012 R2:
- In the Connections pane, expand the server name, and then click Application Pools.
- In the Application Pools pane, select the application pool you want to edit.
- In the Actions pane, click Recycling...
- On the Recycling Conditions page of the Edit Application Pool Recycling Settings Wizard:
- Select at least one of the options in the Fixed Intervals section
- Regular time intervals
- Fixed number of requests
- Specific time(s)
- Type the values into the appropriate text boxes
- Click Next.
- Select at least one of the options in the Fixed Intervals section
- Optional Step: On the Recycling Events to Log page of the Edit Application Pool Recycling Settings Wizard, select the configurable recycling events and run-time recycling events that you want IIS to send to the event log when they occur, and then click Finish.
Configuration
The <periodicRestart>
element is configurable at the server level in the ApplicationHost.config file (which is located at %windir%\system32\inetsrv\config directory).
Attributes
Attribute | Description |
---|---|
memory |
Optional uint attribute. Specifies the amount of virtual memory (in kilobytes) that a worker process can use before the worker process is recycled. The maximum value supported for this property is 4,294,967 KB. The default value is |
privateMemory |
Optional uint attribute. Specifies the amount of private memory (in kilobytes) that a worker process can use before the worker process recycles. The maximum value supported for this property is 4,294,967 KB. The default value is |
requests |
Optional uint attribute. Specifies that the worker process should be recycled after it processes a specific number of requests. The default value is |
time |
Optional timeSpan attribute. Specifies that the worker process should be recycled after a specified amount of time has elapsed. The default value is |
Child Elements
Element | Description |
---|---|
schedule |
Optional element. Specifies the scheduling of periodic restarts of application pools. |
Configuration Sample
The following configuration sample uses the application pool <add>
element to create a new application pool named Contoso. The <recycling>
element configures logging for application pool restarts, the <periodicRestart>
element configures when the application pool restarts, and the <processModel>
element configures the shutdownTimeLimit and startupTimeLimit attributes for shutting down and starting the worker processes in the application pool for 30 seconds each. If these time limits are exceeded, IIS terminates the worker process.
XML
<add name="Contoso"> <recycling logEventOnRecycle="Schedule"> <periodicRestart> <schedule> <clear /> <add value="03:00:00" /> </schedule> </periodicRestart> </recycling> <processModel identityType="NetworkService" shutdownTimeLimit="00:00:30" startupTimeLimit="00:00:30" /> </add>
Sample Code
The following code examples add an application pool named Contoso to your IIS 7 server, then set the application pool to daily recycle at 3:00 A.M.
AppCmd.exe
appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='Contoso']" /commit:apphost
appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='Contoso'].recycling.periodicRestart.schedule.[value='03:00:00']" /commit:apphost
You can also use the following syntax:
appcmd.exe add apppool /name:"Contoso"
appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='Contoso'].recycling.periodicRestart.schedule.[value='03:00:00']" /commit:apphost
Note: You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.
C#
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools");
ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();
ConfigurationElement addElement = applicationPoolsCollection.CreateElement("add");
addElement["name"] = @"Contoso";
ConfigurationElement recyclingElement = addElement.GetChildElement("recycling");
ConfigurationElement periodicRestartElement = recyclingElement.GetChildElement("periodicRestart");
ConfigurationElementCollection scheduleCollection = periodicRestartElement.GetCollection("schedule");
ConfigurationElement addElement1 = scheduleCollection.CreateElement("add");
addElement1["value"] = TimeSpan.Parse("03:00:00");
scheduleCollection.Add(addElement1);
applicationPoolsCollection.Add(addElement);
serverManager.CommitChanges();
}
}
}
VB.NET
Imports System
Imports System.Text Imports Microsoft.Web.Administration
Module Sample
Sub Main()
Dim serverManager As ServerManager = New ServerManager
Dim config As Configuration = serverManager.GetApplicationHostConfiguration
Dim applicationPoolsSection As ConfigurationSection = config.GetSection("system.applicationHost/applicationPools")
Dim applicationPoolsCollection As ConfigurationElementCollection = applicationPoolsSection.GetCollection
Dim addElement As ConfigurationElement = applicationPoolsCollection.CreateElement("add")
addElement("name") = "Contoso" Dim recyclingElement As ConfigurationElement = addElement.GetChildElement("recycling")
Dim periodicRestartElement As ConfigurationElement = recyclingElement.GetChildElement("periodicRestart")
Dim scheduleCollection As ConfigurationElementCollection = periodicRestartElement.GetCollection("schedule")
Dim addElement1 As ConfigurationElement = scheduleCollection.CreateElement("add")
addElement1("value") = TimeSpan.Parse("03:00:00")
scheduleCollection.Add(addElement1)
applicationPoolsCollection.Add(addElement)
serverManager.CommitChanges()
End Sub End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST");
var applicationPoolsCollection = applicationPoolsSection.Collection;
var addElement = applicationPoolsCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "Contoso";
var recyclingElement = addElement.ChildElements.Item("recycling");
var periodicRestartElement = recyclingElement.ChildElements.Item("periodicRestart");
var scheduleCollection = periodicRestartElement.ChildElements.Item("schedule").Collection;
var addElement1 = scheduleCollection.CreateNewElement("add");
addElement1.Properties.Item("value").Value = "03:00:00";
scheduleCollection.AddElement(addElement1);
applicationPoolsCollection.AddElement(addElement);
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST" Set applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST")
Set applicationPoolsCollection = applicationPoolsSection.Collection
Set addElement = applicationPoolsCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "Contoso" Set recyclingElement = addElement.ChildElements.Item("recycling")
Set periodicRestartElement = recyclingElement.ChildElements.Item("periodicRestart")
Set scheduleCollection = periodicRestartElement.ChildElements.Item("schedule").Collection
Set addElement1 = scheduleCollection.CreateNewElement("add")
addElement1.Properties.Item("value").Value = "03:00:00"
scheduleCollection.AddElement(addElement1)
applicationPoolsCollection.AddElement(addElement)
adminManager.CommitChanges()
Article by: Radu Vaduva
Product: DNN
Comments
0 comments
Please sign in to leave a comment.