Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ Charts at 24, 8 and 4 CPUs: [pool-24cpu](https://benchmarks.goptics.org/?id=pool

## Results

Run of 2026-10-24, varmq v1.10.0, `-benchtime=2x`, 495 rows per file. Each file has 55 task/size/workload rows (11 groups such as `Loop10W50K` x 5 workloads), each with 9 subjects. The table counts the rows in which each subject has the lowest `ns/op`; no other subject is fastest in any row.
Run of 2026-10-25, varmq v1.10.0, `-benchtime=2x`, 495 rows per file. Each file has 55 task/size/workload rows (11 groups such as `Loop10W50K` x 5 workloads), each with 9 subjects. The table counts the rows in which each subject has the lowest `ns/op`; no other subject is fastest in any row.

| CPUs | Rows | VarMQ | Ants | ErrGroup | BufferedPool |
|------|------|-------|------|----------|--------------|
| 24 | 55 | 40 | 0 | 2 | 13 |
| 8 | 55 | 36 | 0 | 6 | 13 |
| 4 | 55 | 20 | 4 | 11 | 20 |
| CPUs | Rows | VarMQ | Ants | ErrGroup | Gopool | BufferedPool |
|------|------|-------|------|----------|--------|--------------|
| 24 | 55 | 39 | 0 | 3 | 1 | 12 |
| 8 | 55 | 33 | 0 | 8 | 0 | 14 |
| 4 | 55 | 19 | 4 | 11 | 0 | 21 |

On the 15 one-worker `Loop10W1` rows (5 workloads x 3 files), BufferedPool is fastest in 14. On the four workloads other than `1Mu-1t`, the next subject (Gopool on `1u-1Mt`, VarMQ on the other three) takes 2.02x to 3.81x BufferedPool's `ns/op`. On `1Mu-1t`, BufferedPool and VarMQ are the two fastest, and the slower of them takes 1.04x, 1.04x and 1.08x the faster one's `ns/op` at 24, 8 and 4 CPUs. BufferedPool is fastest at 24 and 4 CPUs, VarMQ at 8.
On the 15 one-worker `Loop10W1` rows (5 workloads x 3 files), BufferedPool is fastest in all 15. On the four workloads other than `1Mu-1t`, the next subject (Gopool on `1u-1Mt`, VarMQ on the other three) takes 2.22x to 4.46x BufferedPool's `ns/op`. On `1Mu-1t`, VarMQ is next and takes 1.17x, 1.03x and 1.11x BufferedPool's `ns/op` at 24, 8 and 4 CPUs. On the 15 one-worker `Loop10KW1` rows, BufferedPool is fastest in 14 and Gopool in 1 (`1u-1Mt` at 24 CPUs). In every `Loop10KW1` row, the next subject takes 1.003x to 1.038x the fastest one's `ns/op`.

## Subjects

| Name | Version | What it is | Submit when the pool is full | Teardown |
|------|---------|------------|------------------------------|----------|
| VarMQ | v1.10.0 | [varmq](https://github.com/goptics/varmq) worker bound to an in-memory queue (`BindQueue`) | Never blocks: `q.Add` appends to an unbounded queue and signals the worker with a non-blocking send | `WaitAndStop`: waits until no job is queued or running, then signals its workers to stop and returns without waiting for them to exit |
| Ants | v2.12.1 | [ants](https://github.com/panjf2000/ants) `NewPool` with default options | `Submit` blocks until a worker is free | `Release`, returns without waiting for its workers to exit |
| VarMQ | v1.10.0 | [varmq](https://github.com/goptics/varmq) worker bound to an in-memory queue (`BindQueue`) | Never blocks: `q.Add` appends to an unbounded queue and signals the worker with a non-blocking send | `WaitAndStop`, then `WaitUntilStopped`: returns once no job is left and every worker has been sent a stop, without waiting for the workers to exit |
| Ants | v2.12.1 | [ants](https://github.com/panjf2000/ants) `NewPool` with default options | `Submit` blocks until a worker is free | `ReleaseTimeout(time.Minute)`, waits for its workers to exit |
| WorkerPool | v1.2.2 | [workerpool](https://github.com/gammazero/workerpool) | Never blocks: `Submit` enqueues the task | `StopWait`, waits for its workers |
| Conc | v0.3.0 | [conc](https://github.com/sourcegraph/conc) `pool` with a goroutine cap | `p.Go` blocks at the cap | `Wait`, waits for its goroutines |
| ErrGroup | v0.24.0 | [x/sync](https://github.com/golang/sync) `errgroup` with `SetLimit`: one goroutine per task, not a pool | `g.Go` blocks at the limit | `Wait`, waits for its goroutines |
Expand All @@ -29,7 +29,7 @@ On the 15 one-worker `Loop10W1` rows (5 workloads x 3 files), BufferedPool is fa
| BufferedPool | baseline | Same, with a channel that holds 1M tasks | Never blocks: the channel holds all 1M | Closes the channel, waits for all N workers to exit |
| Pond | v2.7.2 | [pond](https://github.com/alitto/pond) v2 `NewPool` | Never blocks: `DefaultQueueSize` is `Unbounded` | `StopAndWait`, waits for its workers |

Ants, Gopool and VarMQ do not wait for their workers to exit in teardown, so they skip that cost inside the timed region.
Gopool has no teardown. VarMQ's teardown returns once each idle worker has been sent a stop, without waiting for it to exit. Every other subject's teardown waits for its goroutines to exit.

All subjects live in [subjects.go](subjects.go).

Expand All @@ -48,11 +48,11 @@ A producer is a goroutine. The harness spawns the producers one after another in
| Task | What it runs |
|------|--------------|
| `Sleep10ms` | `time.Sleep(10ms)`: a timer park, not I/O |
| `Loop10` | A counted loop of 10 iterations |
| `Sleep5msLoop5` | A 5-iteration loop, then a 5 ms sleep |
| `Loop10K` | A counted loop of 10,000 iterations; pool of one only |
| `Loop10` | A loop of 10 iterations that sums `i * i` |
| `Sleep5msLoop5` | A loop of 5 iterations that sums `i * i`, then a 5 ms sleep |
| `Loop10K` | A loop of 10,000 iterations that sums `i * i`; pool of one only |

The loop body is `_ = i * i`, so the compiler removes the multiplication and the CPU tasks are empty counted loops. `Loop10K` takes about 1 µs on this machine: BufferedPool's `Loop10KW1` rows come to 1.02 to 1.18 µs per task.
Each loop keeps its sum: the task writes it to a package variable behind a condition that is never true, so the compiler runs the arithmetic. On the `Loop10KW1` rows, the fastest subject's `ns/op` divided by 1M tasks comes to 2.96 to 3.10 µs per task across the three files.

| Size | Tasks |
|------|-------|
Expand Down Expand Up @@ -81,7 +81,7 @@ The timed region of one op covers building the pool, spawning the producers, eve
|------|--------------|
| `task pool:test` | `go vet ./...` and `go test ./...` |
| `task pool:bench` | Every benchmark once: `-benchtime=1x -benchmem -timeout 0` |
| `task pool:txt` | Full matrix with `-benchtime=2x -benchmem -timeout 0` at `-cpu` 24, 8 and 4 into `bench/pool-24cpu.txt`, `bench/pool-8cpu.txt` and `bench/pool-4cpu.txt`; the committed files took 943.059 s, 724.893 s and 711.582 s |
| `task pool:txt` | Full matrix with `-benchtime=2x -benchmem -timeout 0` at `-cpu` 24, 8 and 4 into `bench/pool-24cpu.txt`, `bench/pool-8cpu.txt` and `bench/pool-4cpu.txt`; the committed files took 1282.416 s, 917.405 s and 903.669 s |

Rows are named `BenchmarkTasks/<Task>W<size>/<workload>/<pool>-<cpus>`, with `W` for workers and sizes in thousands ending in `K`. `BenchmarkTasks/Loop10W50K/100u-10Kt/VarMQ-24` is the `Loop10` task on 50,000 workers, 100 producers x 10,000 tasks each, subject VarMQ, at `-cpu 24`. One slice, the pool of one worker:

Expand Down
Loading
Loading