Skip to content

Dispatcher handshake serializes every job at about 260k jobs/s #184

Closed

Description

@TMHSDigital

Summary

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.

Where

  • internal/scan/runner.go:533-535 (unbuffered jobs, enqueue, completed)
  • internal/scan/runner.go:692-731 (single dispatcher select)
  • 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

Getting started

  • Relevant files: internal/scan/runner.go
  • How to run tests: go test -race ./internal/scan/

Related: #49


Filed by repo-audit/full-audit at 3139c44. Severity: low. Effort: S. audit-key: performance|internal/scan/runner.go|Run.dispatcher

Activity

  1. added
    performance
    area: scan
    severity: low
    on Nov 9, 2026
  2. TMHSDigital commented on Nov 11, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 1fcd5bc.

    • 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: scanperformanceseverity: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions