<# .SYNOPSIS Track 1: матрица размер истории x число клиентов с перезапуском контейнера на каждую точку. .EXAMPLE # замеры "до" (образ уже собран) .\tools\LoadTest\run-matrix.ps1 -Label before # замеры "после": пересобрать образ и повторить те же точки .\tools\LoadTest\run-matrix.ps1 -Label after -Rebuild # быстрая проверка скрипта .\tools\LoadTest\run-matrix.ps1 -Label smoke -Sizes 1000 -Clients 1 -Repeats 1 -Duration 3 -Warmup 2 -Output $env:TEMP\smoke.jsonl #> [CmdletBinding()] param( [string]$Label = 'before', [int[]]$Sizes = @(1000, 10000, 50000), [int[]]$Clients = @(1, 8, 32), [int]$Repeats = 2, [int]$Duration = 8, [int]$Warmup = 5, [string]$Cpus = '2', [string]$Memory = '512m', [string]$Output = 'evidence/track1/results.jsonl', [string]$Image = 'mtusi-messenger:lab1', [ValidateSet('first', 'last')][string]$Page = 'first', [switch]$Rebuild ) $ErrorActionPreference = 'Stop' Set-Location (Resolve-Path (Join-Path $PSScriptRoot '..\..')) $name = 'mtusi-messenger-lab1' $url = 'http://127.0.0.1:8080' function Remove-Api { if (docker ps -aq --filter "name=^/$name$") { docker rm -f $name | Out-Null } } function Start-Api { Remove-Api docker run -d --rm --name $name --cpus $Cpus --memory $Memory ` -p 127.0.0.1:8080:8080 --env-file .env $Image | Out-Null for ($i = 0; $i -lt 60; $i++) { try { if ((Invoke-WebRequest "$url/health/ready" -UseBasicParsing -TimeoutSec 2).StatusCode -eq 200) { return } } catch { } Start-Sleep -Milliseconds 500 } throw 'API did not become ready within 30 s' } if ($Rebuild) { Write-Host 'Rebuilding image...' docker build -t $Image . | Out-Null if ($LASTEXITCODE -ne 0) { throw 'docker build failed' } } dotnet build tools/LoadTest -c Release -v q | Out-Null if ($LASTEXITCODE -ne 0) { throw 'LoadTest build failed' } $points = @(foreach ($n in $Sizes) { foreach ($c in $Clients) { [pscustomobject]@{ History = $n; Clients = $c } } }) $total = $points.Count * $Repeats $done = 0 $started = Get-Date Write-Host "Label=$Label page=$Page points=$($points.Count) repeats=$Repeats runs=$total cpus=$Cpus memory=$Memory output=$Output" try { for ($rep = 1; $rep -le $Repeats; $rep++) { # Случайный порядок точек в каждом повторе: эффект прогрева не должен совпасть с одним размером. foreach ($p in ($points | Sort-Object { Get-Random })) { $done++ Write-Host ("[{0}/{1}] rep={2} history={3} clients={4} (elapsed {5:mm\:ss})" -f $done, $total, $rep, $p.History, $p.Clients, ((Get-Date) - $started)) Start-Api dotnet run -c Release --project tools/LoadTest --no-build -- ` --url $url --history $p.History --clients $p.Clients ` --duration $Duration --warmup $Warmup ` --page $Page --container $name --label "$Label-r$rep" --output $Output | Out-Null if ($LASTEXITCODE -ne 0) { Write-Warning "run failed (exit $LASTEXITCODE), continuing" } } } } finally { Remove-Api } Write-Host ("Done in {0:mm\:ss}. Results appended to {1}" -f ((Get-Date) - $started), $Output)