From d42b89c4483a4e22e6c72dc69cb49ca8e9b3b812 Mon Sep 17 00:00:00 2001 From: Hal <22532613+HalRiveria@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:08:12 -0500 Subject: [PATCH 1/2] Time the dispatcher's bookkeeping as a ratio, not against a fixed limit The 20,000-job test asserted under 15 s of wall clock, and CI's Windows PowerShell 5.1 runners take anywhere from about 4 to 14.5 s on the same code. It now times 20,000 jobs against the quicker of two 5,000-job runs in the same process and fails at 8 times as long: linear bookkeeping is about 4, and a PowerShell-level walk of the queue per job gives 9 to 10.6 while staying inside the old 15 s limit. Co-Authored-By: Claude Opus 5.5 --- ParallelKit.Harness.ps1 | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/ParallelKit.Harness.ps1 b/ParallelKit.Harness.ps1 index 61ea44e..792b8bf 100644 --- a/ParallelKit.Harness.ps1 +++ b/ParallelKit.Harness.ps1 @@ -1163,19 +1163,30 @@ Test-Assert ($watches.Count -eq 2 -and $null -ne $watches[1] -and -not [object]: # A large batch isn't slowed by per-job queue walks. No processes: the # starter/poll are stubs, so this times the dispatcher's own bookkeeping. -Reset-Harness -$bigCount = 20000 -$feed = @{ Given = $false } -$done = @{ Count = 0 } -$sw = [System.Diagnostics.Stopwatch]::StartNew() -$d = Invoke-PkProcessDispatch -MaxConcurrent 1000 ` - -GroupProvider { if ($feed.Given) { return $null }; $feed.Given = $true; return @{ Name = 'big' } }.GetNewClosure() ` - -JobBuilder { param($g) $jobs = [System.Collections.Generic.List[hashtable]]::new(); for ($i = 0; $i -lt $bigCount; $i++) { $jobs.Add(@{ Id = $i }) }; return $jobs }.GetNewClosure() ` - -JobStarter { param($job) return $job } -JobPollCompleted { param($job) return $true } ` - -JobFinalize { param($job, $pending) $done.Count++ }.GetNewClosure() -$sw.Stop() -Test-Assert ($done.Count -eq $bigCount) "a 20,000-job group runs to completion" -Test-Assert ($sw.Elapsed.TotalSeconds -lt 15) ("and the dispatcher's own bookkeeping stays quick (" + [math]::Round($sw.Elapsed.TotalSeconds, 1) + "s for 20,000 jobs)") +# Measured as a ratio, 20,000 jobs against 5,000 in the same run, so a slow +# runner doesn't fail it: linear bookkeeping takes about 4 times as long. A +# PowerShell-level walk of the queue per job made it 9 (7.7 s for 20,000 +# jobs on 5.1, inside the old 15 s limit). The quicker of two 5,000-job +# runs, so a slow spell there can't hide a walk. +Reset-Harness +function Measure-HarnessBookkeeping { + param([int]$Count) + $feed = @{ Given = $false } + $done = @{ Count = 0 } + $sw = [System.Diagnostics.Stopwatch]::StartNew() + $null = Invoke-PkProcessDispatch -MaxConcurrent 1000 ` + -GroupProvider { if ($feed.Given) { return $null }; $feed.Given = $true; return @{ Name = 'big' } }.GetNewClosure() ` + -JobBuilder { param($g) $jobs = [System.Collections.Generic.List[hashtable]]::new(); for ($i = 0; $i -lt $Count; $i++) { $jobs.Add(@{ Id = $i }) }; return $jobs }.GetNewClosure() ` + -JobStarter { param($job) return $job } -JobPollCompleted { param($job) return $true } ` + -JobFinalize { param($job, $pending) $done.Count++ }.GetNewClosure() + $sw.Stop() + return @{ Done = $done.Count; Seconds = $sw.Elapsed.TotalSeconds } +} +$small = [Math]::Min((Measure-HarnessBookkeeping -Count 5000).Seconds, (Measure-HarnessBookkeeping -Count 5000).Seconds) +$big = Measure-HarnessBookkeeping -Count 20000 +$ratio = $big.Seconds / [Math]::Max($small, 0.001) +Test-Assert ($big.Done -eq 20000) "a 20,000-job group runs to completion" +Test-Assert ($ratio -lt 8) ("and the dispatcher's own bookkeeping grows in step with the job count (" + [math]::Round($big.Seconds, 1) + "s for 20,000 jobs, " + [math]::Round($ratio, 1) + " times 5,000's " + [math]::Round($small, 2) + "s; linear is about 4)") Write-Host "" # ============================================================================== From a62f0d36b437e55d123e31bc0e20a3c699b64efb Mon Sep 17 00:00:00 2001 From: Hal <22532613+HalRiveria@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:17:43 -0500 Subject: [PATCH 2/2] Keep a 45 s ceiling on the 20,000-job run, for a slowdown the ratio can't see Co-Authored-By: Claude Opus 5.5 --- ParallelKit.Harness.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ParallelKit.Harness.ps1 b/ParallelKit.Harness.ps1 index 792b8bf..a52dc53 100644 --- a/ParallelKit.Harness.ps1 +++ b/ParallelKit.Harness.ps1 @@ -1167,7 +1167,9 @@ Test-Assert ($watches.Count -eq 2 -and $null -ne $watches[1] -and -not [object]: # runner doesn't fail it: linear bookkeeping takes about 4 times as long. A # PowerShell-level walk of the queue per job made it 9 (7.7 s for 20,000 # jobs on 5.1, inside the old 15 s limit). The quicker of two 5,000-job -# runs, so a slow spell there can't hide a walk. +# runs, so a slow spell there can't hide a walk. A ceiling of 45 s (about +# 3 times CI's slowest 5.1 runner) still catches a gross slowdown per job, +# which the ratio can't see. Reset-Harness function Measure-HarnessBookkeeping { param([int]$Count) @@ -1186,7 +1188,7 @@ $small = [Math]::Min((Measure-HarnessBookkeeping -Count 5000).Seconds, (Measure- $big = Measure-HarnessBookkeeping -Count 20000 $ratio = $big.Seconds / [Math]::Max($small, 0.001) Test-Assert ($big.Done -eq 20000) "a 20,000-job group runs to completion" -Test-Assert ($ratio -lt 8) ("and the dispatcher's own bookkeeping grows in step with the job count (" + [math]::Round($big.Seconds, 1) + "s for 20,000 jobs, " + [math]::Round($ratio, 1) + " times 5,000's " + [math]::Round($small, 2) + "s; linear is about 4)") +Test-Assert ($ratio -lt 8 -and $big.Seconds -lt 45) ("and the dispatcher's own bookkeeping grows in step with the job count (" + [math]::Round($big.Seconds, 1) + "s for 20,000 jobs, " + [math]::Round($ratio, 1) + " times 5,000's " + [math]::Round($small, 2) + "s; linear is about 4)") Write-Host "" # ==============================================================================