アプリごとのスケーリングを使って Azure App Service で高密度ホスティングを実現する

注意

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、Azure PowerShell のインストールに関する記事を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

App Service を使用するときは、そのアプリを実行する App Service プランをスケーリングすることにより、アプリをスケーリングできます。 同じ App Service プランでアプリを複数実行している場合には、スケールアウトしたインスタンスのそれぞれでプラン内のアプリがすべて実行されることになります。

App Service プラン レベルでアプリごとのスケーリングを有効にして、アプリをホストする App Service プランとは無関係にそのアプリをスケーリングできます。 これにより、App Service プランを 10 個のインスタンスにスケーリングしながら、5 個のインスタンスだけを使用するようにアプリを設定することが可能になります。

Note

アプリごとのスケーリングは、StandardPremiumPremium V2Premium V3Isolated の各価格レベルに限り利用できます。

アプリは、インスタンス間で均等に分散するためのベスト エフォート アプローチを使用して、使用可能な App Service プランに割り当てられます。 均等に分散は保証されませんが、プラットフォームは、同じアプリの 2 つのインスタンスが同じ App Service プラン インスタンスでホストされていないことを確認します。

プラットフォームは、ワーカーの割り当てを決定するメトリックには依存しません。 インスタンスが App Service プランに対して追加または削除されるときにのみ、アプリケーションは再調整されます。

PowerShell を使用したアプリごとのスケーリング

プランの作成時にアプリごとのスケーリングを有効にする場合には、New-AzAppServicePlan コマンドレットに -PerSiteScaling $true パラメーターを渡します。

New-AzAppServicePlan -ResourceGroupName $ResourceGroup -Name $AppServicePlan `
                            -Location $Location `
                            -Tier Premium -WorkerSize Small `
                            -NumberofWorkers 5 -PerSiteScaling $true

Set-AzAppServicePlanコマンドレットに -PerSiteScaling $true パラメーターを渡すことで、既存の App Service プランによるアプリごとのスケーリングを有効にします。

# Enable per-app scaling for the App Service Plan using the "PerSiteScaling" parameter.
Set-AzAppServicePlan -ResourceGroupName $ResourceGroup `
   -Name $AppServicePlan -PerSiteScaling $true

アプリ レベルでは、App Service プランでアプリが使用できるインスタンスの数を構成します。

次の例では、App Service プランでスケール アウトされるインスタンスの数に関係なく、アプリが使用できるインスタンスは 2 個までに制限されます。

# Get the app we want to configure to use "PerSiteScaling"
$newapp = Get-AzWebApp -ResourceGroupName $ResourceGroup -Name $webapp

# Modify the NumberOfWorkers setting to the desired value.
$newapp.SiteConfig.NumberOfWorkers = 2

# Post updated app back to azure
Set-AzWebApp $newapp

重要

$newapp.SiteConfig.NumberOfWorkers$newapp.MaxNumberOfWorkers とは異なるものです。 アプリごとのスケーリングでは、アプリのスケーリング特性の特定に $newapp.SiteConfig.NumberOfWorkers が使用されます。

Azure Resource Manager を使用したアプリごとのスケーリング

次の Azure Resource Manager テンプレートは、以下を作成します。

  • 10 個のインスタンスにスケール アウトされる App Service プラン
  • 最大 5 個のインスタンスまでスケーリングされるように構成されたアプリ

App Service プランは、PerSiteScaling プロパティを true に設定します ("perSiteScaling": true)。 アプリは、使用するワーカーの数を 5 に設定します ("properties": { "numberOfWorkers": "5" })。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters":{
        "appServicePlanName": { "type": "string" },
        "appName": { "type": "string" }
        },
    "resources": [
    {
        "comments": "App Service Plan with per site perSiteScaling = true",
        "type": "Microsoft.Web/serverFarms",
        "sku": {
            "name": "P1",
            "tier": "Premium",
            "size": "P1",
            "family": "P",
            "capacity": 10
            },
        "name": "[parameters('appServicePlanName')]",
        "apiVersion": "2015-08-01",
        "location": "West US",
        "properties": {
            "name": "[parameters('appServicePlanName')]",
            "perSiteScaling": true
        }
    },
    {
        "type": "Microsoft.Web/sites",
        "name": "[parameters('appName')]",
        "apiVersion": "2015-08-01-preview",
        "location": "West US",
        "dependsOn": [ "[resourceId('Microsoft.Web/serverFarms', parameters('appServicePlanName'))]" ],
        "properties": { "serverFarmId": "[resourceId('Microsoft.Web/serverFarms', parameters('appServicePlanName'))]" },
        "resources": [ {
                "comments": "",
                "type": "config",
                "name": "web",
                "apiVersion": "2015-08-01",
                "location": "West US",
                "dependsOn": [ "[resourceId('Microsoft.Web/Sites', parameters('appName'))]" ],
                "properties": { "numberOfWorkers": "5" }
            } ]
        }]
}

アプリごとのスケーリングは、世界各地の Azure リージョンと App Service Environment のどちらでも有効にできる機能です。 ただし推奨されるのは App Service Environment です。App Service Environment を使用した方が、その高度な機能と大きな App Service プラン容量を利用できます。

アプリに対して高密度ホスティングを構成するには、次の手順に従います。

  1. 高密度のプランとして App Service プランを指定し、それを目的の容量にスケール アウトします。
  2. App Service プランの PerSiteScaling フラグを true に設定します。
  3. 新しいアプリが作成され、その App Service プランに 1 に設定された numberOfWorkers プロパティが割り当てられます。
    • この構成を使用すると、可能な最高の密度が得られます。
  4. ワーカーの数はアプリごとに個別に構成でき、必要に応じて追加リソースを許可できます。 例:
    • 使用率が高いアプリでは、numberOfWorkers3 に設定してそのアプリの処理能力を上げます。
    • 使用率の低いアプリでは、numberOfWorkers1 に設定します。

次のステップ