mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Got close to the final version
comitting Claude's code before the last mile improvements
This commit is contained in:
@@ -0,0 +1,658 @@
|
||||
# ============================================================================
|
||||
# BakaShrot replication benchmark
|
||||
#
|
||||
# Runs several servers linked as peers on localhost (by default 4 in a Y: one
|
||||
# hub linked to 3 leaves), each with its own nodes pushing to it, and
|
||||
# measures, stage by stage:
|
||||
# - the push path: achieved vs offered rate, latency, failures
|
||||
# - replication: lag on every server while pushing, whether it keeps up
|
||||
# (trough slope, see Bench_TroughSlope() in BenchClient.pb), and how long
|
||||
# it takes to drain once the pushes stop
|
||||
# - every server's CPU and RAM, and its database's size
|
||||
# - a query suite (queries.txt) after every stage, as the data grows
|
||||
#
|
||||
# Three parts:
|
||||
# 1. Ramp: from an empty database, stages of -Ramp ("NodesxRate", Rate per
|
||||
# node in msg/s, 0 = as fast as the server answers), to find where the
|
||||
# push path and the replication saturate.
|
||||
# 2. Scale: seeds every database up to each of -SeedTotals rows (identical
|
||||
# on every server, see BenchSeed.pb), then runs -SteadyStage and the
|
||||
# query suite at that size: how check-ins and queries hold up with
|
||||
# lots of data.
|
||||
# 3. Mixed: -MixedStage with queries_load.txt running in a loop against
|
||||
# the hub meanwhile: reads under write load, and writes under reads.
|
||||
#
|
||||
# Results go into Build\Bench\runs\<timestamp>\: configs, per-stage samples
|
||||
# (CSV, one row per sample), summaries (JSON), and report.md / results.json
|
||||
# for the whole run.
|
||||
# The databases and server logs go into -DataDir\<timestamp>\ instead, out of
|
||||
# the repo: every push rewrites them, and file watchers on the repo (git
|
||||
# caches, editors) otherwise burn a core or two reacting to it, skewing the
|
||||
# CPU numbers. The databases are deleted at the end, unless -KeepData.
|
||||
#
|
||||
# Usage:
|
||||
# powershell -ExecutionPolicy Bypass -File Tests\Bench\Bench-Replication.ps1
|
||||
# ... -Ramp "5x20,10x50" -SeedTotals @() -PushSeconds 10 quick run
|
||||
# ... -Topology Mesh -PeerSyncInterval 1 variations
|
||||
# ... -Names Wildcard each server only names its own nodes, and
|
||||
# takes the others' by AcceptNodes = n*
|
||||
# ... -Parts Ramp only part 1
|
||||
# Keep -PushSeconds at 6+ times PeerSyncInterval for the trough slope to mean
|
||||
# something.
|
||||
#
|
||||
# ... -Compiler "C:\Program Files\PureBasic_640\Compilers\pbcompilerc.exe" `
|
||||
# -CompilerFlags "/OPTIMIZER" PB 6.40, C backend
|
||||
#
|
||||
# Needs: PureBasic 5.73 x64 (found by itself, or -Compiler), libsodium
|
||||
# extracted in Libs\libsodium\x64 (see Build.ps1), and a sqlite3.dll with
|
||||
# the JSON functions (3.38+): Libs\sqlite\x64\sqlite3.dll by default, or
|
||||
# -SqliteDll.
|
||||
# Everything runs on one machine: the load generator competes with the
|
||||
# servers for the CPU, its own CPU use is in the report.
|
||||
# ============================================================================
|
||||
|
||||
param(
|
||||
[ValidateSet("Y", "Chain", "Mesh")]
|
||||
[string]$Topology = "Y",
|
||||
[ValidateSet("Declared", "Wildcard")]
|
||||
[string]$Names = "Declared",
|
||||
[int]$ServerCount = 4,
|
||||
[int]$MaxNodesPerServer = 10,
|
||||
[int]$MessageSize = 200,
|
||||
[int]$PushSeconds = 30,
|
||||
[int]$PeerSyncInterval = 5,
|
||||
[int]$PeerBatchSize = 100,
|
||||
[int]$PortBase = 13001,
|
||||
[string]$Ramp = "5x5,5x20,5x50,5x100,5x0,10x20,10x50,10x100,10x0",
|
||||
[int[]]$SeedTotals = @(250000, 1000000),
|
||||
[string]$SteadyStage = "10x10",
|
||||
[string]$MixedStage = "10x10",
|
||||
|
||||
[string]$Parts = "Ramp,Scale,Mixed",
|
||||
[int]$QueryRepeats = 3,
|
||||
[int]$DrainTimeout = 180,
|
||||
[string]$Compiler = "",
|
||||
[string]$CompilerFlags = "",
|
||||
[string]$SqliteDll = "",
|
||||
[string]$DataDir = (Join-Path ([IO.Path]::GetTempPath()) "BakaShrot-Bench"),
|
||||
[switch]$KeepData,
|
||||
[switch]$SkipBuild
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# "Ramp,Scale" or "Ramp", "Scale", from -File or -Command alike.
|
||||
$PartList = @($Parts -split "[, ]" | ForEach-Object { $_.Trim() } | Where-Object { $_ })
|
||||
foreach ($Part in $PartList) { if ($Part -notin @("Ramp", "Scale", "Mixed")) { throw "Unknown part $Part, use Ramp, Scale and/or Mixed" } }
|
||||
|
||||
$Stamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
$Root = Resolve-Path (Join-Path $PSScriptRoot "..\..")
|
||||
$BenchDir = $PSScriptRoot
|
||||
$OutDir = Join-Path $Root "Build\Bench"
|
||||
$RunDir = Join-Path $OutDir "runs\$Stamp"
|
||||
$RunData = Join-Path $DataDir $Stamp
|
||||
$LogDir = Join-Path $RunData "logs"
|
||||
$TopicId = 1
|
||||
|
||||
|
||||
# --- Build ------------------------------------------------------------------
|
||||
|
||||
function Find-Compiler {
|
||||
if ($Compiler) { return $Compiler }
|
||||
foreach ($Candidate in @("C:\Program Files\PureBasic_573\Compilers\pbcompiler.exe",
|
||||
"C:\Program Files\PureBasic573\Compilers\pbcompiler.exe")) {
|
||||
if (Test-Path $Candidate) { return $Candidate }
|
||||
}
|
||||
throw "PureBasic 5.73 x64 not found, pass -Compiler"
|
||||
}
|
||||
|
||||
function Copy-Dlls {
|
||||
New-Item -ItemType Directory -Force $OutDir | Out-Null
|
||||
|
||||
$Sodium = Join-Path $Root "Libs\libsodium\x64\libsodium.dll"
|
||||
if (-not (Test-Path $Sodium)) { throw "Missing $Sodium, run Build.ps1 once to extract it" }
|
||||
Copy-Item $Sodium $OutDir -Force
|
||||
|
||||
$Sqlite = $SqliteDll
|
||||
if (-not $Sqlite) { $Sqlite = Join-Path $Root "Libs\sqlite\x64\sqlite3.dll" }
|
||||
if (-not (Test-Path $Sqlite)) { throw "Missing $Sqlite, run Build.ps1 once to extract it, or pass -SqliteDll" }
|
||||
Copy-Item $Sqlite (Join-Path $OutDir "sqlite3.dll") -Force
|
||||
Write-Host "Using SQLite $((Get-Item $Sqlite).VersionInfo.ProductVersion) from $Sqlite"
|
||||
}
|
||||
|
||||
$script:CompilerName = "(not rebuilt, -SkipBuild)"
|
||||
|
||||
function Invoke-Build {
|
||||
$Pb = Find-Compiler
|
||||
New-Item -ItemType Directory -Force $OutDir | Out-Null
|
||||
|
||||
# "PureBasic 6.40 - C Backend (Windows - x64) - (c) ...", 5.73 takes /EXE,
|
||||
# 6.x /OUTPUT.
|
||||
$script:CompilerName = ((& $Pb /VERSION) | Select-Object -First 1) -replace " - \(c\).*$", ""
|
||||
$OutputFlag = if ($script:CompilerName -match "PureBasic 5\.") { "/EXE" } else { "/OUTPUT" }
|
||||
$Extra = @($CompilerFlags -split " " | Where-Object { $_ })
|
||||
if ($Extra.Count -gt 0) { $script:CompilerName += " " + ($Extra -join " ") }
|
||||
Write-Host "Compiler: $($script:CompilerName)"
|
||||
|
||||
foreach ($Item in @(
|
||||
@("Tests\Bench\BenchServer.pb", "BenchServer.exe", @("/CONSOLE", "/THREAD")),
|
||||
@("Tests\Bench\BenchClient.pb", "BenchClient.exe", @("/CONSOLE", "/THREAD")),
|
||||
@("Tests\Bench\BenchSeed.pb", "BenchSeed.exe", @("/CONSOLE")),
|
||||
@("Tools\KeyGen\KeyGen.pb", "KeyGen.exe", @("/CONSOLE")))) {
|
||||
Write-Host "Compiling $($Item[0])"
|
||||
$Flags = $Item[2] + $Extra
|
||||
& $Pb (Join-Path $Root $Item[0]) @Flags /QUIET $OutputFlag (Join-Path $OutDir $Item[1])
|
||||
if ($LASTEXITCODE -ne 0) { throw "Failed to compile $($Item[0])" }
|
||||
}
|
||||
}
|
||||
|
||||
function New-KeyPair {
|
||||
$Lines = & (Join-Path $OutDir "KeyGen.exe")
|
||||
if ($LASTEXITCODE -ne 0) { throw "KeyGen failed: $Lines" }
|
||||
return @{
|
||||
PrivateKey = $Lines[0] -replace "^PrivateKey = ", ""
|
||||
PublicKey = $Lines[1] -replace "^PublicKey = ", ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# --- Topology and configs -----------------------------------------------------
|
||||
|
||||
function Get-Edges {
|
||||
$Edges = @()
|
||||
switch ($Topology) {
|
||||
"Y" { for ($i = 1; $i -lt $ServerCount; $i++) { $Edges += , @(0, $i) } }
|
||||
"Chain" { for ($i = 0; $i -lt $ServerCount - 1; $i++) { $Edges += , @($i, ($i + 1)) } }
|
||||
"Mesh" { for ($i = 0; $i -lt $ServerCount; $i++) { for ($j = $i + 1; $j -lt $ServerCount; $j++) { $Edges += , @($i, $j) } } }
|
||||
}
|
||||
return , $Edges
|
||||
}
|
||||
|
||||
function New-Servers {
|
||||
$Servers = @()
|
||||
for ($i = 0; $i -lt $ServerCount; $i++) {
|
||||
if ($Topology -eq "Y") {
|
||||
if ($i -eq 0) { $Name = "hub" } else { $Name = "leaf$i" }
|
||||
} else {
|
||||
$Name = "s$($i + 1)"
|
||||
}
|
||||
$Keys = New-KeyPair
|
||||
$Servers += [pscustomobject]@{
|
||||
Index = $i
|
||||
Name = $Name
|
||||
NodeId = $i + 1
|
||||
Port = $PortBase + $i
|
||||
PrivateKey = $Keys.PrivateKey
|
||||
PublicKey = $Keys.PublicKey
|
||||
DatabasePath = Join-Path $RunData "$Name.sqlite"
|
||||
ConfigPath = Join-Path $RunDir "$Name.ini"
|
||||
StopFile = Join-Path $RunData "$Name.stop"
|
||||
FirstNode = ($i + 1) * 100 + 1
|
||||
MonitorNode = 900 + $i + 1
|
||||
QueryNode = 950 + $i + 1
|
||||
Peers = @()
|
||||
Process = $null
|
||||
}
|
||||
}
|
||||
foreach ($Edge in (Get-Edges)) {
|
||||
$Servers[$Edge[0]].Peers += $Edge[1]
|
||||
$Servers[$Edge[1]].Peers += $Edge[0]
|
||||
}
|
||||
return $Servers
|
||||
}
|
||||
|
||||
function Write-ServerConfig($Server, $Servers, $ClientKeys) {
|
||||
$LastNode = $Server.FirstNode + $MaxNodesPerServer - 1
|
||||
$Identities = (@($Server.FirstNode..$LastNode) + @($Server.MonitorNode, $Server.QueryNode) | ForEach-Object { "${TopicId}:$_" }) -join ";"
|
||||
|
||||
# Only named topics and nodes replicate, and they must be named on both
|
||||
# ends (Declared): every server names every node of every server, with
|
||||
# the same ids. Wildcard: each server only names its own, the peers take
|
||||
# them by AcceptNodes = n*, and give them ids of their own. The servers'
|
||||
# own nodes are named everywhere either way: a peer authenticates by
|
||||
# name, the others must know it.
|
||||
$NodeNames = @()
|
||||
foreach ($Other in $Servers) {
|
||||
$NodeNames += "n$($Other.NodeId) = $($Other.NodeId)"
|
||||
if ($Names -eq "Wildcard" -and $Other -ne $Server) { continue }
|
||||
$OtherLast = $Other.FirstNode + $MaxNodesPerServer - 1
|
||||
foreach ($Id in (@($Other.FirstNode..$OtherLast) + @($Other.MonitorNode, $Other.QueryNode))) {
|
||||
$NodeNames += "n$Id = $Id"
|
||||
}
|
||||
}
|
||||
|
||||
$Text = @"
|
||||
[BakaShrot]
|
||||
PrivateKey = $($Server.PrivateKey)
|
||||
Topic = $TopicId
|
||||
Node = $($Server.NodeId)
|
||||
|
||||
[BakaShrot.Topics]
|
||||
bench = $TopicId
|
||||
|
||||
[BakaShrot.Nodes]
|
||||
$($NodeNames -join "`r`n")
|
||||
|
||||
[BakaShrot.Server]
|
||||
Host = 127.0.0.1
|
||||
Port = $($Server.Port)
|
||||
ReplicatingTopics = $TopicId
|
||||
DatabasePath = $($Server.DatabasePath)
|
||||
PeerRetryDelay = 2
|
||||
PeerSyncInterval = $PeerSyncInterval
|
||||
PeerBatchSize = $PeerBatchSize
|
||||
|
||||
[BakaShrot.Client.bench]
|
||||
PublicKeys = $($ClientKeys.PublicKey)
|
||||
Identities = $Identities
|
||||
AllowRead = 1
|
||||
AllowWrite = 1
|
||||
AllowQuery = 1
|
||||
|
||||
"@
|
||||
foreach ($PeerIndex in $Server.Peers) {
|
||||
$Peer = $Servers[$PeerIndex]
|
||||
$Text += @"
|
||||
[BakaShrot.Peer.$($Peer.Name)]
|
||||
Host = 127.0.0.1
|
||||
Port = $($Peer.Port)
|
||||
Topic = $TopicId
|
||||
Node = $($Peer.NodeId)
|
||||
PublicKey = $($Peer.PublicKey)
|
||||
$(if ($Names -eq "Wildcard") { "AcceptNodes = n*" })
|
||||
|
||||
[BakaShrot.Client.$($Peer.Name)]
|
||||
PublicKeys = $($Peer.PublicKey)
|
||||
Identities = ${TopicId}:$($Peer.NodeId)
|
||||
AllowRead = 0
|
||||
AllowWrite = 0
|
||||
AllowQuery = 0
|
||||
|
||||
"@
|
||||
}
|
||||
Set-Content -Path $Server.ConfigPath -Value $Text -Encoding Ascii
|
||||
}
|
||||
|
||||
|
||||
# --- Servers ----------------------------------------------------------------
|
||||
|
||||
$script:StartCount = 0
|
||||
|
||||
function Test-Port($Port) {
|
||||
$Client = New-Object System.Net.Sockets.TcpClient
|
||||
try {
|
||||
$Async = $Client.BeginConnect("127.0.0.1", $Port, $null, $null)
|
||||
if ($Async.AsyncWaitHandle.WaitOne(200) -and $Client.Connected) { return $true }
|
||||
return $false
|
||||
} catch {
|
||||
return $false
|
||||
} finally {
|
||||
$Client.Close()
|
||||
}
|
||||
}
|
||||
|
||||
function Start-Servers($Servers) {
|
||||
$script:StartCount++
|
||||
foreach ($Server in $Servers) {
|
||||
Remove-Item $Server.StopFile -ErrorAction SilentlyContinue
|
||||
$Log = Join-Path $LogDir "$($Server.Name)-$($script:StartCount).log"
|
||||
$Server.Process = Start-Process -FilePath (Join-Path $OutDir "BenchServer.exe") `
|
||||
-ArgumentList "`"$($Server.ConfigPath)`"", "`"$($Server.StopFile)`"" `
|
||||
-WorkingDirectory $OutDir -NoNewWindow -PassThru `
|
||||
-RedirectStandardOutput $Log -RedirectStandardError "$Log.err"
|
||||
}
|
||||
foreach ($Server in $Servers) {
|
||||
$Deadline = (Get-Date).AddSeconds(15)
|
||||
while (-not (Test-Port $Server.Port)) {
|
||||
if ($Server.Process.HasExited) { throw "$($Server.Name) exited, see its log in $LogDir" }
|
||||
if ((Get-Date) -gt $Deadline) { throw "$($Server.Name) isn't listening on $($Server.Port)" }
|
||||
Start-Sleep -Milliseconds 100
|
||||
}
|
||||
}
|
||||
# Let the peers link (they retry every 2 s) and run their first check-in.
|
||||
Start-Sleep -Seconds 4
|
||||
Write-Host "Servers up: $(($Servers | ForEach-Object { "$($_.Name)=pid $($_.Process.Id)" }) -join ', ')"
|
||||
}
|
||||
|
||||
function Stop-Servers($Servers) {
|
||||
foreach ($Server in $Servers) {
|
||||
if ($Server.Process -and -not $Server.Process.HasExited) {
|
||||
Set-Content -Path $Server.StopFile -Value "stop"
|
||||
}
|
||||
}
|
||||
foreach ($Server in $Servers) {
|
||||
if ($Server.Process) {
|
||||
if (-not $Server.Process.WaitForExit(30000)) {
|
||||
Write-Warning "$($Server.Name) didn't stop, killing it"
|
||||
$Server.Process.Kill()
|
||||
}
|
||||
$Server.Process = $null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# --- Stages -----------------------------------------------------------------
|
||||
|
||||
function ConvertTo-Stage($Spec) {
|
||||
$Fields = $Spec.Trim().ToLower().Split("x")
|
||||
return [pscustomobject]@{ Nodes = [int]$Fields[0]; Rate = [double]$Fields[1] }
|
||||
}
|
||||
|
||||
function Write-Plan($Path, $Servers, $ClientKeys, $Stage, $Name, $QueryFile, $QueryLoad) {
|
||||
$Text = @"
|
||||
[Bench]
|
||||
PrivateKey = $($ClientKeys.PrivateKey)
|
||||
PublicKey = $($ClientKeys.PublicKey)
|
||||
TopicId = $TopicId
|
||||
ServerCount = $($Servers.Count)
|
||||
PushSeconds = $PushSeconds
|
||||
Rate = $($Stage.Rate)
|
||||
MessageSize = $MessageSize
|
||||
SampleMs = 1000
|
||||
DrainSampleMs = 250
|
||||
DrainTimeout = $DrainTimeout
|
||||
PeerSyncInterval = $PeerSyncInterval
|
||||
SamplesCsv = $(Join-Path $RunDir "$Name.samples.csv")
|
||||
SummaryOut = $(Join-Path $RunDir "$Name.summary.json")
|
||||
QueryFile = $QueryFile
|
||||
QueryRepeats = $QueryRepeats
|
||||
QueryOut = $(Join-Path $RunDir "$Name.queries.json")
|
||||
|
||||
"@
|
||||
foreach ($Server in $Servers) {
|
||||
$ProcId = 0
|
||||
if ($Server.Process) { $ProcId = $Server.Process.Id }
|
||||
# The query suite runs on the hub and the first leaf, the query load
|
||||
# only on the hub.
|
||||
$Text += @"
|
||||
[Server$($Server.Index + 1)]
|
||||
Name = $($Server.Name)
|
||||
Host = 127.0.0.1
|
||||
Port = $($Server.Port)
|
||||
PublicKey = $($Server.PublicKey)
|
||||
Pid = $ProcId
|
||||
DatabasePath = $($Server.DatabasePath)
|
||||
FirstNode = $($Server.FirstNode)
|
||||
MaxNodes = $MaxNodesPerServer
|
||||
NodeCount = $($Stage.Nodes)
|
||||
MonitorNode = $($Server.MonitorNode)
|
||||
QueryNode = $($Server.QueryNode)
|
||||
QueryLoad = $([int]($QueryLoad -and $Server.Index -eq 0))
|
||||
Query = $([int]($Server.Index -le 1))
|
||||
|
||||
"@
|
||||
}
|
||||
Set-Content -Path $Path -Value $Text -Encoding Ascii
|
||||
}
|
||||
|
||||
function Invoke-BenchClient($Mode, $Plan) {
|
||||
& (Join-Path $OutDir "BenchClient.exe") $Mode $Plan | ForEach-Object { Write-Host " $_" }
|
||||
if ($LASTEXITCODE -ne 0) { throw "BenchClient $Mode failed" }
|
||||
}
|
||||
|
||||
$script:Results = @()
|
||||
$script:QueryResults = @()
|
||||
|
||||
function Invoke-Stage($Part, $Name, $Stage, $Servers, $ClientKeys, [switch]$QueryLoad) {
|
||||
$Plan = Join-Path $RunDir "$Name.plan.ini"
|
||||
$LoadFile = ""
|
||||
if ($QueryLoad) { $LoadFile = Join-Path $BenchDir "queries_load.txt" }
|
||||
Write-Plan $Plan $Servers $ClientKeys $Stage $Name $LoadFile $QueryLoad
|
||||
|
||||
$RateText = if ($Stage.Rate -gt 0) { "$($Stage.Rate) msg/s" } else { "max" }
|
||||
Write-Host ""
|
||||
Write-Host "=== $Name : $($Stage.Nodes) nodes/server x $RateText, $PushSeconds s ===" -ForegroundColor Cyan
|
||||
# Other processes busy meanwhile (antivirus scanning the databases...),
|
||||
# tick-based, only good enough to spot the big ones.
|
||||
$Before = @{}
|
||||
Get-Process | ForEach-Object { $Before[$_.Id] = $_.CPU }
|
||||
$StartTime = Get-Date
|
||||
Invoke-BenchClient "run" $Plan
|
||||
$Seconds = ((Get-Date) - $StartTime).TotalSeconds
|
||||
$Others = Get-Process | Where-Object { $_.Name -notin @("BenchServer", "BenchClient", "Idle") -and $null -ne $_.CPU } | ForEach-Object {
|
||||
$Previous = 0
|
||||
if ($Before.ContainsKey($_.Id)) { $Previous = $Before[$_.Id] }
|
||||
[pscustomobject]@{ Name = $_.Name; Percent = 100 * ($_.CPU - $Previous) / $Seconds }
|
||||
} | Sort-Object Percent -Descending | Select-Object -First 3
|
||||
$Summary = Get-Content (Join-Path $RunDir "$Name.summary.json") -Raw | ConvertFrom-Json
|
||||
$Summary | Add-Member -NotePropertyName OtherProcesses -NotePropertyValue (($Others | Where-Object Percent -ge 5 | ForEach-Object { "$($_.Name) $(Format-Num $_.Percent)" }) -join ", ")
|
||||
$Summary | Add-Member -NotePropertyName Stage -NotePropertyValue $Name
|
||||
$Summary | Add-Member -NotePropertyName Part -NotePropertyValue $Part
|
||||
$Summary | Add-Member -NotePropertyName NodesPerServer -NotePropertyValue $Stage.Nodes
|
||||
$script:Results += $Summary
|
||||
|
||||
# The query suite, on the idle servers.
|
||||
Write-Plan $Plan $Servers $ClientKeys $Stage $Name (Join-Path $BenchDir "queries.txt") $false
|
||||
Invoke-BenchClient "query" $Plan
|
||||
$Rows = ($Summary.Servers | Measure-Object -Property Rows -Maximum).Maximum
|
||||
foreach ($Query in (Get-Content (Join-Path $RunDir "$Name.queries.json") -Raw | ConvertFrom-Json)) {
|
||||
$Query | Add-Member -NotePropertyName Stage -NotePropertyValue $Name
|
||||
$Query | Add-Member -NotePropertyName DataRows -NotePropertyValue $Rows
|
||||
$script:QueryResults += $Query
|
||||
}
|
||||
return $Summary
|
||||
}
|
||||
|
||||
function Invoke-Seed($Servers, $TargetRows, $CurrentRows) {
|
||||
$Nodes = $Servers.Count * $MaxNodesPerServer
|
||||
$PerNode = [math]::Ceiling(($TargetRows - $CurrentRows) / $Nodes)
|
||||
if ($PerNode -le 0) { return }
|
||||
$Spec = ($Servers | ForEach-Object { "$($_.FirstNode)-$($_.FirstNode + $MaxNodesPerServer - 1)" }) -join ","
|
||||
Write-Host ""
|
||||
Write-Host "=== Seeding to ~$TargetRows rows per server ($PerNode more per node, in every database) ===" -ForegroundColor Cyan
|
||||
Stop-Servers $Servers
|
||||
$Dbs = $Servers | ForEach-Object { $_.DatabasePath }
|
||||
& (Join-Path $OutDir "BenchSeed.exe") $TopicId $Spec $PerNode $MessageSize @Dbs | ForEach-Object { Write-Host " $_" }
|
||||
if ($LASTEXITCODE -ne 0) { throw "BenchSeed failed" }
|
||||
Start-Servers $Servers
|
||||
}
|
||||
|
||||
|
||||
# --- Report -----------------------------------------------------------------
|
||||
|
||||
function Format-Num($Value, $Decimals = 0) {
|
||||
return ([double]$Value).ToString("N$Decimals", [Globalization.CultureInfo]::InvariantCulture)
|
||||
}
|
||||
|
||||
function Get-Verdict($Summary) {
|
||||
$Notes = @()
|
||||
if ($Summary.Rate -gt 0 -and $Summary.PushRate -lt 0.9 * $Summary.OfferedRate) { $Notes += "push saturated" }
|
||||
if ($Summary.Failed -gt 0) { $Notes += "$($Summary.Failed) failed pushes" }
|
||||
# The trough slope is too noisy for a verdict (check-ins drift against the
|
||||
# windows), the lag in seconds of pushes isn't: keeping up means about
|
||||
# two check-ins' worth at most, through the hub.
|
||||
$MaxLagSeconds = ($Summary.Servers | Measure-Object -Property LagMaxSeconds -Maximum).Maximum
|
||||
if ($MaxLagSeconds -gt 2 * $PeerSyncInterval + 2) { $Notes += "replication lagging" }
|
||||
if (-not $Summary.Drained) { $Notes += "NOT drained" }
|
||||
elseif ($Summary.DrainSeconds -gt 2 * $PeerSyncInterval + 5) { $Notes += "slow drain" }
|
||||
if ($Notes.Count -eq 0) { return "ok" }
|
||||
return $Notes -join ", "
|
||||
}
|
||||
|
||||
function Get-LogIssues($Servers) {
|
||||
$Issues = @()
|
||||
foreach ($Server in $Servers) {
|
||||
$Logs = Get-ChildItem $LogDir -Filter "$($Server.Name)-*.log"
|
||||
$Counts = [ordered]@{}
|
||||
foreach ($Pattern in @("Refused", "Failed", "locked", "timed out", "Dropping", "Lost the link", "too big")) {
|
||||
$Counts[$Pattern] = @($Logs | Select-String -SimpleMatch $Pattern).Count
|
||||
}
|
||||
$Sent = @($Logs | Select-String -Pattern "\[Peer\] Sent (\d+) messages .* in (\d+) ms")
|
||||
$Messages = 0; $Ms = 0
|
||||
foreach ($Match in $Sent) {
|
||||
$Messages += [int]$Match.Matches[0].Groups[1].Value
|
||||
$Ms += [int]$Match.Matches[0].Groups[2].Value
|
||||
}
|
||||
$Issues += [pscustomobject]@{
|
||||
Server = $Server.Name; Counts = $Counts
|
||||
ReplicatedOut = $Messages; ReplicateMs = $Ms; CatchUps = $Sent.Count
|
||||
}
|
||||
}
|
||||
return $Issues
|
||||
}
|
||||
|
||||
function Write-Report($Servers) {
|
||||
$Lines = @()
|
||||
$Lines += "# BakaShrot replication benchmark, $(Get-Date -Format 'yyyy-MM-dd HH:mm')"
|
||||
$Lines += ""
|
||||
$Cpu = (Get-CimInstance Win32_Processor | Select-Object -First 1).Name.Trim()
|
||||
$Ram = [math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB)
|
||||
$Lines += "- Machine: $Cpu, $Ram GB RAM, everything on localhost"
|
||||
$Lines += "- Topology: $Topology, $ServerCount servers ($(($Servers | ForEach-Object { "$($_.Name) <-> " + (($_.Peers | ForEach-Object { $Servers[$_].Name }) -join '/') }) -join '; '))"
|
||||
$Lines += "- Names: $Names ($(if ($Names -eq 'Wildcard') { 'each server names its own nodes, peers take them by AcceptNodes = n*' } else { 'every node named on every server' }))"
|
||||
$Lines += "- Messages: ~$MessageSize bytes of JSON, PeerSyncInterval $PeerSyncInterval s, PeerBatchSize $PeerBatchSize, $PushSeconds s per stage"
|
||||
$Lines += "- Built with: $($script:CompilerName), SQLite $((Get-Item (Join-Path $OutDir 'sqlite3.dll')).VersionInfo.ProductVersion)"
|
||||
$Lines += "- CPU in % of one core (100 = one core busy), System = whole machine in %, Bench = the load generator itself (% of one core)"
|
||||
$Lines += ""
|
||||
|
||||
$Lines += "## Stages"
|
||||
$Lines += ""
|
||||
$Lines += "- Max lag: most messages a server was missing while pushing. Trough: the lowest lag of the last check-in window, slope: how fast those troughs rise (~0 = keeps up)."
|
||||
$Lines += ""
|
||||
$Lines += "| Stage | Nodes | Offered msg/s | Pushed msg/s | Push p50 / p99 / max ms | Failed | Max lag msgs (s of pushes) | Last trough | Trough slope msg/s | Drain s | Verdict |"
|
||||
$Lines += "|---|---|---|---|---|---|---|---|---|---|---|"
|
||||
foreach ($R in $script:Results) {
|
||||
$Offered = if ($R.Rate -gt 0) { Format-Num $R.OfferedRate } else { "max" }
|
||||
$Lag = ($R.Servers | Measure-Object -Property LagMaxPush -Maximum).Maximum
|
||||
$LagSeconds = ($R.Servers | Measure-Object -Property LagMaxSeconds -Maximum).Maximum
|
||||
$Trough = ($R.Servers | Measure-Object -Property LagTroughLast -Maximum).Maximum
|
||||
$Slope = ($R.Servers | Measure-Object -Property LagSlope -Maximum).Maximum
|
||||
$Drain = if ($R.Drained) { Format-Num $R.DrainSeconds 1 } else { "> $DrainTimeout" }
|
||||
$Lines += "| $($R.Stage) | $($R.NodesPerServer) x $ServerCount | $Offered | $(Format-Num $R.PushRate) | $(Format-Num $R.PushP50Ms 1) / $(Format-Num $R.PushP99Ms 1) / $(Format-Num $R.PushMaxMs 0) | $($R.Failed) | $(Format-Num $Lag) ($(Format-Num $LagSeconds 1)) | $(Format-Num $Trough) | $(Format-Num $Slope 1) | $Drain | $(Get-Verdict $R) |"
|
||||
}
|
||||
$Lines += ""
|
||||
|
||||
$Lines += "## Resources while pushing"
|
||||
$Lines += ""
|
||||
$Header = "| Stage | System CPU avg / max | Bench CPU |"
|
||||
$Sep = "|---|---|---|"
|
||||
foreach ($Server in $Servers) { $Header += " $($Server.Name) CPU avg / max | $($Server.Name) RAM WS / private MB |"; $Sep += "---|---|" }
|
||||
$Header += " Other busy processes (% core) |"; $Sep += "---|"
|
||||
$Lines += $Header
|
||||
$Lines += $Sep
|
||||
foreach ($R in $script:Results) {
|
||||
$Row = "| $($R.Stage) | $(Format-Num $R.SystemCpuAvg) % / $(Format-Num $R.SystemCpuMax) % | $(Format-Num $R.BenchCpuAvg) |"
|
||||
foreach ($S in $R.Servers) { $Row += " $(Format-Num $S.CpuAvgPush) / $(Format-Num $S.CpuMaxPush) | $(Format-Num $S.WorkingSetMaxMb 1) / $(Format-Num $S.PrivateMaxMb 1) |" }
|
||||
$Row += " $($R.OtherProcesses) |"
|
||||
$Lines += $Row
|
||||
}
|
||||
$Lines += ""
|
||||
|
||||
$Lines += "## Per server, end of stage"
|
||||
$Lines += ""
|
||||
$Header = "| Stage |"
|
||||
$Sep = "|---|"
|
||||
foreach ($Server in $Servers) { $Header += " $($Server.Name) rows | DB MB | max lag | monitor query avg / max ms |"; $Sep += "---|---|---|---|" }
|
||||
$Lines += $Header
|
||||
$Lines += $Sep
|
||||
foreach ($R in $script:Results) {
|
||||
$Row = "| $($R.Stage) |"
|
||||
foreach ($S in $R.Servers) { $Row += " $(Format-Num $S.Rows) | $(Format-Num $S.DbMb 1) | $(Format-Num $S.LagMaxPush) | $(Format-Num $S.MonitorAvgMs 1) / $(Format-Num $S.MonitorMaxMs 1) |" }
|
||||
$Lines += $Row
|
||||
}
|
||||
$Lines += ""
|
||||
|
||||
$Lines += "## Queries, idle, median ms (on $($Servers[0].Name))"
|
||||
$Lines += ""
|
||||
$Stages = $script:QueryResults | Where-Object Server -eq $Servers[0].Name | Select-Object -ExpandProperty Stage -Unique
|
||||
$Names = $script:QueryResults | Select-Object -ExpandProperty Name -Unique
|
||||
$Header = "| Query |"
|
||||
$Sep = "|---|"
|
||||
foreach ($Stage in $Stages) {
|
||||
$Rows = ($script:QueryResults | Where-Object { $_.Stage -eq $Stage } | Select-Object -First 1).DataRows
|
||||
$Header += " $Stage ($(Format-Num $Rows) rows) |"; $Sep += "---|"
|
||||
}
|
||||
$Lines += $Header
|
||||
$Lines += $Sep
|
||||
foreach ($Name in $Names) {
|
||||
$Row = "| $Name |"
|
||||
foreach ($Stage in $Stages) {
|
||||
$Q = $script:QueryResults | Where-Object { $_.Stage -eq $Stage -and $_.Name -eq $Name -and $_.Server -eq $Servers[0].Name } | Select-Object -First 1
|
||||
if (-not $Q) { $Row += " |" }
|
||||
elseif ($Q.Count -eq 0) { $Row += " FAIL: $($Q.LastError) |" }
|
||||
else { $Row += " $(Format-Num $Q.P50Ms 1) |" }
|
||||
}
|
||||
$Lines += $Row
|
||||
}
|
||||
$Lines += ""
|
||||
|
||||
$Mixed = $script:Results | Where-Object { $_.QueriesUnderLoad.Count -gt 0 }
|
||||
foreach ($R in $Mixed) {
|
||||
$Lines += "## Queries under load ($($R.Stage), on $($Servers[0].Name), while pushing $(Format-Num $R.PushRate) msg/s)"
|
||||
$Lines += ""
|
||||
$Lines += "| Query | Runs | p50 ms | p90 ms | max ms | Failures |"
|
||||
$Lines += "|---|---|---|---|---|---|"
|
||||
foreach ($Q in $R.QueriesUnderLoad) {
|
||||
$Lines += "| $($Q.Name) | $($Q.Count) | $(Format-Num $Q.P50Ms 1) | $(Format-Num $Q.P90Ms 1) | $(Format-Num $Q.MaxMs 1) | $($Q.Failures) $($Q.LastError) |"
|
||||
}
|
||||
$Lines += ""
|
||||
}
|
||||
|
||||
$Lines += "## Server logs"
|
||||
$Lines += ""
|
||||
$Lines += "| Server | Catch-ups sent | Messages replicated out | ms spent sending | Refused | Failed | locked | timed out | Dropping | Lost the link | too big |"
|
||||
$Lines += "|---|---|---|---|---|---|---|---|---|---|---|"
|
||||
foreach ($I in (Get-LogIssues $Servers)) {
|
||||
$Lines += "| $($I.Server) | $($I.CatchUps) | $(Format-Num $I.ReplicatedOut) | $(Format-Num $I.ReplicateMs) | $(($I.Counts.Values) -join ' | ') |"
|
||||
}
|
||||
$Lines += ""
|
||||
|
||||
$Report = Join-Path $RunDir "report.md"
|
||||
Set-Content -Path $Report -Value ($Lines -join "`r`n") -Encoding UTF8
|
||||
@{ Results = $script:Results; Queries = $script:QueryResults } | ConvertTo-Json -Depth 8 | Set-Content (Join-Path $RunDir "results.json") -Encoding UTF8
|
||||
return $Report
|
||||
}
|
||||
|
||||
|
||||
# --- Main -------------------------------------------------------------------
|
||||
|
||||
if (-not $SkipBuild) { Invoke-Build }
|
||||
Copy-Dlls
|
||||
New-Item -ItemType Directory -Force $RunDir, $LogDir | Out-Null
|
||||
Write-Host "Run folder: $RunDir"
|
||||
|
||||
$ClientKeys = New-KeyPair
|
||||
$Servers = @(New-Servers)
|
||||
foreach ($Server in $Servers) { Write-ServerConfig $Server $Servers $ClientKeys }
|
||||
|
||||
try {
|
||||
Start-Servers $Servers
|
||||
$Last = $null
|
||||
|
||||
if ($PartList -contains "Ramp") {
|
||||
$i = 0
|
||||
foreach ($Spec in $Ramp.Split(",")) {
|
||||
$i++
|
||||
$Stage = ConvertTo-Stage $Spec
|
||||
$Last = Invoke-Stage "Ramp" ("ramp{0:D2}-{1}" -f $i, $Spec.Trim()) $Stage $Servers $ClientKeys
|
||||
}
|
||||
}
|
||||
|
||||
if ($PartList -contains "Scale") {
|
||||
foreach ($Target in $SeedTotals) {
|
||||
$Current = 0
|
||||
if ($Last) { $Current = ($Last.Servers | Measure-Object -Property Rows -Minimum).Minimum }
|
||||
Invoke-Seed $Servers $Target $Current
|
||||
$Last = Invoke-Stage "Scale" ("scale-{0}k" -f [math]::Round($Target / 1000)) (ConvertTo-Stage $SteadyStage) $Servers $ClientKeys
|
||||
}
|
||||
}
|
||||
|
||||
if ($PartList -contains "Mixed") {
|
||||
$Last = Invoke-Stage "Mixed" "mixed" (ConvertTo-Stage $MixedStage) $Servers $ClientKeys -QueryLoad
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Stop-Servers $Servers
|
||||
if ($script:Results.Count -gt 0) {
|
||||
$Report = Write-Report $Servers
|
||||
Write-Host ""
|
||||
Write-Host "Report: $Report"
|
||||
}
|
||||
Write-Host "Server logs: $LogDir"
|
||||
if (-not $KeepData) {
|
||||
Get-ChildItem $RunData -Filter "*.sqlite*" | Remove-Item -Force
|
||||
} else {
|
||||
Write-Host "Databases kept in $RunData"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,181 @@
|
||||
; ============================================================================
|
||||
; BakaShrot Bench Seed
|
||||
;
|
||||
; Usage: BenchSeed <TopicId> <Nodes> <RowsPerNode> <MessageSize> <Db> [Db...]
|
||||
; Nodes Node ids, "101-110,201-210".
|
||||
;
|
||||
; Adds RowsPerNode messages to every node, identical in every database, so
|
||||
; servers that were in sync stay in sync without replicating anything: a
|
||||
; quick way to get millions of rows for the query and check-in benchmarks.
|
||||
; Each node continues from the highest message id any database has for it,
|
||||
; and INSERT OR IGNORE keeps what's already there.
|
||||
; Nodes go by name ("n" + id, like Bench-Replication.ps1 names them): each
|
||||
; database stores a node under its own id for that name, and gets the name
|
||||
; (origin "peer", as if a peer had sent it) if it doesn't have it yet, so
|
||||
; servers that take nodes by wildcard (-Names Wildcard) see them as known.
|
||||
; The servers must be stopped. Same JSON as BenchClient's pushes.
|
||||
;
|
||||
; Used by Tests/Bench/Bench-Replication.ps1, compile as a console program.
|
||||
; ============================================================================
|
||||
|
||||
EnableExplicit
|
||||
|
||||
XIncludeFile "../../Server/Storage/Storage.pbi"
|
||||
|
||||
|
||||
#Seed_BatchSize = 50000
|
||||
|
||||
|
||||
; The id DbId has for node "n<Node>", given that name if it has none yet.
|
||||
; Returns -1 on failure.
|
||||
Procedure.i Seed_LocalNode(DbId.i, Node.i)
|
||||
Protected Name.s = "n" + Str(Node), Id.i = -1
|
||||
|
||||
SetDatabaseString(DbId, 0, Name)
|
||||
If DatabaseQuery(DbId, "SELECT node_id FROM nodes WHERE name = ?")
|
||||
If NextDatabaseRow(DbId)
|
||||
Id = GetDatabaseLong(DbId, 0)
|
||||
EndIf
|
||||
FinishDatabaseQuery(DbId)
|
||||
EndIf
|
||||
If Id >= 0
|
||||
ProcedureReturn Id
|
||||
EndIf
|
||||
|
||||
; Its own id, unless something else is named there.
|
||||
SetDatabaseLong(DbId, 0, Node)
|
||||
SetDatabaseString(DbId, 1, Name)
|
||||
If Not DatabaseUpdate(DbId, "INSERT INTO nodes (node_id, name, origin) VALUES (?, ?, 'peer') " +
|
||||
"ON CONFLICT (node_id) DO UPDATE SET name = excluded.name, origin = 'peer' WHERE origin = 'id'")
|
||||
ProcedureReturn -1
|
||||
EndIf
|
||||
SetDatabaseString(DbId, 0, Name)
|
||||
If DatabaseQuery(DbId, "SELECT node_id FROM nodes WHERE name = ?")
|
||||
If NextDatabaseRow(DbId)
|
||||
Id = GetDatabaseLong(DbId, 0)
|
||||
EndIf
|
||||
FinishDatabaseQuery(DbId)
|
||||
EndIf
|
||||
ProcedureReturn Id
|
||||
EndProcedure
|
||||
|
||||
|
||||
Procedure.s Seed_Json(NodeId.i, Seq.q, Pad.s)
|
||||
Protected Kind.s, Value.i
|
||||
|
||||
If Seq % 50 = 0
|
||||
Kind = "alert"
|
||||
Else
|
||||
Select Seq % 4
|
||||
Case 0 : Kind = "temp"
|
||||
Case 1 : Kind = "humidity"
|
||||
Case 2 : Kind = "pressure"
|
||||
Default : Kind = "status"
|
||||
EndSelect
|
||||
EndIf
|
||||
Value = (Seq * 7919 + NodeId) % 10000
|
||||
ProcedureReturn ~"{\"kind\":\"" + Kind + ~"\",\"node\":" + Str(NodeId) + ~",\"seq\":" + Str(Seq) +
|
||||
~",\"value\":" + StrD(Value / 100.0, 2) + ~",\"ts\":" + Str(1700000000 + Seq) +
|
||||
~",\"pad\":\"" + Pad + ~"\"}"
|
||||
EndProcedure
|
||||
|
||||
|
||||
Define TopicId.i, NodesSpec.s, RowsPerNode.i, MessageSize.i, Pad.s
|
||||
Define NewList Nodes.i(), NewList Dbs.i()
|
||||
Define i.i, Part.s, First.i, Last.i, Node.i, StartId.q, Id.q, MaxId.q, Count.q, StartMs.i, Total.q, d.i
|
||||
Define Dim LocalIds.i(0)
|
||||
|
||||
OpenConsole()
|
||||
|
||||
If CountProgramParameters() < 5
|
||||
PrintN("Usage: BenchSeed <TopicId> <Nodes> <RowsPerNode> <MessageSize> <Db> [Db...]")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
TopicId = Val(ProgramParameter(0))
|
||||
NodesSpec = ProgramParameter(1)
|
||||
RowsPerNode = Val(ProgramParameter(2))
|
||||
MessageSize = Val(ProgramParameter(3))
|
||||
If MessageSize > 90
|
||||
Pad = LSet("", MessageSize - 90, "x")
|
||||
EndIf
|
||||
|
||||
For i = 1 To CountString(NodesSpec, ",") + 1
|
||||
Part = Trim(StringField(NodesSpec, i, ","))
|
||||
If Part = ""
|
||||
Continue
|
||||
EndIf
|
||||
If FindString(Part, "-")
|
||||
First = Val(StringField(Part, 1, "-"))
|
||||
Last = Val(StringField(Part, 2, "-"))
|
||||
Else
|
||||
First = Val(Part)
|
||||
Last = First
|
||||
EndIf
|
||||
For Node = First To Last
|
||||
AddElement(Nodes())
|
||||
Nodes() = Node
|
||||
Next
|
||||
Next
|
||||
|
||||
For i = 4 To CountProgramParameters() - 1
|
||||
AddElement(Dbs())
|
||||
Dbs() = OpenStorageDatabase(ProgramParameter(i))
|
||||
If Not Dbs() Or Not SetupStorageDatabase(Dbs())
|
||||
PrintN("Can't open '" + ProgramParameter(i) + "': " + DatabaseError())
|
||||
End 1
|
||||
EndIf
|
||||
Next
|
||||
|
||||
StartMs = ElapsedMilliseconds()
|
||||
ReDim LocalIds(ListSize(Dbs()) - 1)
|
||||
ForEach Nodes()
|
||||
; Where every database is at for this node, continue after the furthest.
|
||||
StartId = 0
|
||||
d = 0
|
||||
ForEach Dbs()
|
||||
LocalIds(d) = Seed_LocalNode(Dbs(), Nodes())
|
||||
If LocalIds(d) < 0
|
||||
PrintN("Can't name node " + Str(Nodes()) + ": " + DatabaseError())
|
||||
End 1
|
||||
EndIf
|
||||
MaxId = GetLatestMessageId(Dbs(), TopicId, LocalIds(d))
|
||||
If MaxId > StartId
|
||||
StartId = MaxId
|
||||
EndIf
|
||||
d + 1
|
||||
Next
|
||||
|
||||
d = -1
|
||||
ForEach Dbs()
|
||||
d + 1
|
||||
Id = StartId
|
||||
While Id < StartId + RowsPerNode
|
||||
If Not DatabaseUpdate(Dbs(), "BEGIN IMMEDIATE")
|
||||
PrintN("BEGIN failed: " + DatabaseError())
|
||||
End 1
|
||||
EndIf
|
||||
Count = 0
|
||||
While Count < #Seed_BatchSize And Id < StartId + RowsPerNode
|
||||
Id + 1
|
||||
Count + 1
|
||||
If Not InsertReplicatedMessage(Dbs(), TopicId, LocalIds(d), Id, Seed_Json(Nodes(), Id, Pad))
|
||||
PrintN("Insert failed: " + DatabaseError())
|
||||
End 1
|
||||
EndIf
|
||||
Wend
|
||||
If Not DatabaseUpdate(Dbs(), "COMMIT")
|
||||
PrintN("COMMIT failed: " + DatabaseError())
|
||||
End 1
|
||||
EndIf
|
||||
Total + Count
|
||||
Wend
|
||||
Next
|
||||
Next
|
||||
|
||||
ForEach Dbs()
|
||||
CloseDatabase(Dbs())
|
||||
Next
|
||||
|
||||
PrintN("Seeded " + Str(Total) + " rows (" + Str(RowsPerNode) + " per node, " + Str(ListSize(Nodes())) + " nodes, " + Str(ListSize(Dbs())) + " databases) in " + StrD((ElapsedMilliseconds() - StartMs) / 1000.0, 1) + " s")
|
||||
End 0
|
||||
@@ -0,0 +1,58 @@
|
||||
; ============================================================================
|
||||
; BakaShrot Bench Server
|
||||
;
|
||||
; Usage: BenchServer <ConfigFile> <StopFile>
|
||||
;
|
||||
; The real server (Server/Root.pbi), without the console commands: it runs
|
||||
; until StopFile exists, then stops its workers cleanly and exits.
|
||||
; BakaShrot_Server.exe can't run headless, with no console input its
|
||||
; Input() returns Chr(4) and it stops right away, see Notes.md.
|
||||
;
|
||||
; Used by Tests/Bench/Bench-Replication.ps1, compile as a thread-safe console
|
||||
; program.
|
||||
; ============================================================================
|
||||
|
||||
EnableExplicit
|
||||
|
||||
XIncludeFile "../../Server/Root.pbi"
|
||||
|
||||
|
||||
Define Root.BakaShrot_Root
|
||||
Define StopFile.s
|
||||
|
||||
OpenConsole("BakaShrot Bench Server")
|
||||
|
||||
If CountProgramParameters() < 2
|
||||
PrintN("Usage: BenchServer <ConfigFile> <StopFile>")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
Root\ConfigPath = ProgramParameter(0)
|
||||
StopFile = ProgramParameter(1)
|
||||
|
||||
If Not BakaShrot_Root_LoadConfig(@Root)
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_Root_OpenDatabase(@Root)
|
||||
FreeConfig(Root\Config)
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_Root_StartWorkers(@Root)
|
||||
BakaShrot_Root_CloseDatabase(@Root)
|
||||
FreeConfig(Root\Config)
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
PrintN("Running until '" + StopFile + "' exists.")
|
||||
|
||||
While FileSize(StopFile) < 0
|
||||
Delay(200)
|
||||
Wend
|
||||
|
||||
PrintN("Stopping...")
|
||||
BakaShrot_Root_StopWorkers(@Root)
|
||||
BakaShrot_Root_CloseDatabase(@Root)
|
||||
FreeConfig(Root\Config)
|
||||
End 0
|
||||
@@ -0,0 +1,106 @@
|
||||
# ============================================================================
|
||||
# Compares runs of Bench-Replication.ps1 side by side, as a markdown table.
|
||||
#
|
||||
# Usage:
|
||||
# powershell -ExecutionPolicy Bypass -File Tests\Bench\Compare-Runs.ps1 `
|
||||
# -Runs "Build\Bench\runs\20261107-123413,Build\Bench\runs\20261107-125334" `
|
||||
# -Labels "Before,WAL + wake-ups" [-Out comparison.md]
|
||||
#
|
||||
# Picks the key numbers of each run's results.json: the push ceilings, the
|
||||
# latencies, replication lag and drain, CPU and RAM, the queries at the
|
||||
# biggest data size, and the mixed stage. Stages missing from a run show "-".
|
||||
# ============================================================================
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $true)] [string[]]$Runs,
|
||||
[string[]]$Labels = @(),
|
||||
[string]$Out = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# "powershell -File" passes "a,b" as one string.
|
||||
$Runs = @($Runs | ForEach-Object { $_ -split "," } | ForEach-Object { $_.Trim() } | Where-Object { $_ })
|
||||
$Labels = @($Labels | ForEach-Object { $_ -split "," } | ForEach-Object { $_.Trim() } | Where-Object { $_ })
|
||||
|
||||
$Culture = [Globalization.CultureInfo]::InvariantCulture
|
||||
|
||||
function Format-Num($Value, $Decimals = 0) {
|
||||
if ($null -eq $Value) { return "-" }
|
||||
return ([double]$Value).ToString("N$Decimals", $Culture)
|
||||
}
|
||||
|
||||
$Data = @()
|
||||
for ($i = 0; $i -lt $Runs.Count; $i++) {
|
||||
$Json = Get-Content (Join-Path $Runs[$i] "results.json") -Raw | ConvertFrom-Json
|
||||
$Label = if ($i -lt $Labels.Count) { $Labels[$i] } else { Split-Path $Runs[$i] -Leaf }
|
||||
$Data += [pscustomobject]@{ Label = $Label; Results = @($Json.Results); Queries = @($Json.Queries) }
|
||||
}
|
||||
|
||||
# A stage by the end of its name ("5x0" matches "ramp05-5x0").
|
||||
function Get-Stage($Run, $Suffix) {
|
||||
return $Run.Results | Where-Object { $_.Stage -like "*$Suffix" } | Select-Object -First 1
|
||||
}
|
||||
|
||||
function Get-Max($Stage, $Property) {
|
||||
if (-not $Stage) { return $null }
|
||||
return ($Stage.Servers | Measure-Object -Property $Property -Maximum).Maximum
|
||||
}
|
||||
|
||||
function Get-Avg($Stage, $Property) {
|
||||
if (-not $Stage) { return $null }
|
||||
return ($Stage.Servers | Measure-Object -Property $Property -Average).Average
|
||||
}
|
||||
|
||||
# Median of a query on the first server, in the last stage that ran it.
|
||||
function Get-Query($Run, $Name) {
|
||||
$Q = $Run.Queries | Where-Object { $_.Name -eq $Name -and $_.Server -eq $Run.Results[0].Servers[0].Name } | Select-Object -Last 1
|
||||
if (-not $Q -or $Q.Count -eq 0) { return $null }
|
||||
return $Q.P50Ms
|
||||
}
|
||||
|
||||
function Get-LoadQuery($Run, $Name) {
|
||||
$Mixed = Get-Stage $Run "mixed"
|
||||
if (-not $Mixed) { return $null }
|
||||
$Q = $Mixed.QueriesUnderLoad | Where-Object Name -eq $Name | Select-Object -First 1
|
||||
if (-not $Q) { return $null }
|
||||
return $Q.P50Ms
|
||||
}
|
||||
|
||||
$Rows = @(
|
||||
@("**Push ceiling**, msg/s, 5 nodes/server", { param($R) Format-Num (Get-Stage $R "5x0").PushRate }),
|
||||
@("**Push ceiling**, msg/s, 10 nodes/server", { param($R) Format-Num (Get-Stage $R "10x0").PushRate }),
|
||||
@("Pushed of 2,000 offered (10 x 50)", { param($R) Format-Num (Get-Stage $R "10x50").PushRate }),
|
||||
@("Pushed of 4,000 offered (10 x 100)", { param($R) Format-Num (Get-Stage $R "10x100").PushRate }),
|
||||
@("Push p50 / p99 ms, 10 x 50", { param($R) $S = Get-Stage $R "10x50"; if ($S) { "$(Format-Num $S.PushP50Ms 1) / $(Format-Num $S.PushP99Ms 1)" } else { "-" } }),
|
||||
@("Push p50 / p99 / max ms, flat out (10 nodes)", { param($R) $S = Get-Stage $R "10x0"; if ($S) { "$(Format-Num $S.PushP50Ms 1) / $(Format-Num $S.PushP99Ms 1) / $(Format-Num $S.PushMaxMs)" } else { "-" } }),
|
||||
@("Replication lag, s of pushes, flat out", { param($R) Format-Num (Get-Max (Get-Stage $R "10x0") "LagMaxSeconds") 1 }),
|
||||
@("Drain after the push, s, flat out", { param($R) Format-Num (Get-Stage $R "10x0").DrainSeconds 1 }),
|
||||
@("Server CPU, % of a core, flat out (avg of the 4)", { param($R) Format-Num (Get-Avg (Get-Stage $R "10x0") "CpuAvgPush") }),
|
||||
@("Machine CPU %, flat out", { param($R) Format-Num (Get-Stage $R "10x0").SystemCpuAvg }),
|
||||
@("Hub RAM, working set MB, max", { param($R) Format-Num (($R.Results | ForEach-Object { $_.Servers[0].WorkingSetMaxMb } | Measure-Object -Maximum).Maximum) 1 }),
|
||||
@("Rows per server at the end", { param($R) Format-Num $R.Results[-1].Servers[0].Rows }),
|
||||
@("Query: latest message, ms (1M rows)", { param($R) Format-Num (Get-Query $R "latest_message") 1 }),
|
||||
@("Query: last 50 of a node, ms", { param($R) Format-Num (Get-Query $R "last_50_of_node") 1 }),
|
||||
@("Query: sync state (GROUP BY all), ms", { param($R) Format-Num (Get-Query $R "sync_state") 1 }),
|
||||
@("Query: sync state from node_heads (what check-ins use now), ms", { param($R) Format-Num (Get-Query $R "sync_state_heads") 1 }),
|
||||
@("Query: JSON count over all rows, ms", { param($R) Format-Num (Get-Query $R "json_count_all") 1 }),
|
||||
@("Query: JSON aggregate over all rows, ms", { param($R) Format-Num (Get-Query $R "json_agg_all") 1 }),
|
||||
@("**Mixed:** pushed of 400 msg/s with a query loop", { param($R) Format-Num (Get-Stage $R "mixed").PushRate }),
|
||||
@("Mixed: push p99 / max ms", { param($R) $S = Get-Stage $R "mixed"; if ($S) { "$(Format-Num $S.PushP99Ms 1) / $(Format-Num $S.PushMaxMs)" } else { "-" } }),
|
||||
@("Mixed: failed pushes", { param($R) $S = Get-Stage $R "mixed"; if ($S) { $S.Failed } else { "-" } }),
|
||||
@("Mixed: JSON count over all rows, ms, under load", { param($R) Format-Num (Get-LoadQuery $R "json_count_all") 1 }),
|
||||
@("Mixed: latest message, ms, under load", { param($R) Format-Num (Get-LoadQuery $R "latest_message") 1 })
|
||||
)
|
||||
|
||||
$Lines = @()
|
||||
$Lines += "| | " + (($Data | ForEach-Object { $_.Label }) -join " | ") + " |"
|
||||
$Lines += "|---|" + (($Data | ForEach-Object { "---" }) -join "|") + "|"
|
||||
foreach ($Row in $Rows) {
|
||||
$Cells = foreach ($Run in $Data) { & $Row[1] $Run }
|
||||
$Lines += "| $($Row[0]) | " + ($Cells -join " | ") + " |"
|
||||
}
|
||||
|
||||
$Text = $Lines -join "`r`n"
|
||||
if ($Out) { Set-Content -Path $Out -Value $Text -Encoding UTF8 }
|
||||
$Text
|
||||
@@ -0,0 +1,182 @@
|
||||
# Benchmark results, 2026-11-07
|
||||
|
||||
`Bench-Replication.ps1` with its defaults: 4 servers in a Y (a hub linked to
|
||||
3 leaves), 5-10 nodes pushing to each, ~200-byte JSON messages, 30 s per
|
||||
stage, `PeerSyncInterval = 5`, `PeerBatchSize = 100`. All on one machine
|
||||
(i5-13500, 16 GB, NVMe), PureBasic 5.73 x64 unless said otherwise, SQLite
|
||||
3.54.1. Table made with `Compare-Runs.ps1`.
|
||||
|
||||
| Version | What changed |
|
||||
|---|---|
|
||||
| Before | Rollback journal, a sync to disk per push, every wait a `Delay(5)` / `Delay(1)` loop |
|
||||
| WAL + wake-ups | WAL with `synchronous = NORMAL`, threads woken by an event / `select()`, a write mutex instead of SQLite's busy-wait |
|
||||
| + grouping | Pushes arriving together share one transaction (group commit) |
|
||||
| + no per-push log | The `PrintN()` per push / read / query removed (`#BakaShrot_Net_LogRequests`) |
|
||||
| + prepared/cache/checkpoints/heads | One writer connection with prepared statements (SQLite's own API), next ids cached in memory, WAL checkpoints in a background thread, the sync state from `node_heads` (`Server/Storage/Writer.pbi`) |
|
||||
| same on PB 6.40 C | The same code, built with PureBasic 6.40's C backend and `/OPTIMIZER` (the load generator too) |
|
||||
|
||||
| | Before | WAL + wake-ups | + grouping | + no per-push log | + prepared/cache/checkpoints/heads (5.73) | same on PB 6.40 C |
|
||||
|---|---|---|---|---|---|---|
|
||||
| **Push ceiling**, msg/s, 5 nodes/server | 958 | 5,771 | 5,709 | 25,681 | 33,522 | 37,162 |
|
||||
| **Push ceiling**, msg/s, 10 nodes/server | 904 | 5,726 | 5,814 | 25,707 | 34,345 | 38,358 |
|
||||
| Pushed of 2,000 offered (10 x 50) | 924 | 1,999 | 2,000 | 2,000 | 2,000 | 1,999 |
|
||||
| Pushed of 4,000 offered (10 x 100) | 899 | 4,000 | 4,000 | 4,000 | 4,000 | 4,000 |
|
||||
| Push p50 / p99 ms, 10 x 50 | 18.0 / 491.5 | 0.4 / 5.1 | 0.5 / 7.2 | 0.5 / 13.6 | 0.3 / 0.8 | 0.2 / 0.9 |
|
||||
| Push p50 / p99 / max ms, flat out (10 nodes) | 18.0 / 574.9 / 2,642 | 5.5 / 25.2 / 193 | 5.6 / 23.1 / 56 | 0.9 / 16.5 / 149 | 0.5 / 2.8 / 854 | 0.5 / 2.5 / 1,485 |
|
||||
| Replication lag, s of pushes, flat out | 8.9 | 5.1 | 5.0 | 8.9 | 9.9 | 8.3 |
|
||||
| Drain after the push, s, flat out | 6.2 | 5.8 | 5.8 | 10.3 | 11.3 | 11.3 |
|
||||
| Server CPU, % of a core, flat out (avg of the 4) | 45 | 65 | 66 | 130 | 120 | 121 |
|
||||
| Machine CPU %, flat out | 41 | 33 | 34 | 67 | 65 | 65 |
|
||||
| Hub RAM, working set MB, max | 34.6 | 42.9 | 44.6 | 45.2 | 38.8 | 40.1 |
|
||||
| Rows per server at the end | 1,021,883 | 1,024,025 | 1,024,025 | 1,887,117 | 2,389,201 | 2,619,806 |
|
||||
| Query: latest message, ms (1M rows) | 5.9 | 0.5 | 0.5 | 0.1 | 0.1 | 0.1 |
|
||||
| Query: last 50 of a node, ms | 5.8 | 1.0 | 1.0 | 0.7 | 0.8 | 0.7 |
|
||||
| Query: sync state (GROUP BY all), ms | 78.0 | 73.1 | 72.1 | 131.9 | 166.7 | 184.1 |
|
||||
| Query: sync state from node_heads (what check-ins use now), ms | - | - | - | - | 0.6 | 0.5 |
|
||||
| Query: JSON count over all rows, ms | 473.6 | 475.1 | 475.3 | 857.5 | 1,080.7 | 1,199.4 |
|
||||
| Query: JSON aggregate over all rows, ms | 1,647.8 | 1,575.8 | 1,533.9 | 2,800.2 | 3,974.2 | 4,371.2 |
|
||||
| **Mixed:** pushed of 400 msg/s with a query loop | 323 | 396 | 397 | 397 | 392 | 396 |
|
||||
| Mixed: push p99 / max ms | 820.2 / 5,119 | 0.7 / 17 | 7.9 / 17 | 18.0 / 30 | 1.2 / 17 | 0.9 / 17 |
|
||||
| Mixed: failed pushes | 1 | 0 | 0 | 0 | 0 | 0 |
|
||||
| Mixed: JSON count over all rows, ms, under load | 545.4 | 502.3 | 506.5 | 925.0 | 1,148.2 | 1,265.6 |
|
||||
| Mixed: latest message, ms, under load | 12.0 | 0.2 | 0.2 | 0.1 | 0.2 | 0.2 |
|
||||
|
||||
The full-table scans grow with the data, and the later runs' flat-out stages
|
||||
wrote more of it: 1.9M, 2.4M, then 2.6M rows per server instead of ~1.02M.
|
||||
Per row they cost the same (~0.45 ms per 1,000 rows for the JSON count).
|
||||
PB 6.40 doesn't change them either, SQLite does the scanning.
|
||||
|
||||
## What limited each version
|
||||
|
||||
- **Before:** the sync to disk on every push, ~250 commits/s per database.
|
||||
- **WAL + wake-ups:** not the database anymore. The `PrintN()` logging every
|
||||
push takes ~0.4 ms and serializes every thread behind it: ~2,400 pushes/s
|
||||
per server whatever the number of nodes, with the server mostly idle
|
||||
(measured on a single server: the listener asleep in `select()` 91 % of
|
||||
the time, the writes busy 33 %, 0.14 ms per push).
|
||||
- **+ grouping:** same cap, so no gain yet: the pushes never piled up
|
||||
behind the write mutex (1.0 per transaction on average). It did cut the
|
||||
worst push from 193 to 56 ms.
|
||||
- **+ no per-push log:** a single server went from ~2,400 to ~12,000
|
||||
pushes/s, and grouping now kicks in: 2.5 pushes per transaction at 5
|
||||
nodes, ~5-9 at 10-20, the database busy 70-90 % of the time at 0.07-0.11
|
||||
ms per push. The cluster tops out at ~25,700 msg/s with the machine at
|
||||
67 % CPU (the load generator itself ~85 % of a core). Next limits: each
|
||||
server's write section, and running everything on one machine.
|
||||
- **+ prepared/cache/checkpoints/heads:** ~25,700 -> ~34,300 msg/s. A push
|
||||
costs ~0.05 ms of write time instead of 0.07-0.11, no statement is
|
||||
prepared again, no MAX() per push. The p99 at moderate load is back under
|
||||
1 ms (13.6 -> 0.8 ms at 10 x 50, 18 -> 1.2 ms in the mixed stage): the
|
||||
checkpoints were what held the writes up. Flat out, the WAL grows faster
|
||||
than the background checkpoints keep up with, so the writer checkpoints by
|
||||
itself past 10,000 frames, and the worst push goes from 149 to 854 ms. The
|
||||
sync state every check-in reads: 0.5 ms instead of a 167 ms GROUP BY.
|
||||
- **Same on PB 6.40 C:** ~34,300 -> ~38,400 msg/s (+12 %), the same
|
||||
latencies, slightly less lag. Both the servers and the load generator are
|
||||
built with it, so part of it may be the generator. The SQLite side (the
|
||||
write section, the queries) is the same DLL either way.
|
||||
|
||||
## Notes
|
||||
|
||||
- Ids checked after the last four runs: every node 1..N, no gap, no
|
||||
duplicate, on all 4 servers, and `node_heads` exactly matching `data`.
|
||||
- **p99 at moderate load went up with grouping** (0.7 -> 8-18 ms), and came
|
||||
back down once the checkpoints left the write path (see above).
|
||||
- Replication keeps up at every load: it drains within ~11 s even after
|
||||
38,000 msg/s. The lag is the check-in wait (`PeerSyncInterval`) plus the
|
||||
hub relaying to its leaves, see `Design/Suggestions.md` #2 to lower it.
|
||||
- The worst push flat out (0.85-1.5 s) is the writer's backstop checkpoint,
|
||||
see `Design/Suggestions.md` #3.
|
||||
|
||||
## Names and wildcards (evening)
|
||||
|
||||
Same benchmark, PureBasic 5.73, after topics and nodes got names, strict
|
||||
"named on both sides" replication, and wildcards, run with `-Names
|
||||
Wildcard`: each server only names its own nodes, and takes everyone else's
|
||||
by `AcceptNodes = n*`, so each server adds the other servers' 30 nodes
|
||||
under ids of its own (counting down from 65535), and the hub relays them on
|
||||
by name. The worst case for the new code: every batch goes through a name
|
||||
lookup and every check-in through the patterns. Run `20261107-220433`,
|
||||
compared with `Compare-Runs.ps1` (`comparison.md` in the run's folder).
|
||||
|
||||
| | Before names (5.73) | Before names (PB 6.40 C) | Names + wildcards (5.73) |
|
||||
|---|---|---|---|
|
||||
| **Push ceiling**, msg/s, 5 nodes/server | 33,522 | 37,162 | 35,124 |
|
||||
| **Push ceiling**, msg/s, 10 nodes/server | 34,345 | 38,358 | 32,846 |
|
||||
| Push p50 / p99 ms, 10 x 50 | 0.3 / 0.8 | 0.2 / 0.9 | 0.3 / 1.1 |
|
||||
| Push p50 / p99 / max ms, flat out (10 nodes) | 0.5 / 2.8 / 854 | 0.5 / 2.5 / 1,485 | 0.6 / 3.2 / 1,503 |
|
||||
| Replication lag, s of pushes, flat out | 9.9 | 8.3 | 8.6 |
|
||||
| Drain after the push, s, flat out | 11.3 | 11.3 | 11.8 |
|
||||
| Server CPU, % of a core, flat out (avg of the 4) | 120 | 121 | 129 |
|
||||
| Hub RAM, working set MB, max | 38.8 | 40.1 | 39.3 |
|
||||
| Rows per server at the end | 2,389,201 | 2,619,806 | 2,395,509 |
|
||||
| Query: sync state from node_heads, ms | 0.6 | 0.5 | 0.7 |
|
||||
| Query: JSON count over all rows, ms | 1,080.7 | 1,199.4 | 1,105.8 |
|
||||
| **Mixed:** pushed of 400 msg/s with a query loop | 392 | 396 | 397 |
|
||||
| Mixed: push p99 / max ms | 1.2 / 17 | 0.9 / 17 | 0.9 / 18 |
|
||||
| Failed pushes, refusals between servers | 0 | 0 | 0 |
|
||||
|
||||
- **Same speed, within run-to-run noise.** Flat out at 10 nodes, the same
|
||||
build gave 32,976 and 37,003 msg/s in two ramp-only runs (declared names)
|
||||
earlier this evening: ±6 % between runs is usual on this machine. The push
|
||||
path itself didn't change, only the check-ins and the batches' first
|
||||
lines.
|
||||
- **Server CPU +7 %** flat out (129 vs 120 % of a core), the name lookups
|
||||
and the bigger sync states, possibly part of the noise too.
|
||||
- **Replication** keeps up at every load and drains in the same time; no
|
||||
batch refused anywhere, every server ended with the same rows.
|
||||
- **Measuring changed slightly:** the lag monitor now asks for each node's
|
||||
latest id by name through the `messages` view (ids differ between
|
||||
servers in this mode), the old runs asked `data` by id. Both are index
|
||||
lookups.
|
||||
|
||||
## Big messages, no JSON check on push, is_json clause (2026-11-08)
|
||||
|
||||
Same setup as the evening run (`-Names Wildcard`), after: packets up to
|
||||
16 MB once authenticated (new inbox: growth by doubling, a read offset),
|
||||
replication batches still ~64 KB, pushes no longer checked to be JSON
|
||||
(`ParseJSON()` gone from the push path, `is_json` flags them), and
|
||||
`is_json = 1` added to the JSON queries.
|
||||
|
||||
| | Before names (5.73) | Before names (PB 6.40 C) | Names + wildcards (5.73) | Big messages, no JSON check, is_json clause (5.73) |
|
||||
|---|---|---|---|---|
|
||||
| **Push ceiling**, msg/s, 5 nodes/server | 33,522 | 37,162 | 35,124 | **38,199** |
|
||||
| **Push ceiling**, msg/s, 10 nodes/server | 34,345 | 38,358 | 32,846 | **37,745** |
|
||||
| Pushed of 2,000 offered (10 x 50) | 2,000 | 1,999 | 1,999 | 2,001 |
|
||||
| Pushed of 4,000 offered (10 x 100) | 4,000 | 4,000 | 4,000 | 4,000 |
|
||||
| Push p50 / p99 ms, 10 x 50 | 0.3 / 0.8 | 0.2 / 0.9 | 0.3 / 1.1 | 0.3 / 1.0 |
|
||||
| Push p50 / p99 / max ms, flat out (10 nodes) | 0.5 / 2.8 / 854 | 0.5 / 2.5 / 1,485 | 0.6 / 3.2 / 1,503 | 0.5 / 2.9 / 822 |
|
||||
| Replication lag, s of pushes, flat out | 9.9 | 8.3 | 8.6 | 10.5 |
|
||||
| Drain after the push, s, flat out | 11.3 | 11.3 | 11.8 | 13.8 |
|
||||
| Server CPU, % of a core, flat out (avg of the 4) | 120 | 121 | 129 | 120 |
|
||||
| Machine CPU %, flat out | 65 | 65 | 69 | 66 |
|
||||
| Hub RAM, working set MB, max | 38.8 | 40.1 | 39.3 | 42.8 |
|
||||
| Rows per server at the end | 2,389,201 | 2,619,806 | 2,395,509 | 2,628,001 |
|
||||
| Query: latest message, ms | 0.1 | 0.1 | 0.1 | 0.1 |
|
||||
| Query: last 50 of a node, ms | 0.8 | 0.7 | 0.8 | 0.8 |
|
||||
| Query: sync state (GROUP BY all), ms | 166.7 | 184.1 | 170.5 | 187.9 |
|
||||
| Query: sync state from node_heads (what check-ins use now), ms | 0.6 | 0.5 | 0.7 | 0.6 |
|
||||
| Query: JSON count over all rows, ms | 1,080.7 | 1,199.4 | 1,105.8 | 1,233.6 |
|
||||
| Query: JSON aggregate over all rows, ms | 3,974.2 | 4,371.2 | 4,084.2 | 4,464.4 |
|
||||
| Same, per million rows: sync state / JSON count / JSON aggregate, ms | 69.8 / 452 / 1,663 | 70.3 / 458 / 1,669 | 71.2 / 462 / 1,705 | 71.5 / 469 / 1,699 |
|
||||
| **Mixed:** pushed of 400 msg/s with a query loop | 392 | 396 | 397 | 384 |
|
||||
| Mixed: push p99 / max ms | 1.2 / 17 | 0.9 / 17 | 0.9 / 18 | 1.0 / 15 |
|
||||
| Mixed: failed pushes | 0 | 0 | 0 | 0 |
|
||||
| Mixed: JSON count over all rows, ms, under load | 1,148.2 | 1,265.6 | 1,179.5 | 1,313.4 |
|
||||
| Mixed: latest message, ms, under load | 0.2 | 0.2 | 0.2 | 0.2 |
|
||||
|
||||
Runs: `20261107-140556`, `20261107-141735`, `20261107-220433`, `20261108-033149` (all 4 servers in a Y, ~200-byte messages; the last two with `-Names Wildcard`). Query times are from the end of each run, so they scale with its row count: compare the per-million row.
|
||||
|
||||
- **Push ceiling up 9-15 %** (38,199 / 37,745 msg/s), the best yet on 5.73,
|
||||
for the same server CPU (120 % of a core). Likely mostly `ParseJSON()`
|
||||
leaving the push path, though runs of one build have spread 33-37k.
|
||||
- **Lag and drain** are a bit higher in seconds, with 15 % more messages
|
||||
pushed per second to relay (397,066 messages behind at most, vs 282,621).
|
||||
- **The `is_json = 1` clause costs nothing measurable:** per million rows,
|
||||
the JSON count is 469 ms vs 462, the aggregate 1,699 vs 1,705.
|
||||
- **Mixed: 384 of 400 msg/s pushed** (397 before), with no failures and a
|
||||
lower p99. The bench's pushers are paced by its own loop, and this run's
|
||||
database was 10 % bigger, so the query loop beside them was slower. Worth
|
||||
a second run before reading anything into it.
|
||||
- 0 refused, failed or "too big" in the server logs, 2,628,001 rows on all
|
||||
4 servers.
|
||||
@@ -0,0 +1,30 @@
|
||||
# Query suite, run by BenchClient's "query" mode after every stage, see
|
||||
# Bench-Replication.ps1. One per line: Name | SQL
|
||||
# {TOPIC} and {NODE} are replaced by the topic id and the server's first node.
|
||||
# "@latest" is a GetLatestMessage of {NODE}, the regular read path.
|
||||
# Results must fit in one packet (64 KB) and 10000 rows.
|
||||
#
|
||||
# The messages look like:
|
||||
# {"kind":"temp","node":101,"seq":12,"value":42.17,"ts":1700000012,"pad":"xxx"}
|
||||
# kind is "alert" for 1 in 50, the others are spread evenly.
|
||||
|
||||
# Indexed, should stay flat as the data grows.
|
||||
latest_message | @latest
|
||||
last_50_of_node | SELECT message_id, message_data FROM data WHERE topic_id = {TOPIC} AND node_id = {NODE} ORDER BY message_id DESC LIMIT 50
|
||||
max_of_node | SELECT MAX(message_id) FROM data WHERE topic_id = {TOPIC} AND node_id = {NODE}
|
||||
by_message_id | SELECT topic_id, node_id FROM data WHERE message_id = 100
|
||||
recent_global | SELECT topic_id, node_id, message_id FROM data ORDER BY rowid DESC LIMIT 100
|
||||
|
||||
# Bounded JSON scan: newest alerts of one node, about 50 rows read per hit.
|
||||
json_alerts_node | SELECT message_id, message_data ->> '$.value' FROM data WHERE topic_id = {TOPIC} AND node_id = {NODE} AND is_json = 1 AND message_data ->> '$.kind' = 'alert' ORDER BY message_id DESC LIMIT 100
|
||||
|
||||
# Index scans, grow with the data.
|
||||
count_node | SELECT COUNT(*) FROM data WHERE topic_id = {TOPIC} AND node_id = {NODE}
|
||||
count_all | SELECT COUNT(*) FROM data
|
||||
sync_state | SELECT topic_id, node_id, MAX(message_id) FROM data GROUP BY topic_id, node_id ORDER BY topic_id, node_id
|
||||
sync_state_heads | SELECT topic_id, node_id, max_message_id FROM node_heads ORDER BY topic_id, node_id
|
||||
|
||||
# Full table scans parsing every message's JSON, the ones that die first.
|
||||
json_count_all | SELECT COUNT(*) FROM data WHERE is_json = 1 AND message_data ->> '$.kind' = 'alert'
|
||||
json_agg_all | SELECT message_data ->> '$.kind', COUNT(*), ROUND(AVG(message_data ->> '$.value'), 2) FROM data WHERE is_json = 1 GROUP BY 1
|
||||
json_agg_node | SELECT message_data ->> '$.kind', COUNT(*), ROUND(AVG(message_data ->> '$.value'), 2) FROM data WHERE topic_id = {TOPIC} AND node_id = {NODE} AND is_json = 1 GROUP BY 1
|
||||
@@ -0,0 +1,13 @@
|
||||
# Queries run in a loop while pushing, in the "mixed" stage of
|
||||
# Bench-Replication.ps1, to see how reads hold up under write load, and how
|
||||
# much a long read slows the writes down (it used to block every commit,
|
||||
# before WAL).
|
||||
# Same format as queries.txt.
|
||||
|
||||
latest_message | @latest
|
||||
last_50_of_node | SELECT message_id, message_data FROM data WHERE topic_id = {TOPIC} AND node_id = {NODE} ORDER BY message_id DESC LIMIT 50
|
||||
json_alerts_node | SELECT message_id, message_data ->> '$.value' FROM data WHERE topic_id = {TOPIC} AND node_id = {NODE} AND is_json = 1 AND message_data ->> '$.kind' = 'alert' ORDER BY message_id DESC LIMIT 100
|
||||
count_node | SELECT COUNT(*) FROM data WHERE topic_id = {TOPIC} AND node_id = {NODE}
|
||||
sync_state | SELECT topic_id, node_id, MAX(message_id) FROM data GROUP BY topic_id, node_id ORDER BY topic_id, node_id
|
||||
sync_state_heads | SELECT topic_id, node_id, max_message_id FROM node_heads ORDER BY topic_id, node_id
|
||||
json_count_all | SELECT COUNT(*) FROM data WHERE is_json = 1 AND message_data ->> '$.kind' = 'alert'
|
||||
Reference in New Issue
Block a user