アプリケーション プールのリサイクル設定 <recycling>
- 概要
- 互換性
- セットアップ
- 方法
- 構成
- サンプル コード
※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。
概要
<recycling>
要素は、IIS 7.0 によるアプリケーション プールの再起動をトリガーする条件を制御するための構成設定を含んでいます。アプリケーション プールのリサイクル時に IIS がイベント ログに書き込むイベントの種類を制御することもできます。
設定した間隔 (180 分間隔など)、毎日特定の時刻、アプリケーション プールが特定の数の要求を受け取った後といった条件でアプリケーション プールをリサイクルするように指定できます。また、ワーカー プロセスの仮想メモリおよび物理メモリの使用量が特定のしきい値に達したときにアプリケーション プールを再起動するように <recycling>
要素を構成することもできます。
<recycling>
要素では、IIS がアプリケーション プールをリサイクルするときにイベント ログに記録されるイベントの 2 つのクラスを指定できます。1 つ目のクラスには、前の段落で挙げたような、構成可能なリサイクル イベントがあります。2 つ目のクラスには、オンデマンドのリサイクル イベント、アプリケーションまたはアプリケーション プール内で実行されているアプリケーションの構成の変更によりトリガーされたリサイクル イベント、ISAPI (Internet Server Application Programming Interface) フィルターまたは ISAPI 拡張の問題によって発生したリサイクルなどのランタイム リサイクル イベントがあります。
<recycling>
要素は、次の属性と子要素を使用してこれらの機能を実装します。
- logEventOnRecycle 属性
- periodicRestart 要素
互換性
IIS 7.0 | IIS 6.0 | |
---|---|---|
説明 | <recycling> は IIS 7.0 で新たに導入された要素です。 |
|
セットアップ
<applicationPools>
コレクションは、IIS 7.0 の既定のインストールに含まれています。
方法
アプリケーション プールで定期的なリサイクルをセットアップする方法
タスク バーの [スタート] ボタンをクリックして、[管理ツール] をポイントし、[インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。
[接続] ウィンドウで、対象のサーバー名を展開し、[アプリケーション プール] をクリックします。
[アプリケーション プール] ウィンドウで、編集するアプリケーション プールを選択します。
[操作] ウィンドウで [リサイクルの設定] をクリックします。
[アプリケーション プールのリサイクル設定の編集] ウィザードの [リサイクル条件] ページで、[一定間隔] セクションのオプションから少なくとも 1 つを選択し、該当するテキスト ボックスに値を入力して、[次へ] をクリックします。
(オプション) [アプリケーション プールのリサイクル設定の編集] ウィザードの [ログを記録するリサイクル イベント] ページで、構成可能なリサイクル イベントおよびランタイム リサイクル イベントを選択します。ここで選択したリサイクル イベントは、その発生時にイベント ログに送信されます。[完了] をクリックします。
注 : 既定では、IIS は [定期的な間隔]、[仮想メモリ使用量]、および [プライベート メモリ使用量] の構成可能なリサイクル イベントをイベント ログに送信します。その他の構成可能なリサイクル イベントは、[リサイクル条件] ページでイベントのログ記録を有効にしている場合にのみログに記録できます。
構成
<recycling>
要素は、ApplicationHost.config ファイル内で、サーバー レベルで構成できます。
属性
属性 | 説明 |
---|---|
disallowOverlappingRotation |
オプションの Boolean 属性。 既存のワーカー プロセスのシャットダウン時に、WWW サービスがそのプロセスの代わりに別のワーカー プロセスを開始するかどうかを指定します。複数のワーカー プロセスをサポートしていないアプリケーション コードをワーカー プロセスがロードする場合は、プロパティの値を true に設定します。 既定値は false です。 |
disallowRotationOnConfigChange |
オプションの Boolean 属性。 構成の変更時に WWW サービスがアプリケーション プール内のワーカー プロセスを入れ替えるかどうかを指定します。 既定値は false です。 |
logEventOnRecycle |
オプションの flags 属性。 アプリケーション プールのリサイクル時に IIS がイベントをログに記録するかどうかを指定します。logEventOnRecycle プロパティには、IIS がイベントをログに記録する際の、リサイクルの理由に対応するビット セットが指定されている必要があります。 logEventOnRecycle 属性には、次の中から 1 つまたは複数の値を指定できます。複数の値を指定する場合はコンマ (,) で区切ります。既定値は、 Time 、Memory 、PrivateMemory の組み合わせです。--------------------------------------------------------------------------------------------------------- 値: ConfigChange 説明:
値: IsapiUnhealthy 説明:
値: Memory 説明:
値: OnDemand 説明:
値: PrivateMemory 説明:
値: Requests 説明:
値: Schedule 説明:
値: Time 説明:
|
子要素
要素 | 説明 |
---|---|
periodicRestart |
オプションの要素。 アプリケーション プールがリサイクルされる条件を指定します。 |
構成サンプル
次の構成サンプルでは、アプリケーション プールの <add>
要素を使用して、Contoso という名前の新しいアプリケーション プールを作成します。<recycling>
要素は、アプリケーション プールの再起動のログ記録を構成します。<periodicRestart>
要素は、アプリケーション プールの再起動時の条件を構成します。<processModel>
要素は、アプリケーション プール内のワーカー プロセスのシャットダウンと起動に関する shutdownTimeLimit 属性および startupTimeLimit 属性をそれぞれ 30 秒に構成します。この時間制限を超えると、IIS はワーカー プロセスを終了します。
<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>
サンプル コード
次のコード サンプルでは、Contoso という名前のアプリケーション プールを IIS 7.0 サーバーに追加し、アプリケーション プールで毎日午前 3:00 にリサイクルを実行するよう設定します。
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
次の構文を使用することもできます。
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
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()