You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dispatcher handshake serializes every job at about 260k jobs/s #184
The scan dispatcher uses three unbuffered channels and every worker performs two rendezvous per job, which caps the engine at about 260k jobs/s regardless of lookup cost. Irrelevant while UDP socket churn caps live scans near 10k qps, but it is the next ceiling once that is fixed, and it already makes 1M-entry simulations take about 3.5 s instead of under 1 s.
internal/scan/runner.go:740-746 (worker handshake per job)
Details
BenchmarkRun1M (simulate, 50 workers): 3.81 s/op, 81 MB, 1.0M allocs. pprof: 65% runtime.semasleep, 22% selectgo, 52% under chanrecv, that is lock and wake-up contention on the channels.
Steps to reproduce
go test ./internal/scan -bench BenchmarkRun1M -cpuprofile cpu.out then go tool pprof -top cpu.out.
Suggested fix
Give jobs a buffer (for example 4x workers) and batch completions (count per worker, report every k jobs or on cancel) so the dispatcher wakes once per batch. Best done after the dispatcher is lifted into its own type.
Acceptance criteria
1M-entry simulate run under 1 s at 50 workers
Cap, resume watermark and EventDone ordering tests unchanged
Chunked hand-out: the dispatcher hands out up to 8 jobs per chunk over a buffered jobs channel. Chunks are smaller when there are few names per worker, so short wordlists still spread across every worker.
Chunked reports: workers report each chunk's completions as one slice over a buffered completed channel.
Interrupts: on cancellation the dispatcher counts the reports already buffered before computing the resume point.
What I tried first: buffering alone, and per-worker batches of 32. Buffering gave about 20%. The 32-batch version made an interrupt lose the resume point (TestResumeMatchesUninterruptedRun failed), so I dropped it.
Results:
BenchmarkRun1M (simulate, 50 workers) on this machine: about 1.6 s/op before, 0.37 to 0.47 s/op after. That meets the under-1 s criterion.
Trade-off: a resumed scan may repeat up to one chunk per worker instead of one lookup per worker. The RootDone docs and the CHANGELOG say so.
Verified with the cap, resume-watermark and EventDone ordering tests, unchanged and passing 5 times in a row (3 under -race). Also added the new TestNextChunkSize, and ran the full go test ./... and golangci-lint run (0 issues).
Activity
TMHSDigital commentedon Nov 11, 2026
Fixed in 1fcd5bc.
jobschannel. Chunks are smaller when there are few names per worker, so short wordlists still spread across every worker.completedchannel.TestResumeMatchesUninterruptedRunfailed), so I dropped it.Results:
BenchmarkRun1M(simulate, 50 workers) on this machine: about 1.6 s/op before, 0.37 to 0.47 s/op after. That meets the under-1 s criterion.RootDonedocs and the CHANGELOG say so.Verified with the cap, resume-watermark and EventDone ordering tests, unchanged and passing 5 times in a row (3 under
-race). Also added the newTestNextChunkSize, and ran the fullgo test ./...andgolangci-lint run(0 issues).docs(architecture): describe the engine as it is on main (#228)
docs(scan,output): correct two stale comments (#233)