サイトの制限 <limits>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

<site> 要素の <limits> 要素は、帯域幅、接続数、またはサイトへのクライアント要求の接続タイムアウトを制限する設定を構成します。

: 特定のサイトに対して <siteDefaults> セクションと <site> セクションの両方で <limits> 要素が構成されている場合、<site> セクションの構成がそのサイトに適用されます。

互換性

  IIS 7.0 IIS 6.0
注意 <site><limits> は IIS 7.0 で新たに導入された要素です。 <limits> 要素は、IIS 6.0 の次のメタベース設定に代わるものです。

ConnectionTimeout
MaxBandwidth
MaxConnections

セットアップ

<site> 要素の <limits> 要素は、IIS 7.0 の既定のインストールに含まれています。

方法

サイトの接続制限オプションを構成する方法

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで、当該サーバー名、[サイト] ノードの順に展開し、対象のサイト名をクリックします。

  3. サイトの [ホーム] ウィンドウで、[操作] ウィンドウにある [詳細設定] をクリックします。

    拡大

  4. [詳細設定] ダイアログ ボックスで、[接続制限] を展開し、接続制限のオプションを指定して、[OK] をクリックします。

    拡大

構成

属性

属性 説明
connectionTimeout オプションの timeSpan 属性。

アクティブでないと見なされる接続を切断するまでに IIS が待機する時間を秒単位で指定します。接続は次の理由からアクティブでないと見なされます。
  • HTTP.sys の Timer_ConnectionIdle タイマーの期限切れ。接続の期限が切れ、アイドル状態のままになります。
  • HTTP.sys の Timer_EntityBody タイマーの期限切れ。要求のエンティティ ボディが到着する前に接続が期限切れになりました。要求にエンティティ ボディがあることが明らかな場合、HTTP API によって Timer_EntityBody タイマーがオンになります。最初、このタイマーの制限は connectionTimeout 値に設定されています。この要求に対して別のデータ指示を受信するたびに、HTTP API によってタイマーがリセットされ、connectionTimeout 属性で指定されている分数が追加で接続に与えられます。
  • HTTP.sys の Timer_AppPool タイマーの期限切れ。要求がサーバー アプリケーションによってキューから取得されて処理されるのをアプリケーション プールのキュー内で待機する時間が長すぎたため、接続は期限切れになりました。このタイムアウト時間は connectionTimeout です。

既定値は 00:02:00 (2 分) です。

maxBandwidth オプションの uint 属性。

サイトに使用される最大ネットワーク帯域幅を指定します。この設定は、ネットワークが IIS アクティビティで過負荷状態になることを防ぐために使用します。

既定値は 4294967295 です。
maxConnections オプションの unit 属性。

サイトの最大接続数を指定します。この設定は、同時クライアント接続の数を制限するために使用します。

既定値は 4294967295 です。

子要素

なし。

構成サンプル

次の構成サンプルは、最大帯域幅が 1 秒あたり 65,536 バイト、最大接続数が 1,024、接続タイムアウトが 1 分に設定された Web サイトを示しています。

<sites>
   <site name="Default Web Site" id="1" serverAutoStart="true">
      <application path="/">
         <virtualDirectory path="/"
            physicalPath="%SystemDrive%\inetpub\wwwroot" />
      </application>

      <bindings>
         <binding protocol="http"
            bindingInformation="*:80:" />
      </bindings>
     <limits maxBandwidth="65536"
         maxConnections="1024"
         connectionTimeout="00:01:00" />
   </site>
</sites>

サンプル コード

次のコード サンプルでは、Default Web Site の最大帯域幅を 1 秒あたり 65,536 バイト、最大接続数を 1,024、接続タイムアウトを 1 分に構成します。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].limits.maxBandwidth:65536" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].limits.maxConnections:1024" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].limits.connectionTimeout:00:01: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 sitesSection = config.GetSection("system.applicationHost/sites");
         ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();

         ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Default Web Site");
         if (siteElement == null) throw new InvalidOperationException("Element not found!");

         ConfigurationElement limitsElement = siteElement.GetChildElement("limits");
         limitsElement["maxBandwidth"] = 65536;
         limitsElement["maxConnections"] = 1024;
         limitsElement["connectionTimeout"] = TimeSpan.Parse("00:01:00");

         serverManager.CommitChanges();
      }
   }

   private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
   {
      foreach (ConfigurationElement element in collection)
      {
         if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
         {
            bool matches = true;
            for (int i = 0; i < keyValues.Length; i += 2)
            {
               object o = element.GetAttributeValue(keyValues[i]);
               string value = null;
               if (o != null)
               {
                  value = o.ToString();
               }
               if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
               {
                  matches = false;
                  break;
               }
            }
            if (matches)
            {
               return element;
            }
         }
      }
      return null;
   }
}

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 sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
      Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection

      Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "Default Web Site")
      If (siteElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If

      Dim limitsElement As ConfigurationElement = siteElement.GetChildElement("limits")
      limitsElement("maxBandwidth") = 65536
      limitsElement("maxConnections") = 1024
      limitsElement("connectionTimeout") = TimeSpan.Parse("00:01:00")

       serverManager.CommitChanges()
   End Sub

   Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
      For Each element As ConfigurationElement In collection
         If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
            Dim matches As Boolean = True
            Dim i As Integer
            For i = 0 To keyValues.Length - 1 Step 2
               Dim o As Object = element.GetAttributeValue(keyValues(i))
               Dim value As String = Nothing
               If (Not (o) Is Nothing) Then
                  value = o.ToString
               End If
               If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
                  matches = False
                  Exit For
               End If
            Next
            If matches Then
               Return element
            End If
         End If
      Next
      Return Nothing
   End Function

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");

var sitesCollection = sitesSection.Collection;
var siteElementPos = FindElement(sitesCollection, "site", ["name", "Default Web Site"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);

var limitsElement = siteElement.ChildElements.Item("limits");
limitsElement.Properties.Item("maxBandwidth").Value = 65536;
limitsElement.Properties.Item("maxConnections").Value = 1024;
limitsElement.Properties.Item("connectionTimeout").Value = "00:01:00";

adminManager.CommitChanges();

function FindElement(collection, elementTagName, valuesToMatch) {
   for (var i = 0; i < collection.Count; i++) {
      var element = collection.Item(i);
      if (element.Name == elementTagName) {
         var matches = true;
         for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
            var property = element.GetPropertyByName(valuesToMatch[iVal]);
            var value = property.Value;
            if (value != null) {
               value = value.toString();
            }
            if (value != valuesToMatch[iVal + 1]) {
               matches = false;
               break;
            }
         }
         if (matches) {
            return i;
         }
      }
   }
   return -1;
}

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")

Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array("name", "Default Web Site"))
If siteElementPos = -1 Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)

Set limitsElement = siteElement.ChildElements.Item("limits")
limitsElement.Properties.Item("maxBandwidth").Value = 65536
limitsElement.Properties.Item("maxConnections").Value = 1024
limitsElement.Properties.Item("connectionTimeout").Value = "00:01:00"

adminManager.CommitChanges()

Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set Property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not value = Null Then
               value = CStr(value)
            End If
            If Not value = valuesToMatch(iVal + 1) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function