Last active
August 4, 2020 09:14
-
-
Save rupertbenbrook/ddff253cc01b2696aa348582456b83bf to your computer and use it in GitHub Desktop.
Azure App Service High Density Scaling Tests based on https://docs.microsoft.com/en-us/azure/app-service/manage-scale-per-app. Tested running on PowerShell Core 7 with Az Cmdlets and .NET 3.1 SDK.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string] $ResourceGroup = "rbtesthighdensity", | |
[string] $Location = "northeurope", | |
[string] $AppPrefix = "rbaathd", | |
[int] $PlanScale = 4, | |
[int] $AppCount = 8, | |
[int] $WorkerScale = 1, | |
[bool] $FirstAppLarge = $true | |
) | |
$ErrorActionPreference = "Stop" | |
Write-Host "*** Creating app package" | |
Remove-Item TestApp -Recurse -Force -ErrorAction SilentlyContinue | |
mkdir TestApp | |
Set-Location TestApp | |
dotnet new web | |
(Get-Content ".\Startup.cs") -replace """Hello World!""","Environment.MachineName" | Out-File ".\Startup.cs" -Force | |
dotnet publish -c Release -o Publish | |
Compress-Archive -Path ".\Publish\*.*" -DestinationPath "..\TestApp.zip" -Force | |
Set-Location .. | |
Remove-Item TestApp -Recurse -Force -ErrorAction SilentlyContinue | |
Write-Host "*** Creating resource group '$ResourceGroup'" | |
$rg = New-AzResourceGroup -Name $ResourceGroup -Location $Location | |
Write-Host "*** Creating app service plan '$AppPrefix-plan' with $PlanScale instances" | |
$plan = New-AzAppServicePlan -ResourceGroupName $rg.ResourceGroupName -Name "$AppPrefix-plan" -Location $Location -Tier Standard -WorkerSize Small -NumberofWorkers $PlanScale -PerSiteScaling $true | |
1..$AppCount | ForEach-Object { | |
Write-Host "*** Creating app service '$AppPrefix-$_'" | |
$app = New-AzWebApp -ResourceGroupName $rg.ResourceGroupName -AppServicePlan $plan.Name -Name "$AppPrefix-$_" | |
Write-Host "*** Publishing package to app service '$AppPrefix-$_'" | |
Publish-AzWebApp -WebApp $app -ArchivePath (Resolve-Path ".\TestApp.zip") -Force | Out-Null | |
if ($FirstAppLarge -and $_ -eq 1) { | |
$app.SiteConfig.NumberOfWorkers = $PlanScale | |
} else { | |
$app.SiteConfig.NumberOfWorkers = $WorkerScale | |
} | |
$app.SiteConfig.AlwaysOn = $true | |
$app.SiteConfig.LoadBalancing = "LeastRequests" | |
Write-Host "*** Setting app service '$AppPrefix-$_' workers to $($app.SiteConfig.NumberOfWorkers)" | |
$app = Set-AzWebApp $app | |
Write-Host "*** Pinging app service '$AppPrefix-$_'" | |
$check = Invoke-WebRequest -Uri "https://$AppPrefix-$_.azurewebsites.net/" | |
$instance = [System.Text.Encoding]::UTF8.GetString($check.Content) | |
Write-Host "$AppPrefix-$_ - $($check.StatusCode) - $instance" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string] $ResourceGroup = "rbtesthighdensity", | |
[string] $AppPrefix = "rbaathd", | |
[bool] $PerSiteScaling = $true, | |
[int] $PlanScale = 4, | |
[int] $AppCount = 8, | |
[int] $WorkerScale = 1, | |
[bool] $FirstAppLarge = $true | |
) | |
$ErrorActionPreference = "Stop" | |
Write-Host "*** Setting app service plan '$AppPrefix-plan' to $PlanScale instances" | |
Set-AzAppServicePlan -ResourceGroupName $ResourceGroup -Name "$AppPrefix-plan" -PerSiteScaling $PerSiteScaling -NumberofWorkers $PlanScale | Out-Null | |
if ($PerSiteScaling) { | |
1..$AppCount | ForEach-Object { | |
$app = Get-AzWebApp -ResourceGroupName $ResourceGroup -Name "$AppPrefix-$_" | |
if ($FirstAppLarge -and $_ -eq 1) { | |
$app.SiteConfig.NumberOfWorkers = $PlanScale | |
} else { | |
$app.SiteConfig.NumberOfWorkers = $WorkerScale | |
} | |
Write-Host "*** Setting app service '$AppPrefix-$_' workers to $($app.SiteConfig.NumberOfWorkers)" | |
$app = Set-AzWebApp $app | |
Write-Host "*** Pinging app service '$AppPrefix-$_'" | |
$check = Invoke-WebRequest -Uri "https://$AppPrefix-$_.azurewebsites.net/" | |
$instance = [System.Text.Encoding]::UTF8.GetString($check.Content) | |
Write-Host "$AppPrefix-$_ - $($check.StatusCode) - $instance" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string] $AppPrefix = "rbaathd", | |
[int] $AppCount = 8, | |
[int] $LoadParallel = 32, | |
[int] $LoadDelay = 100, | |
[int] $RunSeconds = 30 | |
) | |
$ErrorActionPreference = "Stop" | |
Write-Host "*** Running web load for $RunSeconds seconds over $AppCount apps on $LoadParallel threads" | |
$map = @{} | |
$start = Get-Date | |
1..$LoadParallel | ForEach-Object -ThrottleLimit $LoadParallel -Parallel { | |
$name = $using:AppPrefix | |
$appNum = ($_ % $using:AppCount) + 1 | |
$name += "-$appNum" | |
$map = $using:map | |
do { | |
$check = Invoke-WebRequest -Uri "https://$name.azurewebsites.net/" -DisableKeepAlive -SslProtocol Tls12 | |
$instance = [System.Text.Encoding]::UTF8.GetString($check.Content) | |
if ($map.ContainsKey($instance)) { | |
if (-not $map[$instance].Contains($name)) { | |
$map[$instance] += $name | |
} | |
} else { | |
$map[$instance] = @($name) | |
} | |
Start-Sleep -Milliseconds $using:LoadDelay | |
} while (((Get-Date) - $using:start).TotalSeconds -lt $using:RunSeconds) | |
} | |
$map | Format-Table @{l="Instance";e={$_.Name}},@{l="Apps";e={($_.Value | Sort-Object) -join ', '}} -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment