アプリケーション プールのリサイクル設定 <recycling>

概要

<recycling> 要素には、IIS 7 がアプリケーション プールの再起動をトリガーする条件を制御する構成設定が含まれています。 アプリケーション プールのリサイクル時に IIS がイベント ログに書き込むイベントの種類も制御できます。

毎日特定の時刻に、またはアプリケーション プールが特定の数の要求を受信した後に、設定した間隔 (180 分ごとなど) で IIS がアプリケーション プールをリサイクルするように指定できます。 ワーカー プロセスの仮想メモリと物理メモリの使用量が特定のしきい値に達したときに、アプリケーション プールを再起動するように <recycling> 要素を構成することもできます。

<recycling> 要素を使用して、アプリケーション プールを IIS がリサイクルするときにイベント ログにログするイベントのクラスを 2 つ指定できます。 1 つめのクラスには、前の段落で説明したイベントなどの、構成できるリサイクル イベントが含まれています。 2 つめのクラスには、オンデマンド リサイクル イベント、アプリケーション プールで実行されているアプリケーションの構成変更によってトリガーされるリサイクル イベント、異常な Internet Server Application Programming Interface (ISAPI) フィルターまたは ISAPI 拡張機能によるリサイクルなどの、ランタイム リサイクル イベントが含まれます。

<recycling> 要素は、次の属性と子要素を使用してこれらの機能を実装します。

  • logEventOnRecycle 属性
  • periodicRestart 要素

互換性

バージョン メモ
IIS 10.0 logEventOnRecycle 属性の既定値は IIS 10.0 で変更されました。
IIS 8.5 <recycling> 要素は IIS 8.5 では変更されませんでした。
IIS 8.0 <recycling> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <recycling> 要素は IIS 7.5 では変更されませんでした。
IIS 7.0 <recycling> 要素が IIS 7.0 で導入されました。
IIS 6.0 <recycling> 要素は、IIS 6.0 の IIsApplicationPools メタベース プロパティの一部を置き換えます。

段取り

<applicationPools> コレクションは、IIS 7 の既定のインストールに含まれています。

操作方法

アプリケーション プールの定期的なリサイクルをセットアップする方法

  1. 次のようにインターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー] をクリックし、[ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
      • [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーで、[スタート] ボタンをクリックし、[管理ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順にクリックします。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウでサーバー名を展開し、[アプリケーション プール] をクリックします。

  3. [アプリケーション プール] ウィンドウで、編集するアプリケーション プールを選びます。

  4. [操作] ウィンドウで、[リサイクルの設定] をクリックします。
    Screenshot that shows I I S Manager. Recycling is listed in the Actions pane.

  5. アプリケーション プールのリサイクル設定の編集ウィザードの [リサイクル条件] ページで、[一定間隔] セクションの少なくとも 1 つのオプションを選び、該当するテキスト ボックスに値を入力して、[次へ] をクリックします。
    Screenshot that shows the Recycling Conditions page in the Edit Application Pool Recycling Settings dialog box. Specific time is checked, and 3 A M is entered in the text box.

  6. (省略可能) アプリケーション プールのリサイクル設定の編集ウィザードの [ログを記録するリサイクル イベント] ページで、構成可能なリサイクル イベントと、発生したときに IIS がイベント ログに送信するランタイム リサイクル イベントを選び、[終了] をクリックします。
    Screenshot that shows the Recycling Events to Log page. Scheduled time is selected.

構成

<recycling> 要素は、ApplicationHost.config ファイルにサーバー レベルで構成できます。

属性

属性 説明
disallowOverlappingRotation 省略可能な Boolean 属性です。

WWW サービスが、既存のワーカー プロセスのシャットダウン中にそのプロセスを置き換えるために別のワーカー プロセスを開始するかどうかを指定します。 ワーカー プロセスが複数のワーカー プロセスをサポートしていないアプリケーション コードを読み込む場合は、このプロパティの値を true に設定する必要があります。

既定値は false です。
disallowRotationOnConfigChange 省略可能な Boolean 属性です。

構成が変更されたときに WWW サービスがアプリケーション プール内のワーカー プロセスをローテーションするかどうかを指定します。

既定値は false です。
logEventOnRecycle 省略可能なフラグ属性。

アプリケーション プールがリサイクルされるときに IIS がイベントをログすることを指定します。 logEventOnRecycle プロパティに、IIS がイベントをログする場合のリサイクルの理由に対応するビットを設定する必要があります。

logEventOnRecycle 属性には、次の可能な値のうち 1 つ以上を指定できます。 複数の値を指定する場合はコンマ (,) で区切ります。 IIS 10 より前のバージョンの IIS の既定のフラグは、TimeMemory、および PrivateMemory です。IIS 10 以降の場合は、TimeRequestsScheduleMemoryIsapiUnhealthyOnDemandConfigChange、および PrivateMemory です。
Value 説明
ConfigChange 構成変更のためにアプリケーション プールがリサイクルされたときに、イベントをログします。

数値は 64 です。
IsapiUnhealthy ISAPI 拡張機能が異常な状態であることをワーカー プロセスに報告した後でアプリケーション プールがリサイクルされたときに、イベントをログします。
数値は 16 です。
Memory 指定した量の仮想メモリを使用した後でアプリケーション プールがリサイクルされたときに、イベントをログします。

数値は 8 です。
OnDemand 問題を修正するためにアプリケーション プールが即時リサイクルされたときに、イベントをログします。

数値は 32 です。
PrivateMemory 指定した量の仮想メモリを使用した後でアプリケーション プールがリサイクルされたときに、イベントをログします。

数値は 128 です。
Requests アプリケーション プールが構成された数の要求に達した後でリサイクルされたときに、イベントをログします。

数値は 2 です。
Schedule アプリケーション プールが構成された時刻に達した後でリサイクルされたときに、イベントをログします。

数値は 4 です。
Time 構成された時間が経過した後でアプリケーション プールがリサイクルされたときに、イベントをログします。

数値は 1 です。

子要素

要素 説明
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 サーバーに追加し、次にアプリケーション プールを毎日午前 3 時にリサイクルするように設定します。

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

Note

AppCmd.exe を使用してこれらの設定を構成するときは、commit パラメーターを必ず apphost に設定する必要があります。 これで、ApplicationHost.config ファイルの適切な場所セクションに構成設定がコミットされます。

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()