From f504db34730a2eefb2b773e714c7b38574d311d5 Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 00:36:26 +0600 Subject: [PATCH 1/9] feat(sqlite): race sqliteq against goqite, backlite and River Every subject opens SQLite with sqliteq's connection settings (WAL, synchronous NORMAL, 5 s busy timeout) and the row's wal_autocheckpoint; pool size and everything else follow each library's own defaults and documentation. Rows are now /ckpt/, so the compared library sits on the x axis like the pool and redis charts. Co-Authored-By: Claude Fable 5.1 --- sqlite/Taskfile.yml | 13 ++- sqlite/backlite.go | 146 ++++++++++++++++++++++++ sqlite/benchmark_test.go | 18 +-- sqlite/db.go | 64 +++++++++++ sqlite/go.mod | 16 +++ sqlite/go.sum | 79 +++++++++++-- sqlite/goqite.go | 118 ++++++++++++++++++++ sqlite/harness_test.go | 234 +++++---------------------------------- sqlite/river.go | 124 +++++++++++++++++++++ sqlite/store.go | 45 -------- sqlite/subjects.go | 114 +++++++++++++++++++ sqlite/subjects_test.go | 71 ++++++++++++ sqlite/varmq.go | 227 +++++++++++++++++++++++++++++++++++++ 13 files changed, 1000 insertions(+), 269 deletions(-) create mode 100644 sqlite/backlite.go create mode 100644 sqlite/db.go create mode 100644 sqlite/goqite.go create mode 100644 sqlite/river.go delete mode 100644 sqlite/store.go create mode 100644 sqlite/subjects.go create mode 100644 sqlite/subjects_test.go create mode 100644 sqlite/varmq.go diff --git a/sqlite/Taskfile.yml b/sqlite/Taskfile.yml index 1b1df72..36062ed 100644 --- a/sqlite/Taskfile.yml +++ b/sqlite/Taskfile.yml @@ -1,16 +1,19 @@ version: "3" + tasks: test: - desc: Vet and compile (needs a C compiler) + desc: Vet and run every subject through a small job set (needs a C compiler) cmds: - go vet ./... - go test ./... + bench: - desc: Every scenario once + desc: Every scenario and subject once cmds: - - go test -run xxx -bench . -benchtime=1x -timeout 60m + - go test -run xxx -bench . -benchtime=1x -timeout 0 + txt: - desc: Full run into bench/sqlite.txt (real disk; SQLITEQ_BENCH_DIR picks it) + desc: Full run into bench/sqlite.txt (real disk; SQLITEQ_BENCH_DIR picks it; about 30 min) cmds: - mkdir -p bench - - set -o pipefail; go test -run xxx -bench . -benchtime=2x -timeout 60m | tee bench/sqlite.txt + - set -o pipefail; go test -run xxx -bench . -benchtime=2x -timeout 0 | tee bench/sqlite.txt diff --git a/sqlite/backlite.go b/sqlite/backlite.go new file mode 100644 index 0000000..c6eac31 --- /dev/null +++ b/sqlite/backlite.go @@ -0,0 +1,146 @@ +package sqlite + +import ( + "context" + "database/sql" + "path/filepath" + "sync/atomic" + "testing" + "time" + + "github.com/mikestefanello/backlite" +) + +// backlite reads a queue's name from the zero value of its task type, so every +// scenario queue needs a task type of its own: backliteTask[qN]. +type qname interface{ name() string } + +type ( + q0 struct{} + q1 struct{} + q2 struct{} + q3 struct{} + q4 struct{} + q5 struct{} + q6 struct{} + q7 struct{} + q8 struct{} + q9 struct{} +) + +func (q0) name() string { return "q0" } +func (q1) name() string { return "q1" } +func (q2) name() string { return "q2" } +func (q3) name() string { return "q3" } +func (q4) name() string { return "q4" } +func (q5) name() string { return "q5" } +func (q6) name() string { return "q6" } +func (q7) name() string { return "q7" } +func (q8) name() string { return "q8" } +func (q9) name() string { return "q9" } + +type backliteTask[Q qname] struct { + N int +} + +func (backliteTask[Q]) Config() backlite.QueueConfig { + var q Q + + return backlite.QueueConfig{Name: q.name()} +} + +// backliteQueue builds the queue for one task type and the function that +// makes its tasks. +func backliteQueue[Q qname](ran *atomic.Int64) (backlite.Queue, func(int) backlite.Task) { + q := backlite.NewQueue[backliteTask[Q]](func(context.Context, backliteTask[Q]) error { + ran.Add(1) + + return nil + }) + + return q, func(i int) backlite.Task { return backliteTask[Q]{N: i} } +} + +// ponytail: ten task types for the ten-queue scenario; add a type to go wider. +var backliteQueues = []func(*atomic.Int64) (backlite.Queue, func(int) backlite.Task){ + backliteQueue[q0], backliteQueue[q1], backliteQueue[q2], backliteQueue[q3], backliteQueue[q4], + backliteQueue[q5], backliteQueue[q6], backliteQueue[q7], backliteQueue[q8], backliteQueue[q9], +} + +type backliteConsumer struct { + db *sql.DB + client *backlite.Client + tasks []func(int) backlite.Task + ran *atomic.Int64 + total int + started bool +} + +// openBacklite makes one backlite client with 16 workers per scenario queue +// and one registered queue per scenario queue, all in one database file. +func openBacklite(tb testing.TB, dir string, sc scenario, ckpt int, ran *atomic.Int64) consumer { + tb.Helper() + + if sc.queues > len(backliteQueues) { + tb.Fatalf("backlite: %d queues, task types for %d", sc.queues, len(backliteQueues)) + } + + db := openDB(tb, filepath.Join(dir, "bench.db"), ckpt) + + client, err := backlite.NewClient(backlite.ClientConfig{ + DB: db, + NumWorkers: 16 * sc.queues, + ReleaseAfter: 10 * time.Minute, // required; requeues a claimed task after this, far beyond one run + }) + if err != nil { + tb.Fatalf("backlite: %v", err) + } + + if err := client.Install(); err != nil { + tb.Fatalf("backlite schema: %v", err) + } + + c := &backliteConsumer{db: db, client: client, ran: ran, total: sc.total} + + for i := range sc.queues { + q, mk := backliteQueues[i](ran) + client.Register(q) + c.tasks = append(c.tasks, mk) + } + + return c +} + +func (c *backliteConsumer) add(q, i int) bool { + _, err := c.client.Add(c.tasks[q](i)).Save() + + return err == nil +} + +func (c *backliteConsumer) start() error { + c.client.Start(context.Background()) + c.started = true + + return nil +} + +func (c *backliteConsumer) wait(deadline time.Duration) error { + return waitHandled(c.ran, c.total, c.leftover, deadline) +} + +// leftover counts pending and claimed tasks; without retention a completed +// task is deleted. +func (c *backliteConsumer) leftover() (int, error) { + return count(c.db, `SELECT COUNT(*) FROM backlite_tasks`) +} + +func (c *backliteConsumer) close() error { + if c.started { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + c.client.Stop(ctx) + } + + return c.db.Close() +} diff --git a/sqlite/benchmark_test.go b/sqlite/benchmark_test.go index 34df535..ee84364 100644 --- a/sqlite/benchmark_test.go +++ b/sqlite/benchmark_test.go @@ -8,16 +8,20 @@ import ( // checkpoints are the WAL checkpoint page counts every row runs at. var checkpoints = []int{1000, 10000} -// BenchmarkSQLite enqueues and drains jobs through a varmq worker bound to a -// sqliteq queue. Names are //ckpt. +// BenchmarkSQLite enqueues and drains jobs through every subject. Names are +// /ckpt/. func BenchmarkSQLite(b *testing.B) { for _, sc := range scenarios { b.Run(sc.name, func(b *testing.B) { - for _, l := range sc.layouts { - b.Run(l.String(), func(b *testing.B) { - for _, ckpt := range checkpoints { - b.Run(fmt.Sprintf("ckpt%d", ckpt), func(b *testing.B) { - runScenario(b, sc, l, ckpt) + for _, ckpt := range checkpoints { + b.Run(fmt.Sprintf("ckpt%d", ckpt), func(b *testing.B) { + for _, subj := range subjects { + if !subj.runs(sc) { + continue + } + + b.Run(subj.name, func(b *testing.B) { + runScenario(b, sc, subj, ckpt) }) } }) diff --git a/sqlite/db.go b/sqlite/db.go new file mode 100644 index 0000000..5e6b5b2 --- /dev/null +++ b/sqlite/db.go @@ -0,0 +1,64 @@ +package sqlite + +import ( + "database/sql" + "fmt" + "sync" + "testing" + + "github.com/mattn/go-sqlite3" +) + +// dsn carries sqliteq's connection settings, so every subject pays the same +// journal, fsync and lock-wait costs and the chart compares queue code. +func dsn(path string) string { + return path + "?_journal_mode=WAL&_synchronous=NORMAL&_busy_timeout=5000" +} + +var ( + driversMu sync.Mutex + drivers = map[int]bool{} +) + +// driverName registers, once per checkpoint size, a sqlite3 driver whose +// connections start with PRAGMA wal_autocheckpoint, as sqliteq does for its own. +func driverName(ckpt int) string { + name := fmt.Sprintf("bench_sqlite3_ckpt%d", ckpt) + + driversMu.Lock() + defer driversMu.Unlock() + + if !drivers[ckpt] { + pragma := fmt.Sprintf("PRAGMA wal_autocheckpoint=%d", ckpt) + sql.Register(name, &sqlite3.SQLiteDriver{ + ConnectHook: func(c *sqlite3.SQLiteConn) error { + _, err := c.Exec(pragma, nil) + + return err + }, + }) + drivers[ckpt] = true + } + + return name +} + +// openDB opens the database file at path for a rival subject. +func openDB(tb testing.TB, path string, ckpt int) *sql.DB { + tb.Helper() + + db, err := sql.Open(driverName(ckpt), dsn(path)) + if err != nil { + tb.Fatalf("open %s: %v", path, err) + } + + return db +} + +// count runs a COUNT(*) query. +func count(db *sql.DB, query string) (int, error) { + var n int + err := db.QueryRow(query).Scan(&n) + + return n, err +} diff --git a/sqlite/go.mod b/sqlite/go.mod index 744b5e3..613bada 100644 --- a/sqlite/go.mod +++ b/sqlite/go.mod @@ -6,6 +6,22 @@ require ( github.com/goptics/sqliteq v0.3.0 github.com/goptics/varmq v1.9.0 github.com/mattn/go-sqlite3 v1.14.28 + github.com/mikestefanello/backlite v0.8.0 + github.com/riverqueue/river v0.49.0 + github.com/riverqueue/river/riverdriver/riversqlite v0.49.0 + maragu.dev/goqite v0.4.0 +) + +require ( + github.com/google/uuid v1.6.0 // indirect + github.com/riverqueue/river/riverdriver v0.49.0 // indirect + github.com/riverqueue/river/rivershared v0.49.0 // indirect + github.com/riverqueue/river/rivertype v0.49.0 // indirect + github.com/tidwall/gjson v1.19.0 // indirect + github.com/tidwall/match v1.2.0 // indirect + github.com/tidwall/pretty v1.2.1 // indirect + github.com/tidwall/sjson v1.2.5 // indirect + golang.org/x/sync v0.23.0 // indirect ) replace github.com/goptics/varmq => ../../varmq diff --git a/sqlite/go.sum b/sqlite/go.sum index 19ef01b..454bc6a 100644 --- a/sqlite/go.sum +++ b/sqlite/go.sum @@ -1,12 +1,75 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/goptics/sqliteq v0.3.0 h1:5Jff3AqiEt2Em41QK83tBalqNCF64vrBJY1JdWRkfog= github.com/goptics/sqliteq v0.3.0/go.mod h1:9FFuDJnO3iC5ToSBDxJGCeds5VORAYgX0xBEZznqgV4= +github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438 h1:Dj0L5fhJ9F82ZJyVOmBx6msDp/kfd1t9GRfny/mfJA0= +github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.11.0 h1:IzBBtyK9AHqf98cctWFifYSci2hgQR/cd56wB4p+ogg= +github.com/jackc/pgx/v5 v5.11.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A= github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +github.com/mikestefanello/backlite v0.8.0 h1:k+kLlVI0ng0Ooj9iimo1cJB0Vj3TbG8yBYxGzoKNyNM= +github.com/mikestefanello/backlite v0.8.0/go.mod h1:3dpRu8KHcxiWmSdY6n1HklF/0QAvxCJdE8hYIeyKsvI= +github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= +github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/riverqueue/river v0.49.0 h1:JUCLFgregbX1Wu+bSTHCjF/WHGdrwGbtz/ddInHfeb0= +github.com/riverqueue/river v0.49.0/go.mod h1:USYb57gpMBXLQm2l7poskAalOPaf5uHjSZgp2AOoYDw= +github.com/riverqueue/river/riverdriver v0.49.0 h1:kSykNQJNB7AeG6kudjB0mThV29PvykoOBIFT8ipCHEc= +github.com/riverqueue/river/riverdriver v0.49.0/go.mod h1:rVUuX/fTF2kAiJjpPT+10Lft8n90kvLqjm6b+rFXaVE= +github.com/riverqueue/river/riverdriver/riverpgxv5 v0.49.0 h1:c7YA1plP/nrNS3SEHuKizf4wHx9OQ87Yxuhj3V0eQ50= +github.com/riverqueue/river/riverdriver/riverpgxv5 v0.49.0/go.mod h1:o7zkFstM+Fk+mnlOW2sx92mQW4JswSc6zvN191l8Isg= +github.com/riverqueue/river/riverdriver/riversqlite v0.49.0 h1:DfATYWIuQ4bKjhhqj/XYn3ZGpluXqG0VAZfk+voL558= +github.com/riverqueue/river/riverdriver/riversqlite v0.49.0/go.mod h1:sOSH7dNsGt2UWLFUk7Cy9qNRNkRTswFrTwYf+TJkpeg= +github.com/riverqueue/river/rivershared v0.49.0 h1:wnCYVwftMiu85kT1JrUPKEgujKkBIWoRtSNZJTUtotY= +github.com/riverqueue/river/rivershared v0.49.0/go.mod h1:E8UzQAdDutFT8rVL1wZeNbuphmIS81TgngU7/1F4U5E= +github.com/riverqueue/river/rivertype v0.49.0 h1:3up3P2DtOqnM2yEYSC1xeK9AjrljOtIfl10yZlaF4aM= +github.com/riverqueue/river/rivertype v0.49.0/go.mod h1:XKkcRQR6zm8RR/JQa1Q2ywpj8uXQu21quPa4Lpw1Xhw= +github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= +github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.19.0 h1:xwxm7n691Uf3u5OFjzngavjGTh55KX5q/9w9xHW88JU= +github.com/tidwall/gjson v1.19.0/go.mod h1:V37/opeE/JbLUOfH0QTXiNez2l0RUjYUhpT4szFQAfc= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/match v1.2.0 h1:0pt8FlkOwjN2fPt4bIl4BoNxb98gGHN2ObFEDkrfZnM= +github.com/tidwall/match v1.2.0/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= +golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk= +golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= +golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= +golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= +golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= +maragu.dev/goqite v0.4.0 h1:x4UT5qxfI/Gz2NWpMEunN0HZ/gyMJdY551rc4BGuR9I= +maragu.dev/goqite v0.4.0/go.mod h1:UVHAW44gJFtP2nucAO7R2NBzveM6HrJO97CAa12uuVc= +maragu.dev/is v0.3.0 h1:A2B6ylehcHJw7gQqzgwDMWMkS6jmhaBu8s6fy+RG6yA= +maragu.dev/is v0.3.0/go.mod h1:bviaM5S0fBshCw7wuumFGTju/izopZ/Yvq4g7Klc7y8= +modernc.org/libc v1.74.1 h1:bdR4VTKFMC4966QSNZ05XLGI/VwzVa2kTUX51Dm0riQ= +modernc.org/libc v1.74.1/go.mod h1:uH4t5bOx3G3g9Xcmj10YKlTcVISlRDwv8VoQJG9n8Os= +modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= +modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= +modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI= +modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= +modernc.org/sqlite v1.54.0 h1:JCxR4qwkJvOaqAoYcgDoO25Nc+ROg6EJ2LfBVzdrgog= +modernc.org/sqlite v1.54.0/go.mod h1:4ntCLuNmnH8+GNqjka1wNg7KJd5/Hi5FYp8K+XQ7GZw= diff --git a/sqlite/goqite.go b/sqlite/goqite.go new file mode 100644 index 0000000..954407b --- /dev/null +++ b/sqlite/goqite.go @@ -0,0 +1,118 @@ +package sqlite + +import ( + "context" + "database/sql" + "fmt" + "path/filepath" + "strconv" + "sync" + "sync/atomic" + "testing" + "time" + + "maragu.dev/goqite" + "maragu.dev/goqite/jobs" +) + +// goqiteSchema is schema_sqlite.sql from maragu.dev/goqite v0.4.0 (MIT): the +// module ships it as a file, not as Go code. +const goqiteSchema = ` +create table goqite ( + id text primary key default ('m_' || lower(hex(randomblob(16)))), + created text not null default (strftime('%Y-%m-%dT%H:%M:%fZ')), + updated text not null default (strftime('%Y-%m-%dT%H:%M:%fZ')), + queue text not null, + body blob not null, + timeout text not null default (strftime('%Y-%m-%dT%H:%M:%fZ')), + received integer not null default 0, + priority integer not null default 0 +) strict; + +create trigger goqite_updated_timestamp after update on goqite begin + update goqite set updated = strftime('%Y-%m-%dT%H:%M:%fZ') where id = old.id; +end; + +create index goqite_queue_priority_created_idx on goqite (queue, priority desc, created); +` + +type goqiteConsumer struct { + db *sql.DB + queues []*goqite.Queue + runners []*jobs.Runner + prio bool + ran *atomic.Int64 + total int + cancel context.CancelFunc + stopped sync.WaitGroup +} + +// openGoqite makes one goqite queue and one job runner (16 jobs at a time, +// the default 100 ms poll) per scenario queue, all in one database file. +func openGoqite(tb testing.TB, dir string, sc scenario, ckpt int, ran *atomic.Int64) consumer { + tb.Helper() + + db := openDB(tb, filepath.Join(dir, "bench.db"), ckpt) + // goqite's README setup: one connection, since SQLite allows one writer at a time + db.SetMaxOpenConns(1) + db.SetMaxIdleConns(1) + + if _, err := db.Exec(goqiteSchema); err != nil { + tb.Fatalf("goqite schema: %v", err) + } + + c := &goqiteConsumer{db: db, prio: sc.priority, ran: ran, total: sc.total} + + for i := range sc.queues { + q := goqite.New(goqite.NewOpts{DB: db, Name: fmt.Sprintf("q%d", i)}) + r := jobs.NewRunner(jobs.NewRunnerOpts{Limit: 16, Queue: q}) + r.Register("bench", func(context.Context, []byte) error { + ran.Add(1) + + return nil + }) + + c.queues = append(c.queues, q) + c.runners = append(c.runners, r) + } + + return c +} + +func (c *goqiteConsumer) add(q, i int) bool { + m := goqite.Message{Body: strconv.AppendInt(nil, int64(i), 10)} + if c.prio { + m.Priority = i % 4 // higher first + } + + _, err := jobs.Create(context.Background(), c.queues[q], "bench", m) + + return err == nil +} + +func (c *goqiteConsumer) start() error { + ctx, cancel := context.WithCancel(context.Background()) + c.cancel = cancel + + for _, r := range c.runners { + c.stopped.Go(func() { r.Start(ctx) }) + } + + return nil +} + +func (c *goqiteConsumer) wait(deadline time.Duration) error { + return waitHandled(c.ran, c.total, c.leftover, deadline) +} + +// leftover counts messages; the runner deletes a message after its job returns. +func (c *goqiteConsumer) leftover() (int, error) { return count(c.db, `SELECT COUNT(*) FROM goqite`) } + +func (c *goqiteConsumer) close() error { + if c.cancel != nil { + c.cancel() + c.stopped.Wait() + } + + return c.db.Close() +} diff --git a/sqlite/harness_test.go b/sqlite/harness_test.go index 89acf6c..789b716 100644 --- a/sqlite/harness_test.go +++ b/sqlite/harness_test.go @@ -1,40 +1,19 @@ package sqlite import ( - "database/sql" - "fmt" "os" "path/filepath" "sync" "sync/atomic" "testing" "time" - - "github.com/goptics/sqliteq" - "github.com/goptics/varmq" - _ "github.com/mattn/go-sqlite3" ) -// scenario is one row of the benchmark matrix. -type scenario struct { - name string - queues int - producers int // per queue - total int // jobs over all queues - drain bool // pause the worker, add everything, then time the drain - priority bool - layouts []layout -} - -func (sc scenario) perProducer() int { return sc.total / sc.queues / sc.producers } - var scenarios = []scenario{ - {name: "Mixed1Q", queues: 1, producers: 4, total: 20000, layouts: []layout{singleFile}}, - {name: "Drain1Q", queues: 1, producers: 4, total: 20000, drain: true, layouts: []layout{singleFile}}, - {name: "DrainPrio", queues: 1, producers: 4, total: 10000, drain: true, priority: true, layouts: []layout{singleFile}}, - // SingleFile first: vizb orders chart series by the first layout seen in - // the whole file, and the one-queue scenarios only have SingleFile. - {name: "Mixed10Q", queues: 10, producers: 1, total: 20000, layouts: []layout{singleFile, folder}}, + {name: "Mixed1Q", queues: 1, producers: 4, total: 20000}, + {name: "Drain1Q", queues: 1, producers: 4, total: 20000, drain: true}, + {name: "DrainPrio", queues: 1, producers: 4, total: 10000, drain: true, priority: true}, + {name: "Mixed10Q", queues: 10, producers: 1, total: 20000}, } // benchRoot is where the benchmark databases live. They must be on a real disk: @@ -73,55 +52,23 @@ func freshDir(tb testing.TB) string { return dir } -// waitDeadline bounds how long one iteration waits for its workers to drain, +// waitDeadline bounds how long one iteration waits for its consumer to drain, // so a stuck job fails its row instead of hanging the whole run. const waitDeadline = 5 * time.Minute -// bound is one queue with its worker. -type bound struct { - worker varmq.Worker - add func(i int) bool // enqueues job number i -} - -func bind(tb testing.TB, qs sqliteq.Queues, sc scenario, name string, ran *atomic.Int64) bound { - tb.Helper() - - w := varmq.NewWorker(func(varmq.Job[int]) { ran.Add(1) }, varmq.WithConcurrency(16)) - - if sc.priority { - q, err := qs.NewPriorityQueue(name) - if err != nil { - tb.Fatal(err) - } - - pq := w.WithPersistentPriorityQueue(q) - - return bound{worker: pq.Worker(), add: func(i int) bool { return pq.Add(i, i%4) }} - } - - q, err := qs.NewQueue(name) - if err != nil { - tb.Fatal(err) - } - - pq := w.WithPersistentQueue(q) - - return bound{worker: pq.Worker(), add: func(i int) bool { return pq.Add(i) }} -} - // runScenario runs sc b.N times, each on a fresh database, and reports jobs/s // over the timed part only: setup, teardown and the leftover check are not -// timed. Mixed times the first Add to Wait. Drain times Resume to Wait. It -// also reports walMB, the largest size any one -wal file reached in any -// iteration, untimed parts included. -func runScenario(b *testing.B, sc scenario, l layout, ckpt int) { +// timed. Mixed times the first add to the last job handled. Drain times the +// consumer start to the last job handled. It also reports walMB, the largest +// size any one -wal file reached in any iteration, untimed parts included. +func runScenario(b *testing.B, sc scenario, subj subject, ckpt int) { b.Helper() var walPeak int64 for range b.N { b.StopTimer() - walPeak = max(walPeak, runOnce(b, sc, l, ckpt)) + walPeak = max(walPeak, runOnce(b, sc, subj, ckpt)) } if sec := b.Elapsed().Seconds(); sec > 0 { @@ -181,84 +128,39 @@ func sampleWAL(dir string) (stop func() int64) { } // runOnce runs one iteration and returns its WAL peak in bytes. -func runOnce(b *testing.B, sc scenario, l layout, ckpt int) int64 { +func runOnce(b *testing.B, sc scenario, subj subject, ckpt int) int64 { b.Helper() dir := freshDir(b) - path := dir - if l == singleFile { - path = filepath.Join(dir, "bench.db") - } + var ran atomic.Int64 // handler runs over all queues - qs := openStore(b, path, l, ckpt) + c := subj.open(b, dir, sc, ckpt, &ran) stopWAL := sampleWAL(dir) defer stopWAL() // a failed iteration still stops the sampler - var ran atomic.Int64 // handler runs over all queues - - bounds := make([]bound, sc.queues) - for i := range bounds { - bounds[i] = bind(b, qs, sc, fmt.Sprintf("q%d", i), &ran) - - if sc.drain { - if err := bounds[i].worker.Pause(); err != nil { - b.Fatalf("pause: %v", err) - } - } - } - - var ( - wg sync.WaitGroup - failed atomic.Int64 - ) - - produce := func() { - for _, bd := range bounds { - for p := range sc.producers { - wg.Go(func() { - for j := range sc.perProducer() { - if !bd.add(p*sc.perProducer() + j) { - failed.Add(1) - } - } - }) - } - } - - wg.Wait() - } + var failed int64 if sc.drain { - produce() + failed = produce(c, sc) b.StartTimer() - for _, bd := range bounds { - if err := bd.worker.Resume(); err != nil { - b.Fatalf("resume: %v", err) - } + if err := c.start(); err != nil { + b.Fatalf("start: %v", err) } } else { + if err := c.start(); err != nil { + b.Fatalf("start: %v", err) + } + b.StartTimer() - produce() + failed = produce(c, sc) } - waited := make(chan struct{}) - - go func() { - defer close(waited) - - for _, bd := range bounds { - bd.worker.Wait() - } - }() - - select { - case <-waited: - case <-time.After(waitDeadline): + if err := c.wait(waitDeadline); err != nil { b.StopTimer() - b.Fatalf("%s: workers still busy %s after the last Add: a job is stuck", sc.name, waitDeadline) + b.Fatalf("%s: %v: a job is stuck", sc.name, err) } b.StopTimer() @@ -267,98 +169,22 @@ func runOnce(b *testing.B, sc scenario, l layout, ckpt int) int64 { b.Fatalf("%s: handler ran %d times, want %d: a job was lost or run twice", sc.name, n, sc.total) } - if n := failed.Load(); n > 0 { - b.Fatalf("%d Add calls returned false", n) + if failed > 0 { + b.Fatalf("%d adds failed", failed) } - if left, err := rowsLeft(path, l, sc.queues); err != nil { + if left, err := c.leftover(); err != nil { b.Fatalf("count leftover rows: %v", err) } else if left > 0 { - b.Fatalf("%d rows left in the queue tables after Wait", left) - } - - for _, bd := range bounds { - if err := bd.worker.WaitAndStop(); err != nil { - b.Fatalf("stop: %v", err) - } + b.Fatalf("%d rows left in the queue tables", left) } // Closing checkpoints and removes the WAL, so the sampling stops first walPeak := stopWAL() - if err := qs.Close(); err != nil { - b.Fatalf("close store: %v", err) + if err := c.close(); err != nil { + b.Fatalf("close: %v", err) } return walPeak } - -// rowsLeft counts the rows in every table of the store's database files, read -// with database/sql directly. It fails when it finds fewer than queues tables, -// so a check that looked at nothing cannot pass. -func rowsLeft(path string, l layout, queues int) (rows int, err error) { - files := []string{path} - - if l == folder { - if files, err = filepath.Glob(filepath.Join(path, "*.db")); err != nil { - return 0, err - } - } - - tables := 0 - - for _, f := range files { - db, err := sql.Open("sqlite3", f) - if err != nil { - return 0, err - } - - names, err := tableNames(db) - if err != nil { - db.Close() - - return 0, err - } - - for _, t := range names { - var n int - if err := db.QueryRow(`SELECT COUNT(*) FROM "` + t + `"`).Scan(&n); err != nil { - db.Close() - - return 0, err - } - - rows += n - tables++ - } - - db.Close() - } - - if tables < queues { - return 0, fmt.Errorf("found %d queue tables, want at least %d", tables, queues) - } - - return rows, nil -} - -func tableNames(db *sql.DB) ([]string, error) { - r, err := db.Query(`SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'`) - if err != nil { - return nil, err - } - defer r.Close() - - var names []string - - for r.Next() { - var n string - if err := r.Scan(&n); err != nil { - return nil, err - } - - names = append(names, n) - } - - return names, r.Err() -} diff --git a/sqlite/river.go b/sqlite/river.go new file mode 100644 index 0000000..28a7c6c --- /dev/null +++ b/sqlite/river.go @@ -0,0 +1,124 @@ +package sqlite + +import ( + "context" + "database/sql" + "fmt" + "log/slog" + "path/filepath" + "sync/atomic" + "testing" + "time" + + "github.com/riverqueue/river" + "github.com/riverqueue/river/riverdriver/riversqlite" + "github.com/riverqueue/river/rivermigrate" +) + +type riverArgs struct { + N int `json:"n"` +} + +func (riverArgs) Kind() string { return "bench" } + +type riverWorker struct { + river.WorkerDefaults[riverArgs] + ran *atomic.Int64 +} + +func (w *riverWorker) Work(context.Context, *river.Job[riverArgs]) error { + w.ran.Add(1) + + return nil +} + +type riverConsumer struct { + db *sql.DB + client *river.Client[*sql.Tx] + prio bool + ran *atomic.Int64 + total int + started bool +} + +// openRiver migrates a fresh database and makes one River client with a +// 16-worker queue per scenario queue. +func openRiver(tb testing.TB, dir string, sc scenario, ckpt int, ran *atomic.Int64) consumer { + tb.Helper() + + db := openDB(tb, filepath.Join(dir, "bench.db"), ckpt) + // riversqlite's package doc: one connection, so River's parallel internal + // operations do not fail with SQLITE_BUSY + db.SetMaxOpenConns(1) + + driver := riversqlite.New(db) + ctx := context.Background() + + migrator, err := rivermigrate.New(driver, nil) + if err != nil { + tb.Fatalf("river migrator: %v", err) + } + + if _, err := migrator.Migrate(ctx, rivermigrate.DirectionUp, nil); err != nil { + tb.Fatalf("river migrate: %v", err) + } + + workers := river.NewWorkers() + river.AddWorker(workers, &riverWorker{ran: ran}) + + queues := make(map[string]river.QueueConfig, sc.queues) + for i := range sc.queues { + queues[fmt.Sprintf("q%d", i)] = river.QueueConfig{MaxWorkers: 16} + } + + client, err := river.NewClient(driver, &river.Config{ + Logger: slog.New(slog.DiscardHandler), + Queues: queues, + Workers: workers, + }) + if err != nil { + tb.Fatalf("river client: %v", err) + } + + return &riverConsumer{db: db, client: client, prio: sc.priority, ran: ran, total: sc.total} +} + +func (c *riverConsumer) add(q, i int) bool { + opts := &river.InsertOpts{Queue: fmt.Sprintf("q%d", q)} + if c.prio { + opts.Priority = i%4 + 1 // 1 is River's highest + } + + _, err := c.client.Insert(context.Background(), riverArgs{N: i}, opts) + + return err == nil +} + +func (c *riverConsumer) start() error { + c.started = true + + return c.client.Start(context.Background()) +} + +func (c *riverConsumer) wait(deadline time.Duration) error { + return waitHandled(c.ran, c.total, c.leftover, deadline) +} + +// leftover counts jobs not yet completed; River keeps completed rows in +// river_job for 24 hours by default. +func (c *riverConsumer) leftover() (int, error) { + return count(c.db, `SELECT COUNT(*) FROM river_job WHERE state <> 'completed'`) +} + +func (c *riverConsumer) close() error { + if c.started { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + if err := c.client.Stop(ctx); err != nil { + return err + } + } + + return c.db.Close() +} diff --git a/sqlite/store.go b/sqlite/store.go deleted file mode 100644 index 842a93b..0000000 --- a/sqlite/store.go +++ /dev/null @@ -1,45 +0,0 @@ -// Package sqlite benchmarks sqliteq, the SQLite storage adapter, end to end -// through a varmq worker. -package sqlite - -import ( - "testing" - - "github.com/goptics/sqliteq" -) - -// layout is how queues map onto database files. -type layout int - -const ( - // folder is one database file per queue, all in the directory path. - folder layout = iota - // singleFile is every queue in the one database file path. - singleFile -) - -func (l layout) String() string { - if l == folder { - return "Folder" - } - - return "SingleFile" -} - -// openStore opens one sqliteq database set at path with the given WAL -// checkpoint page count. -func openStore(tb testing.TB, path string, l layout, ckpt int) sqliteq.Queues { - tb.Helper() - - opts := []sqliteq.StoreOption{sqliteq.WithCheckpointPages(ckpt)} - if l == singleFile { - opts = append(opts, sqliteq.WithSingleFile()) - } - - qs, err := sqliteq.New(path, opts...) - if err != nil { - tb.Fatalf("sqliteq.New(%s): %v", path, err) - } - - return qs -} diff --git a/sqlite/subjects.go b/sqlite/subjects.go new file mode 100644 index 0000000..01181b5 --- /dev/null +++ b/sqlite/subjects.go @@ -0,0 +1,114 @@ +// Package sqlite benchmarks SQLite-backed job queues end to end: sqliteq +// through a varmq worker against goqite, backlite and River's SQLite driver. +package sqlite + +import ( + "fmt" + "sync" + "sync/atomic" + "testing" + "time" +) + +// scenario is one group of the benchmark matrix. +type scenario struct { + name string + queues int + producers int // per queue + total int // jobs over all queues + drain bool // fill everything first, then time the consumer from start to empty + priority bool // job i gets priority i%4; only subjects with a priority queue run it +} + +func (sc scenario) perProducer() int { return sc.total / sc.queues / sc.producers } + +// consumer is one subject bound to a scenario's queues on a fresh database. +// Every subject's handler only counts: ran.Add(1). +type consumer interface { + add(queue, i int) bool // enqueue job i on queue + start() error // begin consuming: after filling on drain scenarios, before on mixed + wait(deadline time.Duration) error // until every job is handled and acknowledged + leftover() (int, error) // rows still in the queue tables + close() error +} + +type subject struct { + name string + priority bool // has a priority queue, so it runs DrainPrio + only10Q bool // identical to another subject with one queue, so it runs only with more + open func(tb testing.TB, dir string, sc scenario, ckpt int, ran *atomic.Int64) consumer +} + +// subjects in chart order: vizb lays out the x axis by first appearance. +var subjects = []subject{ + {name: "VarMQ", priority: true, open: openVarMQ(folder)}, + {name: "VarMQSingleFile", only10Q: true, open: openVarMQ(singleFile)}, + {name: "Goqite", priority: true, open: openGoqite}, + {name: "Backlite", open: openBacklite}, + {name: "River", priority: true, open: openRiver}, +} + +func (s subject) runs(sc scenario) bool { + return (!sc.priority || s.priority) && (!s.only10Q || sc.queues > 1) +} + +// produce runs sc.producers goroutines per queue, each adding perProducer +// jobs, and returns how many adds failed. +func produce(c consumer, sc scenario) int64 { + var ( + wg sync.WaitGroup + failed atomic.Int64 + ) + + for q := range sc.queues { + for p := range sc.producers { + wg.Go(func() { + for j := range sc.perProducer() { + if !c.add(q, p*sc.perProducer()+j) { + failed.Add(1) + } + } + }) + } + } + + wg.Wait() + + return failed.Load() +} + +// waitHandled is wait for the subjects without a Wait of their own: first +// until the handler ran total times, then until the last acknowledgement +// cleared the queue table, all within deadline. +func waitHandled(ran *atomic.Int64, total int, leftover func() (int, error), deadline time.Duration) error { + timeout := time.NewTimer(deadline) + defer timeout.Stop() + + tick := time.NewTicker(time.Millisecond) + defer tick.Stop() + + for ran.Load() < int64(total) { + select { + case <-tick.C: + case <-timeout.C: + return fmt.Errorf("%d of %d jobs handled after %s", ran.Load(), total, deadline) + } + } + + for { + n, err := leftover() + if err != nil { + return err + } + + if n == 0 { + return nil + } + + select { + case <-tick.C: + case <-timeout.C: + return fmt.Errorf("%d rows still queued %s after the last job", n, deadline) + } + } +} diff --git a/sqlite/subjects_test.go b/sqlite/subjects_test.go new file mode 100644 index 0000000..e01ec4b --- /dev/null +++ b/sqlite/subjects_test.go @@ -0,0 +1,71 @@ +package sqlite + +import ( + "sync/atomic" + "testing" + "time" +) + +// TestSubjects runs every subject through small mixed, drain, priority and +// two-queue runs and checks that every job is handled exactly once and +// nothing is left in the queue tables. +func TestSubjects(t *testing.T) { + cases := []scenario{ + {name: "Mixed", queues: 1, producers: 2, total: 200}, + {name: "Drain", queues: 1, producers: 2, total: 200, drain: true}, + {name: "DrainPrio", queues: 1, producers: 2, total: 200, drain: true, priority: true}, + {name: "Mixed2Q", queues: 2, producers: 1, total: 200}, + } + + for _, subj := range subjects { + for _, sc := range cases { + if !subj.runs(sc) { + continue + } + + t.Run(subj.name+"/"+sc.name, func(t *testing.T) { + var ran atomic.Int64 + + c := subj.open(t, t.TempDir(), sc, 1000, &ran) + + var failed int64 + + if sc.drain { + failed = produce(c, sc) + + if err := c.start(); err != nil { + t.Fatal(err) + } + } else { + if err := c.start(); err != nil { + t.Fatal(err) + } + + failed = produce(c, sc) + } + + if err := c.wait(time.Minute); err != nil { + t.Fatal(err) + } + + if n := ran.Load(); n != int64(sc.total) { + t.Fatalf("handler ran %d times, want %d", n, sc.total) + } + + if failed > 0 { + t.Fatalf("%d adds failed", failed) + } + + if left, err := c.leftover(); err != nil { + t.Fatal(err) + } else if left > 0 { + t.Fatalf("%d rows left in the queue tables", left) + } + + if err := c.close(); err != nil { + t.Fatal(err) + } + }) + } + } +} diff --git a/sqlite/varmq.go b/sqlite/varmq.go new file mode 100644 index 0000000..b1c01e2 --- /dev/null +++ b/sqlite/varmq.go @@ -0,0 +1,227 @@ +package sqlite + +import ( + "database/sql" + "fmt" + "path/filepath" + "sync/atomic" + "testing" + "time" + + "github.com/goptics/sqliteq" + "github.com/goptics/varmq" +) + +// layout is how sqliteq maps queues onto database files. +type layout int + +const ( + // folder is one database file per queue, all in the directory path: sqliteq's default. + folder layout = iota + // singleFile is every queue in the one database file path. + singleFile +) + +// openStore opens one sqliteq database set at path with the given WAL +// checkpoint page count. +func openStore(tb testing.TB, path string, l layout, ckpt int) sqliteq.Queues { + tb.Helper() + + opts := []sqliteq.StoreOption{sqliteq.WithCheckpointPages(ckpt)} + if l == singleFile { + opts = append(opts, sqliteq.WithSingleFile()) + } + + qs, err := sqliteq.New(path, opts...) + if err != nil { + tb.Fatalf("sqliteq.New(%s): %v", path, err) + } + + return qs +} + +// bound is one queue with its worker. +type bound struct { + worker varmq.Worker + add func(i int) bool // enqueues job number i +} + +func bind(tb testing.TB, qs sqliteq.Queues, sc scenario, name string, ran *atomic.Int64) bound { + tb.Helper() + + w := varmq.NewWorker(func(varmq.Job[int]) { ran.Add(1) }, varmq.WithConcurrency(16)) + + if sc.priority { + q, err := qs.NewPriorityQueue(name) + if err != nil { + tb.Fatal(err) + } + + pq := w.WithPersistentPriorityQueue(q) + + return bound{worker: pq.Worker(), add: func(i int) bool { return pq.Add(i, i%4) }} + } + + q, err := qs.NewQueue(name) + if err != nil { + tb.Fatal(err) + } + + pq := w.WithPersistentQueue(q) + + return bound{worker: pq.Worker(), add: func(i int) bool { return pq.Add(i) }} +} + +type varmqConsumer struct { + qs sqliteq.Queues + bounds []bound + path string + l layout + drain bool +} + +func openVarMQ(l layout) func(testing.TB, string, scenario, int, *atomic.Int64) consumer { + return func(tb testing.TB, dir string, sc scenario, ckpt int, ran *atomic.Int64) consumer { + tb.Helper() + + path := dir + if l == singleFile { + path = filepath.Join(dir, "bench.db") + } + + c := &varmqConsumer{qs: openStore(tb, path, l, ckpt), path: path, l: l, drain: sc.drain} + + for i := range sc.queues { + bd := bind(tb, c.qs, sc, fmt.Sprintf("q%d", i), ran) + + if sc.drain { + if err := bd.worker.Pause(); err != nil { + tb.Fatalf("pause: %v", err) + } + } + + c.bounds = append(c.bounds, bd) + } + + return c + } +} + +func (c *varmqConsumer) add(q, i int) bool { return c.bounds[q].add(i) } + +// start resumes the paused workers of a drain run; otherwise they have been +// running since NewWorker. +func (c *varmqConsumer) start() error { + if !c.drain { + return nil + } + + for _, bd := range c.bounds { + if err := bd.worker.Resume(); err != nil { + return err + } + } + + return nil +} + +func (c *varmqConsumer) wait(deadline time.Duration) error { + waited := make(chan struct{}) + + go func() { + defer close(waited) + + for _, bd := range c.bounds { + bd.worker.Wait() + } + }() + + select { + case <-waited: + return nil + case <-time.After(deadline): + return fmt.Errorf("workers still busy %s after the last add", deadline) + } +} + +func (c *varmqConsumer) leftover() (int, error) { return rowsLeft(c.path, c.l, len(c.bounds)) } + +func (c *varmqConsumer) close() error { + for _, bd := range c.bounds { + if err := bd.worker.WaitAndStop(); err != nil { + return err + } + } + + return c.qs.Close() +} + +// rowsLeft counts the rows in every table of the store's database files, read +// with database/sql directly. It fails when it finds fewer than queues tables, +// so a check that looked at nothing cannot pass. +func rowsLeft(path string, l layout, queues int) (rows int, err error) { + files := []string{path} + + if l == folder { + if files, err = filepath.Glob(filepath.Join(path, "*.db")); err != nil { + return 0, err + } + } + + tables := 0 + + for _, f := range files { + db, err := sql.Open("sqlite3", f) + if err != nil { + return 0, err + } + + names, err := tableNames(db) + if err != nil { + db.Close() + + return 0, err + } + + for _, t := range names { + var n int + if err := db.QueryRow(`SELECT COUNT(*) FROM "` + t + `"`).Scan(&n); err != nil { + db.Close() + + return 0, err + } + + rows += n + tables++ + } + + db.Close() + } + + if tables < queues { + return 0, fmt.Errorf("found %d queue tables, want at least %d", tables, queues) + } + + return rows, nil +} + +func tableNames(db *sql.DB) ([]string, error) { + r, err := db.Query(`SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'`) + if err != nil { + return nil, err + } + defer r.Close() + + var names []string + + for r.Next() { + var n string + if err := r.Scan(&n); err != nil { + return nil, err + } + + names = append(names, n) + } + + return names, r.Err() +} From 3b67206d284694bff54e1a3457ec7f749823b310 Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 01:05:31 +0600 Subject: [PATCH 2/9] fix(sqlite): run River at its minimum fetch cooldown The default 100 ms FetchCooldown caps 16 workers at 160 jobs/s whatever SQLite does (measured 159 at both checkpoint sizes). At the 1 ms minimum the row is bound by SQLite and River's own per-job work. Listed as the suite's one forced setting. Co-Authored-By: Claude Fable 5.1 --- sqlite/river.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sqlite/river.go b/sqlite/river.go index 28a7c6c..0428bb8 100644 --- a/sqlite/river.go +++ b/sqlite/river.go @@ -72,9 +72,14 @@ func openRiver(tb testing.TB, dir string, sc scenario, ckpt int, ran *atomic.Int } client, err := river.NewClient(driver, &river.Config{ - Logger: slog.New(slog.DiscardHandler), - Queues: queues, - Workers: workers, + // Forced: River fetches at most MaxWorkers jobs, then waits FetchCooldown + // before the next fetch, so the default 100 ms caps 16 workers at 160 + // jobs/s whatever the database does. The 1 ms minimum lets SQLite and + // River's own per-job work set the number instead. + FetchCooldown: river.FetchCooldownMin, + Logger: slog.New(slog.DiscardHandler), + Queues: queues, + Workers: workers, }) if err != nil { tb.Fatalf("river client: %v", err) From 20d4d4315d78862f523f360da27a7e779666715d Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 01:06:38 +0600 Subject: [PATCH 3/9] fix(redis): poll rmq every 1 ms instead of the example's 100 ms rmq sleeps pollDuration after every fetch pass, fetched or empty, so the example value capped one connection near prefetch / 0.1 s: the first run measured 5.9k to 10.3k jobs/s at C1, on the cap, and a 102 ms pickup latency that was the timer. rmq has no default for the setting; at 1 ms the pass's own round trips set the number. Co-Authored-By: Claude Fable 5.1 --- redis/rmq.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/redis/rmq.go b/redis/rmq.go index 9695400..9eb22b3 100644 --- a/redis/rmq.go +++ b/redis/rmq.go @@ -8,11 +8,15 @@ import ( const ( rmqQueue = "bench" - // rmq has no default for either setting. Both come from rmq v5.2.0's - // example/consumer/main.go (prefetchLimit 1000, pollDuration 100ms). The - // prefetch is raised to 2*workers when that is larger, because rmq's README - // says the prefetch limit should always exceed the consumer count. - rmqPollDuration = 100 * time.Millisecond + // rmq has no default for either setting. The prefetch comes from rmq + // v5.2.0's example/consumer/main.go (prefetchLimit 1000), raised to + // 2*workers when that is larger, because rmq's README says the prefetch + // limit should always exceed the consumer count. The example's 100 ms + // pollDuration is not used: consume sleeps it after every pass, fetched or + // empty, which capped one connection near prefetch / 0.1 s (about 10,000 + // jobs/s; the first run measured 5.9k to 10.3k at C1). At 1 ms the pass's + // own round trips set the number. + rmqPollDuration = time.Millisecond rmqMinPrefetch = 1000 ) From adec9c92f7af6462ac928765782eed74918ec228 Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 01:28:29 +0600 Subject: [PATCH 4/9] feat(sqlite): full run with goqite, backlite and River, 2026-10-25 32 rows, -benchtime=2x, varmq 415ad73 through the replace directive, sqliteq v0.3.0, goqite v0.4.0, backlite v0.8.0, River v0.49.0 at a 1 ms fetch cooldown, ext4 over NVMe. Co-Authored-By: Claude Fable 5.1 --- sqlite/bench/sqlite.txt | 44 ++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/sqlite/bench/sqlite.txt b/sqlite/bench/sqlite.txt index 98985ad..8a34e6e 100644 --- a/sqlite/bench/sqlite.txt +++ b/sqlite/bench/sqlite.txt @@ -2,15 +2,37 @@ goos: linux goarch: amd64 pkg: github.com/goptics/benchmarks/sqlite cpu: 13th Gen Intel(R) Core(TM) i7-13700 -BenchmarkSQLite/Mixed1Q/SingleFile/ckpt1000-24 2 3039747602 ns/op 6579 jobs/s 4.161 walMB -BenchmarkSQLite/Mixed1Q/SingleFile/ckpt10000-24 2 2074583028 ns/op 9640 jobs/s 41.22 walMB -BenchmarkSQLite/Drain1Q/SingleFile/ckpt1000-24 2 1613315062 ns/op 12397 jobs/s 4.157 walMB -BenchmarkSQLite/Drain1Q/SingleFile/ckpt10000-24 2 1137877831 ns/op 17577 jobs/s 41.22 walMB -BenchmarkSQLite/DrainPrio/SingleFile/ckpt1000-24 2 906832514 ns/op 11027 jobs/s 4.153 walMB -BenchmarkSQLite/DrainPrio/SingleFile/ckpt10000-24 2 591091365 ns/op 16918 jobs/s 41.21 walMB -BenchmarkSQLite/Mixed10Q/SingleFile/ckpt1000-24 2 4662094013 ns/op 4290 jobs/s 4.231 walMB -BenchmarkSQLite/Mixed10Q/SingleFile/ckpt10000-24 2 2304644819 ns/op 8678 jobs/s 41.31 walMB -BenchmarkSQLite/Mixed10Q/Folder/ckpt1000-24 2 882018262 ns/op 22675 jobs/s 4.145 walMB -BenchmarkSQLite/Mixed10Q/Folder/ckpt10000-24 2 572491534 ns/op 34935 jobs/s 39.43 walMB +BenchmarkSQLite/Mixed1Q/ckpt1000/VarMQ-24 2 3192392801 ns/op 6265 jobs/s 4.153 walMB +BenchmarkSQLite/Mixed1Q/ckpt1000/Goqite-24 2 9849167800 ns/op 2031 jobs/s 4.145 walMB +BenchmarkSQLite/Mixed1Q/ckpt1000/Backlite-24 2 74830086386 ns/op 267.3 jobs/s 200.2 walMB +BenchmarkSQLite/Mixed1Q/ckpt1000/River-24 2 15362132646 ns/op 1302 jobs/s 4.211 walMB +BenchmarkSQLite/Mixed1Q/ckpt10000/VarMQ-24 2 1607840522 ns/op 12439 jobs/s 41.22 walMB +BenchmarkSQLite/Mixed1Q/ckpt10000/Goqite-24 2 5197534856 ns/op 3848 jobs/s 41.22 walMB +BenchmarkSQLite/Mixed1Q/ckpt10000/Backlite-24 2 130632159101 ns/op 153.1 jobs/s 140.2 walMB +BenchmarkSQLite/Mixed1Q/ckpt10000/River-24 2 8317833819 ns/op 2404 jobs/s 41.27 walMB +BenchmarkSQLite/Drain1Q/ckpt1000/VarMQ-24 2 1317111602 ns/op 15185 jobs/s 4.153 walMB +BenchmarkSQLite/Drain1Q/ckpt1000/Goqite-24 2 7263340616 ns/op 2754 jobs/s 4.149 walMB +BenchmarkSQLite/Drain1Q/ckpt1000/Backlite-24 2 17531593564 ns/op 1141 jobs/s 179.8 walMB +BenchmarkSQLite/Drain1Q/ckpt1000/River-24 2 6375015794 ns/op 3137 jobs/s 4.256 walMB +BenchmarkSQLite/Drain1Q/ckpt10000/VarMQ-24 2 813634553 ns/op 24581 jobs/s 41.22 walMB +BenchmarkSQLite/Drain1Q/ckpt10000/Goqite-24 2 4936705099 ns/op 4051 jobs/s 41.22 walMB +BenchmarkSQLite/Drain1Q/ckpt10000/Backlite-24 2 13402619364 ns/op 1492 jobs/s 152.5 walMB +BenchmarkSQLite/Drain1Q/ckpt10000/River-24 2 5448609552 ns/op 3671 jobs/s 41.40 walMB +BenchmarkSQLite/DrainPrio/ckpt1000/VarMQ-24 2 734529722 ns/op 13614 jobs/s 4.153 walMB +BenchmarkSQLite/DrainPrio/ckpt1000/Goqite-24 2 3472367467 ns/op 2880 jobs/s 4.149 walMB +BenchmarkSQLite/DrainPrio/ckpt1000/River-24 2 3225075666 ns/op 3101 jobs/s 4.544 walMB +BenchmarkSQLite/DrainPrio/ckpt10000/VarMQ-24 2 486231908 ns/op 20566 jobs/s 41.21 walMB +BenchmarkSQLite/DrainPrio/ckpt10000/Goqite-24 2 2524238889 ns/op 3962 jobs/s 41.22 walMB +BenchmarkSQLite/DrainPrio/ckpt10000/River-24 2 2813890148 ns/op 3554 jobs/s 41.39 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/VarMQ-24 2 654451480 ns/op 30560 jobs/s 4.132 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/VarMQSingleFile-24 2 4499681254 ns/op 4445 jobs/s 4.240 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/Goqite-24 2 9295114232 ns/op 2152 jobs/s 4.141 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/Backlite-24 2 4112004616 ns/op 4864 jobs/s 367.9 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/River-24 2 30302010174 ns/op 660.0 jobs/s 4.310 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/VarMQ-24 2 192812872 ns/op 103728 jobs/s 39.28 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/VarMQSingleFile-24 2 1781507324 ns/op 11226 jobs/s 41.32 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/Goqite-24 2 4495456860 ns/op 4449 jobs/s 41.22 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/Backlite-24 2 3729655254 ns/op 5362 jobs/s 369.9 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/River-24 2 18103584976 ns/op 1105 jobs/s 41.26 walMB PASS -ok github.com/goptics/benchmarks/sqlite 66.554s +ok github.com/goptics/benchmarks/sqlite 1272.094s From 934a9df59edec0fc7d00a82a8d9e4d29df2e7b13 Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 01:29:32 +0600 Subject: [PATCH 5/9] docs: READMEs in benchmark-repo shape, five datasets, new names Root, pool, redis and sqlite READMEs cut to results, subjects with versions, matrix, running. The redis per-library source notes move to redis/NOTES.md; site and deploy detail to worker/README.md. The site builds five datasets: Worker Pool (24/8/4 CPUs), Message Queue Redis (C1 and C4 groups together) and Message Queue SQLite. The redis README's numbers are from the 2026-10-24 run until the rerun lands. Co-Authored-By: Claude Fable 5.1 --- LICENSE | 1 + README.md | 151 +++------- Taskfile.yml | 33 +-- pool/README.md | 156 +++------- redis/NOTES.md | 570 ++++++++++++++++++++++++++++++++++++ redis/README.md | 741 +++++------------------------------------------ sqlite/README.md | 134 ++++----- worker/README.md | 15 + 8 files changed, 821 insertions(+), 980 deletions(-) create mode 100644 redis/NOTES.md create mode 100644 worker/README.md diff --git a/LICENSE b/LICENSE index ce727b5..68f3d59 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ MIT License +Copyright (c) 2026 goptics Copyright (c) 2022 Alejandro Durante Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/README.md b/README.md index 21a2c8c..fd7c547 100644 --- a/README.md +++ b/README.md @@ -1,131 +1,64 @@ # VarMQ Benchmarks -[![Benchmark Charts](https://img.shields.io/badge/%F0%9F%93%8A-Live_Charts-blue?style=for-the-badge)](https://benchmarks.goptics.org) +[![Live charts](https://img.shields.io/badge/%F0%9F%93%8A-Live_Charts-blue?style=for-the-badge)](https://benchmarks.goptics.org) -How fast is [VarMQ](https://github.com/goptics/varmq) compared to other Go worker pools and job queues, and under which conditions? - -This repo answers that with three benchmark suites, fixed workloads, and one live chart site at . - -## Vision - -Benchmark numbers in library READMEs are easy to cherry-pick. We wanted the opposite: - -- **One harness per suite, many subjects.** Every subject in a suite is driven by the exact same code path. -- **Realistic shapes, not a single number.** A pool that shines with one producer and a million tasks can fall apart with a million producers submitting one task each. We test both ends and the middle. -- **Overhead in isolation.** With tens or hundreds of thousands of workers a slow pool can hide behind parallelism. A pool of one worker takes that cover away and shows what each pool costs per task. -- **Reproducible and public.** Raw `go test -bench` output is committed to each suite's `bench/` directory. The site is built from those files, so anyone can see the data behind every bar. -- **Honest baselines.** In the pool suite, alongside real libraries, we include two hand-rolled channel pools. If a library cannot beat a `for task := range ch` loop, that is worth knowing. +Benchmark suites for [VarMQ](https://github.com/goptics/varmq) against other Go worker pools and message queues. Raw `go test -bench` output is committed under `/bench/`; the charts at are built from those files. ## Suites -| Suite | Module | What is raced | Datasets | README | -|-------|--------|---------------|----------|--------| -| Pool | `pool/` | VarMQ and eight other in-process worker pools | [24 CPUs](https://benchmarks.goptics.org/?id=pool-24cpu), [8 CPUs](https://benchmarks.goptics.org/?id=pool-8cpu), [4 CPUs](https://benchmarks.goptics.org/?id=pool-4cpu) | [pool/README.md](pool/README.md) | -| Redis | `redis/` | VarMQ on Redis against Asynq, rmq, taskq and gocraft/work | [Persistent](https://benchmarks.goptics.org/?id=redis-persistent), [Distributed](https://benchmarks.goptics.org/?id=redis-distributed) | [redis/README.md](redis/README.md) | -| Sqlite | `sqlite/` | sqliteq driven through a VarMQ worker | [Persistent](https://benchmarks.goptics.org/?id=sqlite-persistent) | [sqlite/README.md](sqlite/README.md) | - -**Pool.** Nine subjects (VarMQ, Pond, Ants, WorkerPool, Conc, ErrGroup, Gopool and two channel baselines) run the same five workload shapes of 1M tasks, at three pool sizes plus a single worker. The same matrix is recorded at 24, 8 and 4 CPUs, one dataset each. - -**Redis.** VarMQ's Redis queue (redisq) is raced against Asynq, rmq, taskq and gocraft/work with real consumer processes. The Persistent dataset uses one consumer process and also carries enqueue-only and pickup-latency rows. The Distributed dataset uses four consumer processes. - -**Sqlite.** sqliteq, the SQLite-backed persistent queue, through a VarMQ worker: one queue, drain, priority and ten queues, with a WAL checkpoint of 1000 and 10000 pages. It has its own module because it needs cgo. - -## How results get published - -1. `/bench/*.txt` is raw `go test -bench` output, committed from the reference machine. Benchmarks never run in CI. -2. `task site:build` converts each file to a dataset JSON with [vizb](https://github.com/goptics/vizb), writes a catalog, and builds one HTML page, all under `worker/public/`. -3. CI installs vizb through the [vizb action](https://github.com/goptics/vizb), which also writes the page, runs `task site:json` for the datasets, and then `wrangler deploy`. Pull requests build only; the deploy runs on pushes and manual runs on `main`. The workflow is [.github/workflows/site.yml](.github/workflows/site.yml). -4. A small Cloudflare Worker ([worker/](worker/)) serves the page and the datasets from Workers Static Assets at `benchmarks.goptics.org`. - -| URL | Serves | -|-----|--------| -| `/` | The dashboard with the dataset switcher. Loads the catalog, then the first dataset | -| `/?id=` | The same dashboard with one dataset selected, for example `/?id=redis-persistent` | -| `/` | A single dataset with no switcher | -| `/dataset` | The catalog, `[{id, name}]` in dashboard order | -| `/dataset/` | One dataset as JSON | +| Suite | Compares | Charts | Details | +|-------|----------|--------|---------| +| Worker pool | VarMQ vs Pond, Ants, WorkerPool, Conc, ErrGroup, Gopool and two channel baselines | [24](https://benchmarks.goptics.org/?id=pool-24cpu), [8](https://benchmarks.goptics.org/?id=pool-8cpu), [4 CPUs](https://benchmarks.goptics.org/?id=pool-4cpu) | [pool/README.md](pool/README.md) | +| Message queue, Redis | VarMQ (redisq) vs Asynq, rmq, taskq, gocraft/work, with one and four consumer processes | [redis](https://benchmarks.goptics.org/?id=redis) | [redis/README.md](redis/README.md) | +| Message queue, SQLite | VarMQ (sqliteq) vs goqite, backlite, River, at WAL checkpoint 1000 and 10000 pages | [sqlite](https://benchmarks.goptics.org/?id=sqlite) | [sqlite/README.md](sqlite/README.md) | -The dataset ids are `pool-24cpu`, `pool-8cpu`, `pool-4cpu`, `redis-persistent`, `redis-distributed` and `sqlite-persistent`. Only the latest run of each is kept. +## Results -Deploying needs two GitHub secrets: +Pool and Redis runs of 2026-10-24, SQLite run of 2026-10-25, all `-benchtime=2x`. Full tables in the suite READMEs. -- `CLOUDFLARE_API_TOKEN` with Workers Scripts: Edit, plus Zone goptics.org: DNS Edit and Workers Routes Edit for the custom domain. -- `CLOUDFLARE_ACCOUNT_ID`. +- Pool: VarMQ is the fastest subject in 40, 36 and 20 of the 55 rows at 24, 8 and 4 CPUs. It is slower than the buffered-channel baseline on the one-worker `Loop10` rows. +- Redis: with the `Noop` task, VarMQ is first in 2 of the 6 one-process rows and VarMQDistributed in 3 of the 6 four-process rows, every win with 100 producers; gocraft/work leads the single-producer rows. Pickup latency p50: taskq 0.063 ms, VarMQ 0.142 ms, rmq 102.2 ms, Asynq 995.3 ms. +- SQLite: VarMQ (sqliteq) is first in all 16 rows: on `Mixed1Q` at ckpt1000 it runs 3.1x goqite, 4.8x River and 23x backlite, and ten queues in separate files reach 103,728 jobs/s at ckpt10000. -## Running it yourself +## Environment -Requires Go 1.26+, [Task](https://taskfile.dev), [vizb](https://github.com/goptics/vizb) and `jq`. Redis suite: Docker. Sqlite suite: a C compiler. `task site:dev`: Node. +Intel Core i7-13700 (24 threads), linux/amd64, Go 1.26.2. Pool suite at GOMAXPROCS 24, 8 and 4. Redis 7.2 (Debian image) pinned to CPU 14, client on the other cores. SQLite databases on ext4 over NVMe. -```bash -# every task, per suite and for the site -task --list -``` +| Library | Version | +|---------|---------| +| varmq | 415ad73 (unreleased, `replace` in each go.mod) | +| redisq | v1.5.0 | +| sqliteq | v0.3.0 | +| pond | v2.7.2 | +| ants | v2.12.1 | +| workerpool | v1.2.2 | +| conc | v0.3.0 | +| x/sync (errgroup) | v0.24.0 | +| bytedance/gopkg (gopool) | v0.1.4 | +| asynq | v0.26.0 | +| rmq | v5.2.0 | +| taskq | v3.2.9 | +| gocraft/work | v0.5.1 | +| goqite | v0.4.0 | +| backlite | v0.8.0 | +| river | v0.49.0 | -```bash -# one iteration of every pool benchmark -task pool:bench -``` +## Running -```bash -# one iteration of every Redis benchmark (starts Redis on localhost:6390 first) -task redis:up redis:bench -# stop it afterwards with task redis:down -``` +Needs Go 1.26+ and [Task](https://taskfile.dev); Docker for the Redis suite; a C compiler for the SQLite suite; [vizb](https://github.com/goptics/vizb) and `jq` for `task site:preview`. ```bash -# one iteration of every sqlite scenario +task --list # every task +task pool:bench # one iteration of every pool benchmark +task redis:up redis:bench redis:down task sqlite:bench +task pool:txt # full run into pool/bench/ (hours); also redis:txt, sqlite:txt +task report # every suite, then the local preview +task site:preview # all datasets in one local HTML ``` -```bash -# build all six datasets from bench/*.txt into one HTML, no Worker -task site:preview -``` - -```bash -# build against localhost:8787 and run the Worker with wrangler dev -task site:dev -``` - -```bash -# regenerate every bench/*.txt (hours), then open the local preview -task report -``` - -To run a slice, call `go test` inside the suite's module: - -```bash -# pool: Loop10 task, 50K workers, 100 producers, only the baselines -cd pool && go test -run xxx -bench 'Tasks/Loop10W50K/100u-10Kt/(GoroutinePool|BufferedPool)$' -benchtime=1x -``` - -```bash -# pool: only the pool of one worker, every task, workload and subject (about 40 s) -cd pool && go test -run xxx -bench 'Tasks/W1$' -benchtime=1x -``` - -```bash -# redis: one Durable cell, needs task redis:up -cd redis && go test -run xxx -bench 'Durable/NoopW10C1' -benchtime=1x -timeout 0 -``` - -```bash -# sqlite: one scenario -cd sqlite && go test -run xxx -bench 'SQLite/Mixed10Q' -benchtime=1x -``` - -## Layout - -| Path | Purpose | -|------|---------| -| `pool/` | Pool suite: its own Go module, `bench/pool-{24,8,4}cpu.txt`, Taskfile and README | -| `redis/` | Redis suite: its own Go module, `compose.yml`, `bench/redis.txt`, Taskfile and README | -| `sqlite/` | Sqlite suite: its own Go module, `bench/sqlite.txt`, Taskfile and README | -| `worker/` | Cloudflare Worker (`worker.js`, `wrangler.jsonc`). `worker/public/` is build output and gitignored | -| `dist/` | Local preview from `task site:preview`. Gitignored | -| `Taskfile.yml` | Includes the three suite Taskfiles, plus `site:*`, `report` and `clean` | -| `.github/workflows/site.yml` | Site build and deploy | +Each suite README shows how to run one slice with `go test -bench`. Pushes to `main` rebuild and deploy the charts; see [worker/README.md](worker/README.md). ## License -MIT. See [LICENSE](LICENSE). +MIT, see [LICENSE](LICENSE). The pool harness started from [alitto/pond-benchmarks](https://github.com/alitto/pond-benchmarks). diff --git a/Taskfile.yml b/Taskfile.yml index 92e06cf..e27303d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -10,13 +10,13 @@ vars: DATA: worker/public/data DATA_URL: https://benchmarks.goptics.org/dataset BAR: vizb bar -p /n/y/x -T s -M MB --round -l --border-radius 8,8,0,0 - # keep in step with redis/subjects.go: a subject missing here is dropped from redis-persistent + # C1, Enqueue and Latency groups race VarMQ's persistent queue against these; + # VarMQDistributed only appears in the C4 groups. Keep in step with redis/subjects.go. SUBJECTS: '(VarMQ|Asynq|Rmq|Taskq|GocraftWork)' # catalog order = dashboard order; listed literally (a glob sorts 4cpu before 24cpu) JSONS: >- worker/public/data/pool-24cpu.json worker/public/data/pool-8cpu.json worker/public/data/pool-4cpu.json - worker/public/data/redis-persistent.json worker/public/data/redis-distributed.json - worker/public/data/sqlite-persistent.json + worker/public/data/redis.json worker/public/data/sqlite.json tasks: default: @@ -27,24 +27,19 @@ tasks: desc: Convert every bench txt to dataset JSON plus the catalog cmds: - rm -rf {{.DATA}} && mkdir -p {{.DATA}} - - '{{.BAR}} --stack pool/bench/pool-24cpu.txt -n "Pool (24 CPUs)" --id pool-24cpu -d "9 Go worker pools, 5 workload shapes, 1M tasks, GOMAXPROCS 24" -o {{.DATA}}/pool-24cpu.json' - - '{{.BAR}} --stack pool/bench/pool-8cpu.txt -n "Pool (8 CPUs)" --id pool-8cpu -d "Same matrix at GOMAXPROCS 8" -o {{.DATA}}/pool-8cpu.json' - - '{{.BAR}} --stack pool/bench/pool-4cpu.txt -n "Pool (4 CPUs)" --id pool-4cpu -d "Same matrix at GOMAXPROCS 4" -o {{.DATA}}/pool-4cpu.json' + - '{{.BAR}} --stack pool/bench/pool-24cpu.txt -n "Worker Pool (24 CPUs)" --id pool-24cpu -d "9 Go worker pools, 5 workload shapes, 1M tasks, GOMAXPROCS 24" -o {{.DATA}}/pool-24cpu.json' + - '{{.BAR}} --stack pool/bench/pool-8cpu.txt -n "Worker Pool (8 CPUs)" --id pool-8cpu -d "Same matrix at GOMAXPROCS 8" -o {{.DATA}}/pool-8cpu.json' + - '{{.BAR}} --stack pool/bench/pool-4cpu.txt -n "Worker Pool (4 CPUs)" --id pool-4cpu -d "Same matrix at GOMAXPROCS 4" -o {{.DATA}}/pool-4cpu.json' - >- - {{.BAR}} --stack redis/bench/redis.txt -n "Redis (Persistent)" --id redis-persistent - -d "One consumer process: VarMQ persistent queue vs Asynq, rmq, taskq, gocraft/work; plus enqueue-only and pickup latency" - -f '^(Benchmark)?(Durable/[^/]+C1|Enqueue/Enqueue|Latency/[^/]+)/[^/]+/{{.SUBJECTS}}$' + {{.BAR}} --stack redis/bench/redis.txt -n "Message Queue Redis" --id redis + -d "VarMQ (redisq) vs Asynq, rmq, taskq, gocraft/work on Redis 7.2. C1 groups: one consumer process; C4: four. Plus enqueue-only and pickup latency" + -f '^(Benchmark)?((Durable/[^/]+C1|Enqueue/Enqueue|Latency/[^/]+)/[^/]+/{{.SUBJECTS}}$|Durable/[^/]+C4/)' --better p50-ms:low,p99-ms:low,max-ms:low - -o {{.DATA}}/redis-persistent.json + -o {{.DATA}}/redis.json - >- - {{.BAR}} --stack redis/bench/redis.txt -n "Redis (Distributed)" --id redis-distributed - -d "Four consumer processes: VarMQ distributed queue vs Asynq, rmq, taskq, gocraft/work" - -f '^(Benchmark)?Durable/[^/]+C4/' - -o {{.DATA}}/redis-distributed.json - - >- - {{.BAR}} --stack sqlite/bench/sqlite.txt -n "Sqlite (Persistent)" --id sqlite-persistent - -d "sqliteq through a VarMQ worker: one queue, drain, priority, ten queues; WAL checkpoint 1000 vs 10000 pages" - --better walMB:low -o {{.DATA}}/sqlite-persistent.json + {{.BAR}} --stack sqlite/bench/sqlite.txt -n "Message Queue SQLite" --id sqlite + -d "VarMQ (sqliteq) vs goqite, backlite, River on SQLite: one queue, drain, priority, ten queues; WAL checkpoint 1000 vs 10000 pages" + --better walMB:low -o {{.DATA}}/sqlite.json - jq -se 'all(.data | length > 0)' {{.JSONS}} - jq -s 'map({id, name})' {{.JSONS}} > {{.DATA}}/_catalog.json @@ -62,7 +57,7 @@ tasks: vars: { DATA_URL: '{{.DATA_URL}}' } site:preview: - desc: Same six datasets embedded in one HTML, no Worker + desc: Every dataset embedded in one HTML, no Worker cmds: - task: site:json - mkdir -p dist diff --git a/pool/README.md b/pool/README.md index 6cd4ad9..a7ca2de 100644 --- a/pool/README.md +++ b/pool/README.md @@ -1,139 +1,86 @@ -# Pool benchmarks +# Worker pool benchmarks -Nine Go worker pools driven by one harness across five workload shapes and four task types, 1M tasks per run. VarMQ is raced against Pond, Ants, WorkerPool, Conc, ErrGroup, Gopool and two hand-rolled channel baselines. +Nine in-process Go worker pools driven by one harness, 1M tasks per op, recorded at 24, 8 and 4 CPUs: [pool-24cpu](https://benchmarks.goptics.org/?id=pool-24cpu), [pool-8cpu](https://benchmarks.goptics.org/?id=pool-8cpu), [pool-4cpu](https://benchmarks.goptics.org/?id=pool-4cpu). -This module is `package main` with its own `go.mod`. Run everything from this directory, or from the repo root as `task pool:`. - -## Run - -| Task | What it does | -|------|--------------| -| `task pool:test` | `go vet` and `go test` | -| `task pool:bench` | Every benchmark once (`-benchtime=1x`) | -| `task pool:txt` | Full matrix at 24, 8 and 4 CPUs into `bench/pool-24cpu.txt`, `bench/pool-8cpu.txt` and `bench/pool-4cpu.txt` (hours) | - -One slice, for example the pool of one worker (about 40 s): - -```bash -go test -run xxx -bench 'Tasks/W1$' -benchtime=1x -``` - -Loop10 task, 50K workers, 100 producers, only the baselines: - -```bash -go test -run xxx -bench 'Tasks/Loop10W50K/100u-10Kt/(GoroutinePool|BufferedPool)$' -benchtime=1x -``` +## Results -One pool size, here 100K workers (also `W50K`, `W300K`): +Run of 2026-10-24, varmq 415ad73 (unreleased, `replace` in go.mod), `-benchtime=2x`, 495 rows per file. Each file has 55 task/size/workload rows (11 groups like `Loop10W50K` x 5 workloads); the table counts the rows in which each subject has the lowest `ns/op`, and no other subject is fastest in any row. -```bash -go test -run xxx -bench 'Tasks/W100K$' -benchtime=1x -``` +| CPUs | Rows | VarMQ | BufferedPool | ErrGroup | Ants | +|------|------|-------|--------------|----------|------| +| 24 | 55 | 40 | 13 | 2 | 0 | +| 8 | 55 | 36 | 13 | 6 | 0 | +| 4 | 55 | 20 | 20 | 11 | 4 | -## Results - -`bench/pool-24cpu.txt`, `pool-8cpu.txt` and `pool-4cpu.txt` are one run from -2026-10-24: varmq 415ad73 (unreleased, through the `replace` directive in -`go.mod`), `-benchtime=2x`, 495 rows each. Counting the fastest pool per row -over the 55 rows of each file (11 task and size groups x 5 workloads): VarMQ is -first in 40 rows at 24 CPUs, 36 at 8 and 20 at 4; BufferedPool takes 13, 13 -and 20; ErrGroup 2, 6 and 11; Ants 4 at 4 CPUs. The one-worker `Loop10W1` -rows are the consistent loss, where VarMQ runs at about a quarter of -BufferedPool: with no parallelism the hand-off cost is all there is. +On the five one-worker `Loop10W1` rows of each file, VarMQ's `ns/op` divided by BufferedPool's is 3.26x to 4.22x on the four workloads other than `1Mu-1t` (4.22x on `1u-1Mt` at 24 CPUs) and level on `1Mu-1t` (1.04x at 24 CPUs, 0.96x at 8, 1.08x at 4). ## Subjects -| Name | What it is | -|------|------------| -| **VarMQ** | [goptics/varmq](https://github.com/goptics/varmq), worker bound to a queue | -| **Pond** | [alitto/pond](https://github.com/alitto/pond) v2 | -| **Ants** | [panjf2000/ants](https://github.com/panjf2000/ants) v2 | -| **WorkerPool** | [gammazero/workerpool](https://github.com/gammazero/workerpool) | -| **Conc** | [sourcegraph/conc](https://github.com/sourcegraph/conc) `pool` with a goroutine cap | -| **ErrGroup** | [x/sync/errgroup](https://pkg.go.dev/golang.org/x/sync/errgroup) with `SetLimit`. Not a pool: a new goroutine per task behind a semaphore, the stdlib-adjacent default many projects reach for | -| **Gopool** | [bytedance/gopkg](https://github.com/bytedance/gopkg) `util/gopool`. Tasks go to an unbounded list, so `submit` never blocks; idle workers exit on their own. The worker cap is soft and can overshoot slightly under contention | -| **GoroutinePool** | N goroutines reading from an **unbuffered** channel. Baseline. | -| **BufferedPool** | Same, but the channel holds 1M tasks. Baseline. | +| Name | Version | What it is | +|------|---------|------------| +| VarMQ | 415ad73 (unreleased, `replace` in go.mod) | [goptics/varmq](https://github.com/goptics/varmq), worker bound to a queue | +| Pond | v2.7.2 | [alitto/pond/v2](https://github.com/alitto/pond) | +| Ants | v2.12.1 | [panjf2000/ants/v2](https://github.com/panjf2000/ants) | +| WorkerPool | v1.2.2 | [gammazero/workerpool](https://github.com/gammazero/workerpool) | +| Conc | v0.3.0 | [sourcegraph/conc](https://github.com/sourcegraph/conc) `pool` with a goroutine cap | +| ErrGroup | v0.24.0 | [x/sync/errgroup](https://pkg.go.dev/golang.org/x/sync/errgroup): one goroutine per task behind a semaphore, not a pool | +| Gopool | v0.1.4 | [bytedance/gopkg](https://github.com/bytedance/gopkg) `util/gopool`: submit never blocks; soft worker cap | +| GoroutinePool | baseline | N goroutines reading from an unbuffered channel | +| BufferedPool | baseline | Same, but the channel holds 1M tasks | All subjects live in [subjects.go](subjects.go). -## Dimensions - -Every subject is run across the full product of these axes, except that a pool of one worker runs only the CPU tasks (see **Pool size**): - -**Workload shape** (producers x tasks per producer, always 1M tasks total) +## Workloads -| Name | Producers | Tasks each | -|------|-----------|------------| +| Workload | Producers | Tasks each | +|----------|-----------|------------| | `1u-1Mt` | 1 | 1,000,000 | | `100u-10Kt` | 100 | 10,000 | | `1Ku-1Kt` | 1,000 | 1,000 | | `10Ku-100t` | 10,000 | 100 | | `1Mu-1t` | 1,000,000 | 1 | -**Task type** - -| Name | Behaviour | +| Task | Behaviour | |------|-----------| | `Sleep10ms` | I/O-like: sleep 10 ms | | `Loop10` | CPU-like: 10 iterations of trivial math | | `Sleep5msLoop5` | Mixed: 5 iterations then sleep 5 ms | | `Loop10K` | CPU-like: 10,000 iterations, about 1 µs. Pool of 1 only. | -**Pool size** - -| Size | Tasks | What it shows | -|------|-------|---------------| -| 50K workers | `Sleep10ms`, `Loop10`, `Sleep5msLoop5` | How the pool scales when work can run in parallel | -| 100K workers | `Sleep10ms`, `Loop10`, `Sleep5msLoop5` | The same, with twice the goroutines to spawn and schedule | -| 300K workers | `Sleep10ms`, `Loop10`, `Sleep5msLoop5` | The same, at six times the 50K size | -| 1 worker | `Loop10`, `Loop10K` | What each pool costs per task: submit, hand-off and wake-up, with no parallelism to hide it | +| Size | Tasks | +|------|-------| +| 50K workers | `Sleep10ms`, `Loop10`, `Sleep5msLoop5` | +| 100K workers | `Sleep10ms`, `Loop10`, `Sleep5msLoop5` | +| 300K workers | `Sleep10ms`, `Loop10`, `Sleep5msLoop5` | +| 1 worker | `Loop10`, `Loop10K` | -A pool of one runs no sleeping tasks: every pool would show the same `time.Sleep`, and one worker sleeping 10 ms per task needs almost three hours for 1M tasks. Sizes and their tasks live in `poolSizes` in [subjects.go](subjects.go). +W1 runs CPU tasks only, since one worker sleeping 10 ms per task would take about three hours for 1M tasks. -**CPU count**: results are recorded for the machine default (24 cores on the reference machine), 8 cores and 4 cores (`-cpu` flag). +The matrix is recorded at 24, 8 and 4 CPUs (`-cpu`), one dataset each. -## Benchmark names +## Method -Every row is named `BenchmarkTasks/W//`, where `W` stands for workers and sizes in thousands end in `K` (`W50K`, `W100K`, `W300K`, `W1`), in the same style as the workload names: - -| Row | Task | Pool size | Workload | Pool | -|-----|------|-----------|----------|------| -| `BenchmarkTasks/Loop10W50K/100u-10Kt/VarMQ` | `Loop10` | 50,000 workers | 100 producers x 10K tasks | VarMQ | -| `BenchmarkTasks/Sleep10msW300K/1Mu-1t/Pond` | `Sleep10ms` | 300,000 workers | 1M producers x 1 task | Pond | -| `BenchmarkTasks/Loop10KW1/1u-1Mt/Ants` | `Loop10K` | 1 worker | 1 producer x 1M tasks | Ants | - -## Metrics - -Each benchmark reports the standard Go numbers plus throughput: +A subject is a factory that, given `maxWorkers`, returns `submit` and `teardown`. Producers are goroutines: a `100u-10Kt` run starts 100 goroutines, each submitting 10,000 tasks. One op is build the pool, submit 1M tasks, wait for all to finish, tear down, with construction and shutdown inside the timed region. - `ns/op`: wall time to push all 1M tasks through the pool and drain it - `ops/s`: tasks completed per second (custom metric, higher is better) - `B/op` and `allocs/op`: memory cost -On a `W1` row there is no parallelism, so `ns/op` divided by 1,000,000 is the time per task: the task itself plus everything the pool adds to it. +## Running -## How it works +| Task | What it does | +|------|--------------| +| `task pool:test` | `go vet` and `go test` | +| `task pool:bench` | Every benchmark once (`-benchtime=1x`) | +| `task pool:txt` | Full matrix at 24, 8 and 4 CPUs into `bench/pool-24cpu.txt`, `bench/pool-8cpu.txt` and `bench/pool-4cpu.txt` (hours) | -``` -subjects.go types.go benchmark_test.go -┌──────────────┐ ┌──────────────┐ ┌──────────────────────────────┐ -│ VarMQ │ │ poolSubmit │ │ for each pool size │ -│ Pond │ ──▶ │ poolTeardown │ ──▶│ for each of its task types │ -│ Ants │ │ workload │ │ for each workload │ -│ WorkerPool │ │ TaskConfig │ │ for each subject │ -│ Conc │ │ │ │ │ -│ ErrGroup │ └──────────────┘ │ spawn producers │ -│ Gopool │ │ submit, wait, teardown│ -│ GoroutinePool│ │ │ -│ BufferedPool │ │ │ -└──────────────┘ └──────────────────────────────┘ +Rows are named `BenchmarkTasks/W//`, with `W` for workers and sizes in thousands ending in `K`: `BenchmarkTasks/Loop10W50K/100u-10Kt/VarMQ` is the `Loop10` task on 50,000 workers, 100 producers x 10,000 tasks each, subject VarMQ. One slice, the pool of one worker: + +```bash +go test -run xxx -bench 'Tasks/W1$' -benchtime=1x ``` -1. **A subject is a factory.** Given `maxWorkers`, it returns `submit(task)` and `teardown()`. Nothing else leaks into the harness. -2. **Producers are goroutines.** For a `100u-10Kt` run the harness starts 100 goroutines, each calling `submit` 10,000 times. A `WaitGroup` counts task completions. -3. **One iteration = full lifecycle.** Build the pool, push 1M tasks, wait for all to finish, tear the pool down. Pool construction and shutdown are deliberately inside the timed region. -4. **Results go to text, text goes to charts.** `task pool:txt` saves `go test -bench` output to `bench/pool-24cpu.txt`, `bench/pool-8cpu.txt` and `bench/pool-4cpu.txt`. The root `task site:build` turns each file into a dataset with [Vizb](https://github.com/goptics/vizb). +The module is `package main` with its own `go.mod`: run from this directory, or as `task pool:` from the root. ## Adding a pool @@ -149,13 +96,4 @@ Append an entry to `subjects` in [subjects.go](subjects.go): }, ``` -That is the whole integration. The harness picks it up on the next run. The factory is called with every pool size in `poolSizes`, including `1`, so it must work with a single worker. - -## Reading the charts - -- Chart groups are named after the task and pool size, for example `Loop10W50K` or `Loop10W1`. Inside a group, bars are grouped by workload shape, then by subject. -- The `W50K`, `W100K` and `W300K` groups show how each pool scales with parallel work; comparing the same group across sizes shows what more workers cost or buy. The `W1` groups show what each pool costs per task, with nothing running in parallel to hide it. -- Hover a bar for exact `ns/op`, `ops/s` and memory values. -- The 24, 8 and 4 CPU runs are separate datasets (`pool-24cpu`, `pool-8cpu`, `pool-4cpu`) in the dataset switcher, so you can see how each pool scales down. -- Compare each library against **GoroutinePool** first. The gap to that baseline is the real overhead of the library. -- **ErrGroup** shows what skipping a pool costs: no worker reuse, one goroutine spawned per task. A pool that loses to it adds overhead without saving any. +The factory is called with every size in `poolSizes`, including `1`. diff --git a/redis/NOTES.md b/redis/NOTES.md new file mode 100644 index 0000000..85122c2 --- /dev/null +++ b/redis/NOTES.md @@ -0,0 +1,570 @@ +# Work per job + +Per-library notes read from the library sources at the versions in go.mod; the table is the index, the sections carry the evidence. + +### Work table + +| Subject | Ack on hot path | Wake mechanism | Idle wait | Round trips per job | Serialization | Pool size | Forced settings | +|---------|-----------------|----------------|-----------|---------------------|---------------|-----------|-----------------| +| VarMQ (persistent) | one pop script per up to k jobs (`listAckPop`, `redisq/queue.go`: `HMGET` guard, `LRANGE`+`LTRIM`, `HSET`, `ZADD` deadline, `ZADD` heartbeat, `LLEN`; `LPOP` variant at k = 1), then one `HDEL`+`ZREM` pipeline per job (`Queue.Acknowledge`): 2 round trips per job at k = 1, falling toward 1 as k grows; k = 64 is the upper bound, not the expected value | in-process: `Add` pokes the ready hint and signals the event loop (`persistentQueue.Add`, `varmq/persistent.go`); no polling on the hot path | 1 `LLEN` per second while the hint is dry (`resync`, `varmq/source.go`), so a second process's adds would be seen up to 1 s late; the subject runs 1 instance | consumer side 1 ack pipeline per job plus 1 pop script per k jobs, k = the free slots at each wake, at most min(workers, 64), sized by `popLen`; the first pass asks for the full credit and pops what is queued, later passes ask for what finished since (not measured); producer side 1 (`RPUSH`); not per job: 1 sweep script per second per queue object | `varmq.Job` JSON (`{id, status, data}`) wrapping the payload | `poolSize(workers)` via `pool_size` in the URL; acks use go-redis's pipeline pool, up to 10 at a time, the rest spill to the main pool | `concurrency = workers` (`varmq.NewWorker(fn, workers)`, `redis/varmq.go`), queue key `bench`, `WithAutoRun(false)` on the Enqueue-only producer; defaults kept: visibility timeout 5 min, heartbeat timeout 30 s, dedup window 5 min | +| Asynq | `EVALSHA` Lua scripts: dequeue (`RPOPLPUSH` pending to active, `HSET`/`HDEL`, `ZADD` lease, `HGET`), then done (`LREM`, `ZREM`, `DEL`, `INCR`/`GET`/`INCR`), 2 round trips | polling: no blocking pop, no push wake | `time.Sleep(TaskCheckInterval/2 + rand.N(TaskCheckInterval))` on an empty queue, `TaskCheckInterval` default 1 s, so 0.5 to 1.5 s; idle `Shutdown` waits out the current sleep | 2 consumer-side, 1 producer-side (plus 1 `SADD` per client) | protobuf `TaskMessage` wrapping the JSON payload, in a task hash | `poolSize(workers)` via `RedisClientOpt.PoolSize` | queue `bench`; defaults kept: retry 25, timeout 30 min, lease 30 s, no retention | +| VarMQDistributed | same pop script and ack pipeline as VarMQ, with the consumer id so a short pop on an empty queue joins `bench:idle` in the same script | push to one consumer per item: the enqueue script `SPOP`s `bench:idle` and `PUBLISH`es `enqueued` on `bench:wake:` (`listPushWake`, `redisq/distributed.go`); a 1 s `nudge` script per consumer re-delivers `enqueued` while items wait; sweep and `Close` wake for what they requeue | no polling on the hot path; the 1 s `nudge` script per consumer is a safety net for lost wakes; sweep script every 1 s per queue object; go-redis pub/sub `PING` every 3 s idle (`pubsub.go`, `initHealthCheck`) | consumer side 1 ack pipeline per job plus 1 pop script per k jobs, as VarMQ; producer side 1 script per job (`RPUSH` plus the wakes) | `varmq.Job` JSON wrapping the payload | `poolSize(workers)` via `pool_size` in the URL, `poolSize(0)` for the producer; pub/sub uses go-redis's own pub/sub pool; acks use its pipeline pool, up to 10 at a time, the rest spill to the main pool | `concurrency = workers` (`varmq.NewWorker(fn, workers)`, `redis/varmq_distributed.go`), queue key `bench`; defaults kept: visibility timeout 5 min, heartbeat timeout 30 s, dedup window 5 min | +| Rmq | `LREM unacked 1 ` per job (`redisDelivery.Ack`, `delivery.go`), 1 round trip; fetch is one `RPOPLPUSH` ready to unacked per job (`consumeBatch`, `queue.go`) | polling only: no blocking pop, no push | `time.Sleep(jitteredDuration(pollDuration))` after every fetch pass, +/-10% (0.9 to 1.1 ms at our setting), not only when empty; no back-off found in `consume` | 2 consumer-side (`RPOPLPUSH`, `LREM`) plus 1 `LLEN` per pass, 1 producer-side (`LPUSH`) | plain string payload (the JSON) | `poolSize(workers)` on our go-redis client (rmq does not create it) | poll duration 1 ms and prefetch limit `max(1000, 2*workers)`: rmq has no default for either; the prefetch follows `example/consumer/main.go` in rmq v5.2.0 (`prefetchLimit = 1000`), raised to 2 x workers because rmq's `README.md` says the prefetch limit should always be greater than the number of consumers; the poll duration is 1 ms rather than the example's 100 ms because `consume` sleeps it after every batch, which capped a connection near prefetch / 0.1 s (about 10,000 jobs/s; the first run measured 5.9k to 10.3k at C1); queue `bench`, tag `bench`; no cleaner | +| Taskq | `XACK`, then `XDEL`, run separately by the worker after the handler (`Queue.Delete`, `redisq/queue.go`), 2 round trips | blocking: `XREADGROUP ... BLOCK` by one fetcher per instance, woken by `XADD` | `WaitTimeout` 1 s: `redisq.NewQueue` sets it before the 10 s default in `QueueOptions.Init`; workers re-check an empty buffer every 1 s; 3 scheduler loops per queue sleep 1 to 1.5 s between passes; `Stop` waits out the fetcher's current block (up to 1 s) | 2 consumer-side (`XACK`, `XDEL`) plus 1 `XREADGROUP` per up to 10 jobs, 1 producer-side (`XADD`) | msgpack `Message` holding msgpack args holding the JSON payload as bytes, in the stream field `body` | `poolSize(workers)` on our go-redis v8 client (`Options.PoolSize`) | `MinNumWorker = MaxNumWorker = workers` (disables autotune, so one fetcher); defaults kept (all in `QueueOptions.Init`, `queue.go`, except as noted): `ReservationSize` 10, `BufferSize` = `ReservationSize`, `ReservationTimeout` 5 min, `WaitTimeout` 1 s (`redisq.NewQueue`, `redisq/queue.go`), retry limit 64 (`TaskOptions.init`, `task.go`); queue `bench`, task `bench`; handler always returns nil | +| GocraftWork | `LREM 1 ` in a `MULTI`/`EXEC` with `DECR lock` and `HINCRBY lock_info` (`removeJobFromInProgress`, `worker.go`), after the handler, 1 round trip; fetch is one Lua script (`redisLuaFetchJob`, `redis.go`) doing `RPOPLPUSH` to a per-pool in-progress list, 1 round trip | polling only: no blocking pop, no push | per-worker backoff `{0, 10, 100, 1000, 5000}` ms after consecutive empty fetches, reset to 0 by a job (`sleepBackoffsInMilliseconds`, `worker.loop`, `worker.go`); `Stop` does not wait out a sleep; other loops: observer 1 s per worker, heartbeat 5 s, requeuers 1 s, reaper first at 10 s then every 10 min, periodic enqueuer 2 min | 2 consumer-side (fetch script, `MULTI`/`EXEC`) plus 1 script per idle poll, 1 producer-side (`LPUSH`; plus at least 1 `SADD` per `Enqueuer`, one per concurrent first enqueue (8 and 10 seen in two runs with 100 producers), and again every 300 s) | JSON `Job` whose `args.p` holds the JSON payload as a string | `poolSize(workers)` for redigo `MaxActive` and `MaxIdle`, `Wait: true` (our choice) | none beyond pool size; `MaxFails` 4 and priority 1 stay at their defaults (`applyDefaultsAndValidate`, `worker_pool.go`) and are not reached because the handler returns nil; namespace `bench`, job `bench`; `logError` prints to stdout (`log.go`) and cannot be redirected | + +### VarMQ (persistent) + +Library versions `varmq 415ad73` (unreleased, `replace` directive) and +`redisq v1.5.0`. + +- Dequeue: `bind` (`varmq/source.go`) sees that `*redisq.Queue` implements + `IBatchAcknowledgeable` (`varmq/interface.go`; `DequeueBatchWithAckIds` in + `redisq/queue.go`), so the worker's source is a `batchAckSource` and its + manager a `creditManager` (`varmq/source_manager.go`). On every wake the + event loop (`goEventLoop`, `varmq/worker_eventloop.go`) runs + `dispatchCredit` (`varmq/worker_credit.go`), which asks the source for + `min(free workers, maxCredit)` jobs, with `maxCredit` 64 and free workers + `concurrency - busyWorkers`, in one `batchAckSource.fetch`, which is one + `DequeueBatchWithAckIds` call. It pops nothing when the hint is dry or no + worker is free. `dequeueBatch` (`redisq/queue.go`) runs one Lua script + with `EVALSHA` (`Script.Run` in `go-redis/v9/script.go`, `EVAL` once on + `NOSCRIPT`): `listAckPop` when it wants 2 or more items (`HMGET` of the + reservation's ack ids as a re-send guard, `LRANGE`+`LTRIM`, `HSET` on + `bench:nacked`, `ZADD` on `bench:timeouts` with a deadline from Redis + `TIME`, `ZADD` on `bench:heartbeats`, `LLEN` for the reply), or the leaner + `listAckPopOneLen` (`HGET` guard, `LPOP`, `HSET`, `ZADD`, `ZADD`, `LLEN`) + when it wants one. How many it wants is `min(free workers, 64, popLen)` + capped at `maxPop` 1000: redisq sizes each call by what the last one left + in the queue or, once the queue emptied, by the run taken since it was + last seen empty (`popLen` and `popRun` in `dequeueBatch`), so 64 is the + cap that binds here. Each popped job goes straight to its own pool goroutine + (`node.Value.Send` in `dispatchCredit`); nothing is buffered. One pop is + in flight at a time per worker, since the event loop runs `dispatchCredit` + serially; acks run from the pool goroutines concurrently. A pop that + comes up short, or a full one that empties the queue, marks the source dry + (`fetch`, `varmq/source.go`), and the next `Add` or resync pokes it. +- Enqueue: `persistentQueue.Add` (`varmq/persistent.go`) calls `enqueue` + (`varmq/interface.go`), which takes the plain `Enqueue` path because the + default `jobIdGenerator` returns `""` (`defaultConfig`, `varmq/config.go`), + so `EnqueueOnce` and the dedup window are never used. `Queue.Enqueue` + (`redisq/queue.go`) is one `RPUSH`, not a pipeline: the queue expiration + is 0. `Add` then pokes the source's ready hint and signals the event loop + (`poke`, `notifyToPullNextJobs`). +- Ack: `job.closeOnce` calls `job.acknowledge` (`varmq/job.go`), which calls + `Queue.Acknowledge` (`redisq/queue.go`): one `HDEL`+`ZREM` pipeline, 1 + round trip per job, run by the pool goroutine right after the handler + returns (`initPoolNode`, `varmq/worker_pool.go`). The ack runs synchronously + in that goroutine, and the worker slot is freed only after it returns + (`busyWorkers` decremented, then `finishJobs` and `notifyToPullNextJobs`), + which is why the next pop's size tracks completions. Acks are not batched. + The ack id is `::`, the prefix 128 random bits + per `Queue` object (`newID`, `ackIDOf`). +- Wake: in process, no polling on the hot path. `Add` pokes and signals, + `Start` (`varmq/worker_lifecycle.go`) signals, `bind` signals once when + the queue is bound, and a pool goroutine signals after each job + (`initPoolNode`). The signal is a non-blocking send on a channel of capacity + 1 (`notifyToPullNextJobs`, `eventLoopSignalCap` in `varmq/worker.go`), so + signals coalesce. No per-job `LLEN`: `creditManager.Len` returns the ready + hint (`batchAckSource.ready`, no I/O), and the credit branch of the event + loop never calls `worker.pending`. +- No mutex across Redis calls on the hot path: the v1.5.0 `Queue` keeps its + config in atomics (the `Queue` struct, `redisq/queue.go`) and holds no + lock around a command, script or pipeline, so adds, pops and acks from + many goroutines run concurrently. The Redis calls under a lock are at + Close only: varmq's `Wait` (`varmq/worker_wait.go`) holds `w.mx` while + `NumPending` runs its `LLEN`, and `Queue.Close` runs `releaseScript` + inside its `closeOnce` `sync.Once` (`redisq/queue.go`). +- Idle wait: when the source is dry it arms a 1 s resync (`markDry`, + `armResync`, `resync` in `varmq/source.go`): one `Queue.Len` (`LLEN`) per + second while the worker is active, the hint is dry and this is its only + source; it pokes if items wait. That is how a second process's adds would + be found, up to 1 s late; the harness keeps this subject at 1 instance, + where the producer is the consumer's own `Add` (`varmqConsumer`, + `redis/varmq.go`). +- Round trips per job, consumer side: 1 ack pipeline per job plus 1 pop + script per k jobs, where k is the free slots at each wake, at most + `min(workers, 64)` and further limited by `popLen`. The first pass, with + every worker idle, asks for the full credit (up to 10 at W10, up to 64 at + W100 and W1000) and pops what is queued, one or a few jobs with the `1u` + workload; later passes ask for what finished since the last one, because + signals coalesce and a slot is freed only after the handler and its ack + return (`dispatchCredit`, `initPoolNode`). On `Sleep1ms` at W10 k is + likely nearer 1 than 10, an estimate that assumes pop and ack round-trip + times, not only the code; with a trickle k is 1, 2 round trips per job. + Not measured. Producer side: 1 per job (`RPUSH`). Not per job: the background + work below. +- Not per job: `newQueue` (`redisq/queue.go`) runs `RequeueNackedItems` + once and starts `sweep`, one `tickScript` per second per `Queue` object, + which requeues items past their visibility deadline, renews this object's + heartbeat and requeues the items of owners whose heartbeat ran out + (`tickBody`). It also calls `PUBSUB NUMSUB` for each live owner's wake + channel and ignores the result here, since only a distributed owner has a + presence row. In the end-to-end runs the producer is the consumer's own + `Queue` object (`varmqConsumer`, `redis/varmq.go`), so one sweep runs; + `BenchmarkEnqueue`'s producer (`varmqProducer`) is a separate object with + its own. Heartbeats are on by default: `SetHeartbeatTimeout` defaults to + 30 s (`newQueueBase`), and each pop that hands out items beats inside its + script (`beatFn`), so no extra round trip. The adapter sets neither the + heartbeat nor the visibility timeout, which stays at 5 min (`newQueueBase`). +- Pool size: `redisq.New` (`redisq/queues.go`) parses the URL with + `redis.ParseURL`, which reads `pool_size` (`setupConnParams`, + `go-redis/v9/options.go`), so the adapter appends it with `withPoolSize` + (`redis/types.go`). `New` also sets a 3 s read timeout and a 512 ms max + retry backoff unless the URL sets them, and one dial attempt, which a URL + cannot change (`DialerRetries`). The ack pipelines go through go-redis's + separate pipeline pool, up to 10 at a time (`DefaultPipelinePoolSize`, + `go-redis/v9/options.go`); the rest spill to the main pool + (`withPipelineConn`, `go-redis/v9/redis.go`), so with more than 10 acks + in flight, as at W100 and W1000, the others run on `pool_size` connections. + `pipeline_pool_size` is a URL option the adapter does not set. +- Batch size: `maxCredit` is 64 (`varmq/worker_credit.go`), the most jobs + one pop takes. `ackSource.maxBatch` stays 1 (`varmq/source.go`); it only + applies to the classic loop that drains jobs parked by a stop or pause. +- Serialization: `job.Json` (`varmq/job.go`) marshals `{id, status, data}` + with the payload as `data` (`id` is empty here); the consumer parses it + back in `toJob` (`varmq/source.go`). +- Close: the adapter calls `WaitAndStop` (`varmq/worker_wait.go`), which + polls `NumPending` (`varmq/worker.go`; one `LLEN` per check, re-checked + every 10 ms while nothing runs, `waitRecheck`) until the queue and the + processing count are 0, then `Stop`. `Queue.Close` (`redisq/queue.go`) + then cancels the sweep and runs `releaseScript` once if the object ever + popped: an `HKEYS` scan of `bench:nacked` that requeues this object's + un-acked items and drops its heartbeat (`releaseBody`, 3 s timeout). After + `Wait` it finds nothing to move. +- Logging: varmq prints nothing (its default error handler is a no-op, + `varmq/config.go`). `redisq` logs through the std `log` package; `TestMain` + discards it. + +### Asynq + +Library version `asynq v0.26.0`. Paths are inside the module (`go env GOMODCACHE`). + +- Dequeue: `processor.exec` (`processor.go`) calls `RDB.Dequeue` + (`internal/rdb/rdb.go`), which runs `dequeueCmd`, a Lua script, with + `EVALSHA` (falling back to `EVAL` on `NOSCRIPT`, `Script.Run` in + `go-redis/v9/script.go`). Keys: `asynq:{bench}:pending`, `:paused`, `:active`, + `:lease`. The script checks `EXISTS` on the paused key, `RPOPLPUSH` pending to + active, `HSET`+`HDEL` on the task hash `asynq:{bench}:t:`, `ZADD` on the + lease zset, then `HGET`s the message. Enqueue is `RDB.Enqueue`: one + `enqueueCmd` script (`EXISTS`, `HSET`, `LPUSH`), plus one `SADD` of the queue + name on a client's first enqueue (`Client.EnqueueContext`, `client.go`). +- Dequeue concurrency: one goroutine (`processor.start`) loops `exec`, so one + `Dequeue` is in flight per server. The handler and its ack run in a goroutine + per task, up to `Concurrency` (the `sema` channel). +- Ack: a handler that returns nil goes to `processor.handleSucceededMessage`. + `Retention` is 0 unless the caller sets it (`composeOptions`, `client.go`), + so it calls `markAsDone` and `RDB.Done`: one `doneCmd` script (`LREM` active, + `ZREM` lease, `DEL` task hash, `INCR` the daily processed counter plus + `EXPIREAT` on its first hit, `GET` then `INCR`/`SET` of the total). Completed + tasks are not kept. +- Wake: none. Polling only. The comment in `processor.exec` says it polls the + queues instead of using a blocking pop. An empty + `Dequeue` makes the processor sleep. Pub/sub exists (`subscriber.go`, + `RDB.CancelationPubSub`), but its use here is task cancelation, not job wake + (read from the file name and calls; not traced further). +- Idle wait: when `Dequeue` returns `ErrNoProcessableTask`, `processor.exec` + runs `time.Sleep(taskCheckInterval/2 + rand.N(taskCheckInterval))`. + `TaskCheckInterval` defaults to 1 s (`defaultTaskCheckInterval`, + `server.go`; `NewServerFromRedisClient`), so each idle sleep is uniform in + [0.5 s, 1.5 s). The sleep is not interruptible and holds a worker token. + Jobs enqueued during it wait it out. Measured in a separate 40-job probe, not + the `Latency` benchmark: median enqueue-to-handled latency about 990 ms and + max 1.4 s over 40 sequential jobs, so the `Latency` benchmark runs 1,000 + jobs, one at a time, for every subject: Asynq's default idle poll would make + a 10,000-job paced run take about 2.75 hours per iteration. +- Shutdown: `Server.Shutdown` (`server.go`) calls `processor.shutdown`, whose + `stop` does `p.done <- struct{}{}`. That send is received only after the + processor goroutine finishes its current `exec`, including the sleep above. + So an idle `Shutdown` inside the timed region blocks for the rest of a + 0.5 to 1.5 s sleep. Measured on an idle server: 41 ms, 296 ms, 432 ms, + 795 ms, 1.07 s over 5 runs; 6 ms when stopped right after `Start`. The + 8 s `ShutdownTimeout` (`defaultShutdownTimeout`) only bounds in-flight + handlers, and idle shutdown does not wait for it. We do not tune either. +- Round trips per job, consumer side: 2 (`Dequeue` script, `Done` script). + Not per job: `heartbeater.beat` (`heartbeat.go`) writes server state and + extends leases for active tasks every 5 s. Producer side: 1 per job (one + `EVALSHA`), plus 1 `SADD` per client. +- Serialization: `base.EncodeMessage` (`internal/base/base.go`) marshals a + protobuf `TaskMessage` (`internal/proto/asynq.proto`) carrying type, payload + (our JSON bytes), id (UUID), queue, retry, timeout and the other fields. It + is stored in the task hash field `msg`; the pending list holds only the id. +- Pool size: `RedisClientOpt.PoolSize` goes to `redis.Options.PoolSize` + (`asynq.go`, `MakeRedisClient`). The server uses one pool for the processor, + heartbeater and the other background jobs. The adapter sets `poolSize(workers)` + on the server and on the client; the client passes 0 workers, which gives + `10*GOMAXPROCS`, the go-redis default. +- Forced settings: queue `bench` with priority 1 (`Config.Queues`; asynq falls + back to a `default` queue if none is set, `NewServerFromRedisClient`), + `Concurrency = workers`, `Logger` no-op and `LogLevel = FatalLevel`. Task + options are the defaults: `MaxRetry` 25 and `Timeout` 30 min (`client.go`), + lease 30 s (`rdb.LeaseDuration`), no `Retention`, no unique key. +- Logging: `internal/log` writes to stderr when no logger is set + (`NewLogger`). The adapter passes a no-op `asynq.Logger`. Nothing else in + the library's non-test code prints to stdout or stderr: no startup banner, + and the only std `log.Printf` is a bad-call path in `internal/errors`, which + `TestMain` discards. + +### VarMQDistributed + +Library versions `varmq 415ad73` (unreleased, `replace` directive) and +`redisq v1.5.0`. + +- Dequeue and ack: the same credit path as VarMQ (persistent). + `redisq.DistributedQueue` embeds `*Queue` (`redisq/distributed.go`) and + its own `DequeueBatchWithAckIds` passes the consumer id to the same + `dequeueBatch` scripts (`redisq/queue.go`), so `dispatchCredit` + (`varmq/worker_credit.go`) pops up to `min(free workers, 64)` jobs per + script, sized by `popLen`, and each job is acked with one `HDEL`+`ZREM` + pipeline (`job.acknowledge` in `varmq/job.go`, `Queue.Acknowledge`). With + a consumer id the pop script also joins the idle set in the same step: + `reply` in `popHead` runs `SADD bench:idle ` when the queue is empty + after the pop and the pop took fewer items than the caller had slots. + varmq's `fetch` (`varmq/source.go`) treats a full pop as not dry for a + subscribed source, so a full pop that empties the queue is followed by + one more pop, which returns nothing and joins the idle set. +- No mutex across Redis calls, and the ack synchronous in the pool goroutine + before the slot is freed: as for VarMQ (persistent), with one `redisq.Queue` + per instance. +- Enqueue: `distributedQueue.Add` (`varmq/distributed.go`) calls `enqueue` + (`varmq/interface.go`), the plain path as for VarMQ (no job id), so + `DistributedQueue.Enqueue` (`redisq/distributed.go`) runs one `listPushWake` + script: `RPUSH`, then `wake` (`wakeFn`, `redisq/notification.go`), which + `SPOP`s `bench:idle` and `PUBLISH`es `enqueued` on `bench:wake:`, up to + once per waiting item, stopping when the set runs out; an id whose `PUBLISH` + reaches no subscriber does not count. One round trip per job whatever it + wakes. `Notification.Send` and the shared `bench:notifications` broadcast + are gone in v1.5.0. +- Wake: push to one consumer per item, plus a nudge. `newDistributedQueue` + (`redisq/distributed.go`) builds the `Notification`, whose constructor + calls `Client.Subscribe` on `bench:wake:` (`newNotification`) + and whose `Start` runs the forwarding goroutine (`PubSub.Channel`) and + `nudgeLoop`. `WithDistributedQueue` (`varmq/worker_binder.go`) binds the + queue as a `batchAckSource`, which signals the event loop once at bind + (`bind`, `varmq/source.go`), then `subscribe` marks the source subscribed + and registers a handler that pokes the ready hint and calls + `handleQueueSubscription`, a non-blocking signal to the event loop + (`notifyToPullNextJobs`, `varmq/worker_eventloop.go`). + `Notification.Subscribe` makes the instance a consumer and `SADD`s it to + the idle set (`markIdle`). A `PUBLISH` reaches one idle consumer, not + every instance. A job finishing signals the event loop as for VarMQ. Once + a second `nudgeLoop` runs the `nudge` script (`LLEN`, then `SREM` of this + consumer from the idle set if items wait, else `SADD` if its own last + look found nothing) and, when items wait, delivers `enqueued` to the + handlers itself, so a lost wake costs at most about 1 s. The sweep and + `Close` of a distributed queue wake up to one idle consumer per item they + requeue (`setOnRequeue(q.wake)`, `wakeIdle`). There is no resync timer: + `armResync` (`varmq/source.go`) returns at once for a subscribed source. + The go-redis pub/sub channel health check still sends a `PING` on the + pub/sub connection when no message has arrived for 3 s (`newChannel`, + `initHealthCheck` in `go-redis/v9/pubsub.go`; ping timeout 5 s, reconnect + timeout 10 s). It has no effect on job pickup. +- Start-up: `Client.Subscribe` (`go-redis/v9/redis.go`) writes `SUBSCRIBE` + on the pub/sub connection before it returns (`PubSub.subscribe` and + `_subscribe` call `writeCmd` and do not read the reply), so the `SUBSCRIBE` + has been written when `NewDistributedQueue` returns, though go-redis does + not wait for Redis to confirm it. `NewWorker` starts the worker + (`WithAutoRun` default) before `WithDistributedQueue` binds the queue; the + bind signals a first pop, `Subscribe` joins the idle set, and jobs already + waiting are found by that pop or by the nudge. That first pop can run before + `Subscribe` sets the consumer id, in which case it does not join the idle set + in-script (`Subscribe` does right after) and, if it comes up short, arms one + 1 s resync (`armResync`): it fires once, runs one `lenIdle` script if the + hint is still dry (`resync`), and is not re-armed, since the source is + subscribed by then. +- No `Listen` is needed: `Queue.Listen` (`redisq/queue.go`) only waits for + SIGINT or SIGTERM. The adapter does not call it. +- Round trips per job, consumer side: 1 ack pipeline per job plus 1 pop + script per k jobs, k as for VarMQ (persistent). Producer side: 1 script + per job (`RPUSH` plus the wakes inside it). +- Not per job: per consumer, the `nudge` script once a second; per `Queue` + object (the producer's included), the `sweep` script once a second + (`tickScript`). In both subjects the sweep counts the subscribers of each + live owner's wake channel with `PUBSUB NUMSUB`; only a distributed owner + has a presence row, so only it can be taken for gone after 5 s without a + subscriber (`tickBody`, `presenceGrace`). The producer's `Notification` + subscribes to its own wake channel too, but its nudge loop does nothing, + since the producer never calls `Subscribe` (`consumer` stays false). + Heartbeat timeout 30 s, visibility timeout 5 min and dedup window 5 min + stay at their defaults (`newQueueBase`). Each pop that hands out items + beats inside its script, as for VarMQ. +- Pool size: `redisq.New` parses `pool_size` from the URL, as for VarMQ + (persistent). The producer keeps `poolSize(0)`, which is `10*GOMAXPROCS`. + The pub/sub connection comes from go-redis's separate pub/sub pool + (`Client.pubSub` in `go-redis/v9/redis.go`), so it never counts against + `pool_size`. The ack pipelines use its pipeline pool, up to 10 at a time + (`DefaultPipelinePoolSize`, `go-redis/v9/options.go`); the rest spill to + the main pool (`withPipelineConn`, `go-redis/v9/redis.go`), as for VarMQ. +- Close: the consumer calls `WaitAndStop` first (its `NumPending` runs the + `lenIdle` script per check: `LLEN`, plus `SADD` to the idle set when 0), + then `DistributedQueue.Close` (`redisq/distributed.go`): `leave` (`SREM` + from the idle set), `Queue.Close` (cancel the sweep, `releaseScript` once + if the object ever popped) and `Notification.Stop` (`SREM` again, cancel + the nudge loop, close the pub/sub). Then the client. +- Serialization: as for VarMQ (persistent). +- Logging: `Notification` and `Queue` use the std `log`, which `TestMain` + discards. + +An intermittent stall of `Sleep1msW1000C4/1u-100Kt/VarMQDistributed` was seen on redisq v1.4.0 and did not reproduce on v1.5.0. + +### Rmq + +Library version `rmq/v5 v5.2.0`. Paths are inside the module (`go env GOMODCACHE`). +The adapter opens one `rmq.OpenConnectionWithRedisClient` connection per +consumer instance and one for the producer, each on its own go-redis v9 +client. + +- Enqueue: `Queue.Publish` (`queue.go`) calls `RedisWrapper.LPush` + (`redis_wrapper.go`): one `LPUSH` of the payload onto + `rmq::queue::[bench]::ready`. One round trip per job. The producer's + `Publish` takes no lock of its own. +- Fetch: `StartConsuming` (`queue.go`) starts one goroutine, `redisQueue.consume`, + per queue. Each pass runs `consumeBatch`: one `LLEN` of this connection's + unacked list (`unackedCount`), then, for `prefetchLimit - unacked` deliveries, + one `RPOPLPUSH` ready to `rmq::connection::::queue::[bench]::unacked` + per delivery (`RedisWrapper.RPopLPush`, not pipelined), each pushed into a + channel of size `prefetchLimit`. An empty list ends the pass. +- Ack: `redisDelivery.Ack` (`delivery.go`) runs one `LREM unacked 1 ` + per job, one round trip. Nothing else is written per job. An ack that finds + nothing to remove returns `ErrorNotFound`; the adapter ignores it. +- Round trips per job, consumer side: 2 (`RPOPLPUSH` and `LREM`), plus one + `LLEN` per fetch pass, plus one `RPOPLPUSH` that returns nil when a pass + drains the list. +- Wake and idle wait: polling only, no blocking pop and no push. + `consume` calls `time.Sleep(jitteredDuration(pollDuration))` after every pass, + including a pass that fetched jobs, not only an empty one. `jitteredDuration` + (`queue.go`) is +/-10%, so 0.9 to 1.1 ms at our 1 ms. No back-off was found in + `consume`: the sleep is the same on an empty queue. Redis errors only add an + `errChan` send. +- Throughput cap: `consume` sleeps after every pass and a pass fetches at most + `prefetchLimit - unacked` deliveries (`consumeBatch`), so one connection moves + at most about `prefetchLimit / (pass time + pollDuration)` jobs per second. + At the example's 100 ms that was 1000 / 0.1 s = 10,000 jobs/s per instance at + `workers <= 500`, and the first run sat on it (5.9k to 10.3k jobs/s at C1); + at our 1 ms the sleep is below the serial `RPOPLPUSH` cost of a pass, so the + pass itself binds. +- Heartbeat: `openConnection` (`connection.go`) starts a goroutine that runs + `SET rmq::connection::::heartbeat 1` with a 1 minute TTL every second + (`heartbeatInterval`, `heartbeatDuration`). It is per connection, not per + job. `openConnection` also runs `SADD rmq::connections`, `OpenQueue` runs + `SADD rmq::queues`, `StartConsuming` runs one `SADD` for the connection's + queue set, and each `AddConsumerFunc` (`addConsumer`) runs one `SADD`, serially. At 1000 workers that is + 1000 setup round trips, inside the timed region. +- Cleaner: `NewCleaner` (`cleaner.go`) has no caller inside rmq, so no cleaner + runs unless the application starts one. The adapter does not. Unacked + deliveries left by a stopped connection stay in its unacked list. +- Tag: `openConnection` names the connection `-`, so the tag + `bench` need not be unique. Consumers get `-` too. +- Stop: `StopAllConsuming` (`connection.go`) calls `Queue.StopConsuming` for + each opened queue. Its channel closes after `stopWg.Wait`, which waits for + every consumer goroutine, but not for the fetch goroutine or the heartbeat + goroutine. The fetch goroutine exits at its next check, so it can run up to + one sleep longer; the adapter closes the go-redis client right after, so + anything it still sends fails. `TestRmqStopEndsPollers` checks that the + fetch and consumer goroutines end. rmq has no exported way to stop the + heartbeat goroutine (`stopHeartbeat` is unexported). After the client closes, + its `SET` fails once a second, and at `HeartbeatErrorLimit` (45) it sends one + blocking error to `errChan` and exits. The adapter gives `errChan` a + buffer of 1024 so that send completes with no reader. Net effect: each + stopped connection leaves one idle goroutine for about 45 s. +- Serialization: `Publish` takes `...string` (`queue.go`), so the adapter sends + `string(payload.marshal())`, the same JSON bytes as the other subjects. + `newDelivery` calls `ExtractHeaderAndPayload` (`header.go`), which only + strips a header when the payload starts with the signature `\xFF\x00\xBE\xBEJ`. + Our JSON starts with `{`, so it passes through. +- Pool size: with `OpenConnectionWithRedisClient` rmq does not create the + client, so the adapter sets `PoolSize` on its own go-redis client: + `poolSize(workers)` per consumer instance, `poolSize(0)` for the producer. +- Logging: rmq does not log. Errors go to `errChan`, which a goroutine drains + until stop. + +### Taskq + +Library version `taskq/v3 v3.2.9`, redis backend `redisq` imported as +`taskqredis`, which uses go-redis **v8** (`github.com/go-redis/redis/v8 v8.11.5`) +rather than the v9 the other subjects use. Paths are inside the module (`go env +GOMODCACHE`). The adapter builds one go-redis v8 client, one `redisq` factory and +one queue named `bench` per consumer instance, and the same per producer. + +- Enqueue: `Queue.Add` (`redisq/queue.go`) calls `Queue.add`, which runs one + `XADD` on the stream `taskq:{bench}:stream` with a single field `body`. One + round trip per job, not pipelined. `add` also fills in a random UUID as the + message ID, unrelated to the stream entry ID. `isDuplicate` only touches Redis + when the message has a `Name`; ours has none. +- Serialization: `Message.MarshalBinary` (`message.go`) msgpack-encodes the + message (task name, args bytes, reserved count, ID). The args are + `msgpack.Marshal([]interface{}{payloadJSON})` (`Message.MarshalArgs`), so the + adapter's JSON bytes ride as one msgpack `bin` inside a msgpack message + inside the stream field. `MarshalBinary` compresses the args with s2 only at + 512 bytes or more; our JSON is about 140 bytes (computed, not measured on the + wire), so no compression applies. +- Fetch: `Consumer.fetchMessages` (`consumer.go`) calls `Queue.ReserveN`, which + runs `XREADGROUP GROUP taskq COUNT BLOCK + STREAMS taskq:{bench}:stream >`. `n` is `ReservationSize`. On `NOGROUP` it + runs `XGROUP CREATE ... MKSTREAM` from `0` and retries. +- Fetchers: with `MinNumWorker == MaxNumWorker`, `Consumer.Start` does not + start the autotuner (`consumer.go`, `Start`: it only runs when min < max). It + calls `replaceConfig` with `NumFetcher: 0`, and `ensureFetcher` + (called from `waitMessage`) then starts one fetcher, id 0. Nothing raises + the count afterwards, so each consumer instance has one fetcher, regardless + of worker count, feeding a buffered channel of `BufferSize` (default = + `ReservationSize`, 10). The fetcher takes up to 10 jobs per `XREADGROUP` + and blocks on the channel when it is full. +- Ack: `Consumer.Put` calls `Consumer.delete`, which calls `Queue.Delete` + (`redisq/queue.go`): `XACK` and then `XDEL`, two separate commands, two + round trips, run by the worker goroutine after the handler returns. The + handler always returns nil, because a returned error makes taskq `Release` + the message for a retry. +- Round trips per job: 2 consumer-side (`XACK`, `XDEL`) plus one `XREADGROUP` + per up to 10 jobs; 1 producer-side (`XADD`). +- Idle wait: the fetcher blocks in `XREADGROUP` for `WaitTimeout`. The default + is 10 s in `QueueOptions.Init` (`queue.go`), but `redisq.NewQueue` sets it to + 1 s first when it is zero (`redisq/queue.go`), so it is 1 s here. A worker + with an empty buffer waits on a 1 s timer (`waitMessage`, + `workerIdleTimeout`) and then loops. Redis wakes the fetcher as soon as an + `XADD` arrives, so blocking is a push wake for a single consumer. +- Scheduler loops: `NewQueue` starts three goroutines per queue, producers + included (`scheduler`: `delayed`, `pending`, `clean_zombie_consumers`). + Each pass takes a Redis lock with `redislock.Obtain` and releases it + (`withRedisLock`), runs one query, and sleeps `1000 + rand(500)` ms when it + found nothing (`schedulerBackoff`). They are idle work, not job work, but they + issue a few Redis commands per second per queue and the producer's one + queue runs them too (the harness calls the producer factory once per + iteration; the N producer goroutines share its one enqueue function), so each + iteration runs 3 loops for the producer plus 3 per consumer instance. `pending` + (`schedulePending`) re-queues entries unacked for `ReservationTimeout` + (5 min), so a run longer than 5 min with slow acks could redeliver; the + collector counts duplicates, and none were seen in `TestSubjects`. +- Stop: `Consumer.Stop` (`consumer.go`, `StopTimeout`) stops the fetchers first + and waits for them, which means waiting out the fetcher's current + `XREADGROUP` block (up to 1 s); idle workers return immediately on `stopCh`. + The adapter then calls `factory.Close`, which closes the queue + (`Queue.CloseTimeout` sets `_closed` and runs `XGROUP DELCONSUMER`), and + then closes the client. The scheduler goroutines are not waited on + (`CloseTimeout` never touches the queue's `WaitGroup`): they exit at their + next wake because `scheduler` checks `closed()` first, and any call they have + in flight when the client closes fails. So every stop costs up to about + 1 s, inside the timed region. `TestTaskqStopLeavesNothingWriting` checks + that nothing writes to Redis after stop returns (a mutant that skips the + close makes it fail: a scheduler recreates the stream group). +- Registry: `taskq.RegisterTask` is global and panics on a second register of + the same name (`task.go`, `RegisterTask`, which wraps `registry.go` + `TaskMap.Register`, the function that returns the error), so the adapter registers + the task `bench` once at package level and routes to the current handler + through an `atomic.Pointer`. All instances of one run share one handler, and + the harness stops a round before the next starts. The queue registry is per + factory (`internal/base/factory.go`, `Factory.Register`), so each instance + has its own factory. +- Pool size: `poolSize(workers)` on our go-redis v8 `Options.PoolSize` per + consumer instance, `poolSize(0)` per producer (v8's own default is + `10 * GOMAXPROCS` as well). +- Logging: taskq logs through `internal.Logger`, set with `taskq.SetLogger`, + and go-redis v8 through `redis.SetLogger`; the adapter sets both to no-ops + in `init`. + +### GocraftWork + +Library version `github.com/gocraft/work v0.5.1`, which imports redigo as +`github.com/gomodule/redigo/redis` (`worker_pool.go`, `enqueue.go`), so the +adapter uses redigo `v1.9.3` and no old `garyburd` import is involved. Paths are +inside the module (`go env GOMODCACHE`). The adapter builds one redigo pool per +consumer instance (one `WorkerPool`), and one per producer (one `Enqueuer`). +Namespace `bench`, job name `bench`, so the job list is `bench:jobs:bench`. + +- Enqueue: `Enqueuer.Enqueue` (`enqueue.go`) runs one `LPUSH bench:jobs:bench + `, then `addToKnownJobs`, which runs `SADD bench:known_jobs bench` + at least once per `Enqueuer` and again after 300 s. The check is not atomic + (read under `RLock`, then `SADD`, then write under `Lock`), so concurrent first + enqueues each issue their own `SADD`: 8 and 10 seen in two runs with 100 producers (`INFO + commandstats` after `BenchmarkEnqueue/100u-1Kt`, against 100,000 `LPUSH`). So + one round trip per job, not pipelined, plus a few extra at the start. The adapter + holds one `Enqueuer` per producer factory call; the N producer goroutines of + a run share it and its pool. +- Serialization: `Job.serialize` (`job.go`) is `json.Marshal` of a `Job` + (`name`, `id`, `t`, `args`). The adapter's JSON rides as the string argument + `p` inside `args`, so it is JSON-escaped inside the job JSON. The `id` is 12 + bytes from `crypto/rand` as hex (`identifier.go`, `makeIdentifier`), made on + every `Enqueue`. The consumer side runs `json.Unmarshal` into a `Job` + (`newJob`, `job.go`) and the adapter then unmarshals `p` a second time. +- Fetch: each worker is one goroutine running `worker.loop` (`worker.go`), + which calls `fetchJob` and `processJob` in turn, so `concurrency` workers mean + `concurrency` jobs in flight. `fetchJob` runs one Lua script through + `redis.Script.Do` (`redisLuaFetchJob`, `redis.go`), which sends `EVALSHA` and + falls back to `EVAL` once on `NOSCRIPT` (redigo `redis/script.go`, `Do`). For a + non-empty queue the script runs `GET max_concurrency`, `LLEN`, `GET paused`, + `GET lock`, `INCR lock`, `HINCRBY lock_info` and `RPOPLPUSH + bench:jobs:bench bench:jobs:bench::inprogress`: 1 round trip and 7 + commands inside the script. On an empty queue it stops after the first two + (`GET`, `LLEN`) and returns nil. The in-progress list is per `WorkerPool`. +- Priority sampling: `prioritySampler.sample` (`priority_sampler.go`) runs on + every fetch, but its loop only runs while more than one job type is + registered; we register one, so it does nothing. The default priority is 1 + (`applyDefaultsAndValidate`, `worker_pool.go`). +- Ack: after the handler returns, `removeJobFromInProgress` (`worker.go`) sends + `MULTI`, `LREM 1 `, `DECR lock` and `HINCRBY + lock_info -1` with `conn.Send`, then runs `EXEC` with `conn.Do`, + which flushes all five commands and reads all five replies (redigo + `redis/conn.go`, `DoWithTimeout`): 1 round trip. The handler returns nil, so `jobFate` is not + reached: no retry or dead-queue write. +- Per job, consumer side: 2 round trips (the fetch script, then the + `MULTI`/`EXEC` pipeline). Idle polls and the background loops below come on + top. `Job.Unique` is false, so `deleteUniqueJob` (an extra `DEL`) is skipped. +- Idle wait: polling only, no blocking pop and no push wake-up. + `sleepBackoffsInMilliseconds = {0, 10, 100, 1000, 5000}` (`worker.go`). + `loop` counts consecutive empty fetches; the first empty fetch sleeps 10 ms + (index 1; index 0 is never used after an empty fetch), the second 100 ms, the + third 1 s, and the fourth and every later one 5 s. A fetched job resets the + count and the timer to 0. The sleep is a timer in the same `select` as the + stop channel, so `Stop` does not wait out a sleep; it waits for a worker's + current job to finish. +- Background loops, per `WorkerPool` (`WorkerPool.Start`, `worker_pool.go`): + - observer, one per worker (`observer.loop`, `observer.go`): 1 s ticker, + writes `HMSET`+`EXPIRE` (or `DEL` when idle) only when something changed + since the last write, and writes immediately on its first observation. The + worker hands it a start and a done observation per job over a 1,024-slot + channel without touching Redis. So up to one 2-command pipeline per worker + per second. + - heartbeater (`heartbeater.go`, `beatPeriod`): 5 s, `SADD` + `HMSET` + pipelined, and once right at start; `SREM` + `DEL` on stop. + - retry and scheduled requeuers (`requeuer.loop`, `requeuer.go`): 1 s ticker + each, one Lua `ZRANGEBYSCORE` per tick on `bench:retry` and + `bench:scheduled`, which stay empty. + - dead pool reaper (`dead_pool_reaper.go`): first pass after `deadTime` + 10 s, then every `reapPeriod` 10 min plus up to 29 s of jitter. It treats a + pool as dead when its `heartbeat_at` is 10 s old or its heartbeat key is + gone (`findDeadPools`), and then requeues that pool's in-progress jobs + (`requeueInProgressJobs`). Every instance runs one. With the 5 s heartbeat a + live pool is not reaped unless its heartbeat is late by more than 5 s; if it + were, its in-flight jobs would be redelivered. Four probe runs of about 10 to 17 s + (W10C1 `Sleep1ms` on both workloads, W10C4 `Sleep1ms` and W1000C4 `Noop` on + `1u-100Kt`) saw no duplicates; that was not kept as a test. + - periodic enqueuer (`periodic_enqueuer.go`): `GET last_periodic_enqueue`, and a + `SET` if the key is absent or more than 2 s old (`shouldEnqueue` compares + against `int64(periodicEnqueuerSleep/time.Minute)`, which is 2 seconds), at + start and then every 2 min plus up to 29 s of jitter. We register no + periodic jobs. + - `Start` also runs `SET max_concurrency 0` for the job synchronously and + launches `SADD bench:known_jobs bench` in a goroutine it never waits for + (`writeConcurrencyControlsToRedis`, `writeKnownJobsToRedis`). + So each instance runs 2 goroutines per worker (loop and observer) plus 5 + background goroutines. +- Stop: `WorkerPool.Stop` (`worker_pool.go`) sends a stop message to every + worker (which also drains and stops its observer), then to the heartbeater, + both requeuers, the reaper and the periodic enqueuer, and waits for each + reply, so all of them have returned when it returns. The only goroutine it + does not wait for is the known-jobs `SADD` above, which normally finishes + right after `Start`. The adapter then closes the pool. + `TestGocraftStopLeavesNothingRunning` checks that no goroutine inside + `gocraft/work` remains after stop, that nothing writes after `FLUSHDB` (waits + 6 s, longer than the 5 s heartbeat), and that stdout stays empty (a mutant that + skips `wp.Stop()` fails it). +- Pool size: `poolSize(workers)` for `MaxActive` and `MaxIdle` per consumer + instance, `poolSize(0)` per producer. `Wait: true` is our choice, not a + default: without it `Pool.Get` returns `ErrPoolExhausted` at `MaxActive` + (redigo `redis/pool.go`), which gocraft/work would log instead of waiting. +- Logging: `logError` (`log.go`) is `fmt.Printf` to **stdout**, not the std + `log` package, and has no hook, so `log.SetOutput` does not silence it. It is + only called when a Redis call or a job fails (fetch, ack, heartbeat, requeue + and observer errors, handler panics), so a healthy run prints nothing; the + stop test above pins that for a short run. A line there would break the + `vizb` parse of `redis.txt` and is a run failure to investigate. diff --git a/redis/README.md b/redis/README.md index 8fe2d2a..130de0c 100644 --- a/redis/README.md +++ b/redis/README.md @@ -1,705 +1,102 @@ -# Redis queue benchmarks +# Redis message queue benchmarks -Benchmarks for Redis-backed job queues: VarMQ's persistent and distributed -queues against Asynq, rmq, taskq and gocraft/work. It lives in its own Go -module so the other libraries' dependencies (some pull in go-redis v8) stay out -of the other modules. +VarMQ (redisq) against Asynq, rmq, taskq and gocraft/work on Redis. +Chart: https://benchmarks.goptics.org/?id=redis -## Run - -```sh -task redis:up # Redis 7.2 (Debian image) on localhost:6390, pinned to CPU 14, no volume -task redis:test # smoke tests -task redis:bench # every benchmark once (-benchtime=1x) -task redis:txt # full run into bench/redis.txt (hours) -task redis:down -``` - -`task redis:txt` runs the client with `taskset -c 0-13,16-23`, so Redis keeps -core 14 and its sibling thread to itself. Compare runs on this setup only: the -alpine image, unpinned, measured about 2.5x lower on the same code. - -Set `REDIS_URL` to use another Redis (default `redis://localhost:6390/0`). The -tests and benchmarks skip when it isn't reachable. `FLUSHDB` runs before every -iteration, so don't point it at a Redis you care about. - -## Dimensions - -- Workloads: `1u-100Kt` (1 producer x 100,000 jobs), `100u-1Kt` (100 x 1,000) -- Workers per instance: 10, 100, 1000. Instances: 1, 4 (VarMQ's persistent - queue supports 1 only, so it has no `C4` rows) -- Tasks: `Noop`, `Sleep1ms` -- Names: `BenchmarkDurable/WC//`, - `BenchmarkEnqueue/Enqueue//`, - `BenchmarkLatency/LatencyW10C1/1u-1Kt/` -- Metrics: `jobs/s` (Durable, Enqueue); `p50-ms`, `p99-ms`, `max-ms` (Latency) - -Each subject runs at its library defaults, apart from worker concurrency and -the Redis pool size (`max(workers, 10*GOMAXPROCS)`, where the library lets us -set it). Anything else a library forces us to choose is listed under -"Forced settings". - -The Enqueue and Latency names carry an extra segment: they were -`BenchmarkEnqueue//` and `BenchmarkLatency/NoopW10C1/...`. -The dashboard's group pattern needs three segments after the function name, and -the old Latency name collided with the `NoopW10C1` end-to-end group. - -## Datasets on the site - -- Redis (Persistent): the `C1` rows of `BenchmarkDurable`, plus Enqueue and - Latency, for VarMQ, Asynq, Rmq, Taskq and GocraftWork. VarMQ's persistent - queue is single-instance, so it only races at one consumer process. -- Redis (Distributed): the `C4` rows, four consumer processes, VarMQDistributed - included. - -Latency is folded into the persistent dataset, so its group shows an empty -`jobs/s` card, and the end-to-end groups show empty `p50-ms`, `p99-ms` and -`max-ms` cards. Those are expected. +## Results -Adding a subject: also add it to `SUBJECTS` in the root Taskfile, or the -persistent dataset drops it. +Run of 2026-10-24: varmq 415ad73 (unreleased, `replace` in go.mod), redisq v1.5.0, `-benchtime=2x`, Redis 7.2 (Debian image) pinned to one core, 150 rows in `bench/redis.txt`. -## Results +`C1`: jobs/s, `Noop` task, one consumer process. -`bench/redis.txt` is one full run from 2026-10-24: varmq 415ad73 (unreleased, -through the `replace` directive in `go.mod`), redisq v1.5.0, `-benchtime=2x`, -Redis 7.2 (Debian image) pinned to CPU 14, the client on the other cores as -`task redis:txt` sets up. 150 rows: 132 `BenchmarkDurable` (2 tasks x 3 worker -counts x 2 workloads x 11 subject and instance shapes), 12 `BenchmarkEnqueue`, -6 `BenchmarkLatency`. No row failed and no run stalled. jobs/s, higher is -better. +| Row | VarMQ | Asynq | Rmq | Taskq | GocraftWork | +|---|---:|---:|---:|---:|---:| +| NoopW10C1 / 1u-100Kt | 21,459 | 15,988 | 6,195 | 18,963 | 25,057 | +| NoopW10C1 / 100u-1Kt | 41,972 | 18,030 | 5,933 | 35,648 | 49,503 | +| NoopW100C1 / 1u-100Kt | 20,859 | 16,978 | 6,129 | 18,439 | 25,315 | +| NoopW100C1 / 100u-1Kt | 60,551 | 19,828 | 5,859 | 35,560 | 45,110 | +| NoopW1000C1 / 1u-100Kt | 21,027 | 15,484 | 10,271 | 16,939 | 24,912 | +| NoopW1000C1 / 100u-1Kt | 59,182 | 18,693 | 9,317 | 28,531 | 40,710 | -End to end, one instance (`C1`, VarMQ persistent against the four -libraries): VarMQ is first in 4 of 12 rows, all with 100 producers -(`100u-1Kt` at W100 and W1000, 60.6k and 59.2k against GocraftWork's 45.1k and -40.7k). With a single producer (`1u-100Kt`) GocraftWork leads every row at -about 25k and VarMQ is second at about 21k; those rows are bound by the one -producer's enqueue round trip. Against Asynq and Taskq, VarMQ is ahead in every -row: 1.1 to 1.4x with one producer, 2 to 3x with 100. +`C4`: jobs/s, `Noop` task, four consumer processes. -End to end, four instances (`C4`, VarMQDistributed): first in 6 of 12 rows, -every `100u-1Kt` row, by 1.3 to 2.1x over the best rival (55k to 66k against -GocraftWork's 33k to 49k). With a single producer GocraftWork or Rmq lead and -VarMQDistributed sits at 0.80 to 0.90x of the best. +| Row | VarMQDistributed | Asynq | Rmq | Taskq | GocraftWork | +|---|---:|---:|---:|---:|---:| +| NoopW10C4 / 1u-100Kt | 21,946 | 13,057 | 21,816 | 10,968 | 25,650 | +| NoopW10C4 / 100u-1Kt | 55,294 | 19,377 | 16,459 | 17,191 | 48,839 | +| NoopW100C4 / 1u-100Kt | 22,484 | 13,135 | 22,400 | 10,629 | 25,512 | +| NoopW100C4 / 100u-1Kt | 65,606 | 21,198 | 16,889 | 16,018 | 43,263 | +| NoopW1000C4 / 1u-100Kt | 22,347 | 14,519 | 23,041 | 7,663 | 19,542 | +| NoopW1000C4 / 100u-1Kt | 64,993 | 16,488 | 25,137 | 11,377 | 32,672 | -`Sleep1ms` at W10 is bound by 10 workers x 1 ms, so every subject lands near -5k to 6k there. +`Sleep1ms` rows are bound by workers x 1 ms and are only on the chart. -Enqueue only (`BenchmarkEnqueue`): VarMQ 42.9k at one producer, the best of -the six; at 100 producers Rmq, GocraftWork and VarMQ tie near 201k to 202k and -VarMQDistributed trails at 143k, the cost of its wake script per enqueue. +Enqueue only (`BenchmarkEnqueue`, jobs/s): VarMQ 42,867 at one producer, the best of the six; at 100 producers Rmq 202,068, GocraftWork 201,297 and VarMQ 201,078 tie, and VarMQDistributed trails at 143,183. Pickup latency (`BenchmarkLatency`, 1,000 jobs one at a time, ms): | Subject | p50 | p99 | max | |---|---|---|---| -| Taskq | 0.063 | 0.190 | 0.61 | -| GocraftWork | 0.092 | 0.474 | 10.80 | -| VarMQ | 0.142 | 0.384 | 3.58 | -| VarMQDistributed | 0.146 | 0.541 | 2.18 | +| Taskq | 0.06330 | 0.1897 | 0.6119 | +| GocraftWork | 0.09234 | 0.4743 | 10.80 | +| VarMQ | 0.1425 | 0.3843 | 3.583 | +| VarMQDistributed | 0.1457 | 0.5407 | 2.183 | | Rmq | 102.2 | 112.3 | 113.3 | -| Asynq | 995.3 | 1492.0 | 1507.0 | +| Asynq | 995.3 | 1492 | 1507 | Rmq's 100 ms poll and Asynq's 0.5 to 1.5 s idle sleep show directly. VarMQ's -batch pop costs about 0.05 ms over Taskq's blocking `XREADGROUP` at p50. +batch pop p50 is 0.1425 ms against Taskq's 0.06330 ms for its blocking `XREADGROUP`. -In `C4` rows the 4 consumer instances are stopped one after another inside the -timed region, so subjects whose stop waits out an idle poll (Asynq about -0.5 to 1.5 s, Taskq up to 1 s per instance) pay that up to 4 times; a later run -will stop them concurrently. +In `C4` rows the four instances are stopped one after another inside the timed region, so Asynq and Taskq pay their idle poll up to four times. -A `Sleep1msW1000C4/1u-100Kt/VarMQDistributed` row stalled in an earlier full -run on redisq v1.4.0, described under "Known issue" in the VarMQDistributed -section. This run completed that row (and every other) on v1.5.0. +Full run: `bench/redis.txt`. +On the chart, the C1, Enqueue and Latency groups show VarMQ and the four rivals; the C4 groups show VarMQDistributed and the four. -## Work per job +## Subjects -Each row of the work table is read from the library source. The notes per subject -come first and cite the file and function for each claim; the table is last, so -a new row is added at the end of the file. +| Subject (chart name) | Library | Version | Instances | Wake | Consumer round trips per job | +|---|---|---|---|---|---| +| VarMQ | goptics/varmq with goptics/redisq | varmq 415ad73 (unreleased, `replace` in go.mod), redisq v1.5.0 | 1 | push in-process | 1 ack pipeline per job + 1 pop script per up to 64 jobs | +| VarMQDistributed | goptics/varmq with goptics/redisq | varmq 415ad73 (unreleased, `replace` in go.mod), redisq v1.5.0 | 1 and 4 | push to one idle consumer plus a 1 s nudge | 1 ack pipeline per job + 1 pop script per up to 64 jobs | +| Asynq | hibiken/asynq | v0.26.0 | 1 and 4 | poll 0.5-1.5 s | 2 | +| Rmq | adjust/rmq/v5 | v5.2.0 | 1 and 4 | poll 1 ms | 2 | +| Taskq | vmihailenco/taskq/v3 | v3.2.9 with go-redis v8 v8.11.5 | 1 and 4 | blocking XREADGROUP | 2 + 1 per 10 jobs | +| GocraftWork | gocraft/work | v0.5.1 with redigo v1.9.3 | 1 and 4 | backoff poll 10 ms to 5 s | 2 | -### VarMQ (persistent) +What each library does per job, read from source: [NOTES.md](NOTES.md). -Library versions `varmq 415ad73` (unreleased, `replace` directive) and -`redisq v1.5.0`. +## Matrix -- Dequeue: `bind` (`varmq/source.go`) sees that `*redisq.Queue` implements - `IBatchAcknowledgeable` (`varmq/interface.go`; `DequeueBatchWithAckIds` in - `redisq/queue.go`), so the worker's source is a `batchAckSource` and its - manager a `creditManager` (`varmq/source_manager.go`). On every wake the - event loop (`goEventLoop`, `varmq/worker_eventloop.go`) runs - `dispatchCredit` (`varmq/worker_credit.go`), which asks the source for - `min(free workers, maxCredit)` jobs, with `maxCredit` 64 and free workers - `concurrency - busyWorkers`, in one `batchAckSource.fetch`, which is one - `DequeueBatchWithAckIds` call. It pops nothing when the hint is dry or no - worker is free. `dequeueBatch` (`redisq/queue.go`) runs one Lua script - with `EVALSHA` (`Script.Run` in `go-redis/v9/script.go`, `EVAL` once on - `NOSCRIPT`): `listAckPop` when it wants 2 or more items (`HMGET` of the - reservation's ack ids as a re-send guard, `LRANGE`+`LTRIM`, `HSET` on - `bench:nacked`, `ZADD` on `bench:timeouts` with a deadline from Redis - `TIME`, `ZADD` on `bench:heartbeats`, `LLEN` for the reply), or the leaner - `listAckPopOneLen` (`HGET` guard, `LPOP`, `HSET`, `ZADD`, `ZADD`, `LLEN`) - when it wants one. How many it wants is `min(free workers, 64, popLen)` - capped at `maxPop` 1000: redisq sizes each call by what the last one left - in the queue or, once the queue emptied, by the run taken since it was - last seen empty (`popLen` and `popRun` in `dequeueBatch`), so 64 is the - cap that binds here. Each popped job goes straight to its own pool goroutine - (`node.Value.Send` in `dispatchCredit`); nothing is buffered. One pop is - in flight at a time per worker, since the event loop runs `dispatchCredit` - serially; acks run from the pool goroutines concurrently. A pop that - comes up short, or a full one that empties the queue, marks the source dry - (`fetch`, `varmq/source.go`), and the next `Add` or resync pokes it. -- Enqueue: `persistentQueue.Add` (`varmq/persistent.go`) calls `enqueue` - (`varmq/interface.go`), which takes the plain `Enqueue` path because the - default `jobIdGenerator` returns `""` (`defaultConfig`, `varmq/config.go`), - so `EnqueueOnce` and the dedup window are never used. `Queue.Enqueue` - (`redisq/queue.go`) is one `RPUSH`, not a pipeline: the queue expiration - is 0. `Add` then pokes the source's ready hint and signals the event loop - (`poke`, `notifyToPullNextJobs`). -- Ack: `job.closeOnce` calls `job.acknowledge` (`varmq/job.go`), which calls - `Queue.Acknowledge` (`redisq/queue.go`): one `HDEL`+`ZREM` pipeline, 1 - round trip per job, run by the pool goroutine right after the handler - returns (`initPoolNode`, `varmq/worker_pool.go`). The ack runs synchronously - in that goroutine, and the worker slot is freed only after it returns - (`busyWorkers` decremented, then `finishJobs` and `notifyToPullNextJobs`), - which is why the next pop's size tracks completions. Acks are not batched. - The ack id is `::`, the prefix 128 random bits - per `Queue` object (`newID`, `ackIDOf`). -- Wake: in process, no polling on the hot path. `Add` pokes and signals, - `Start` (`varmq/worker_lifecycle.go`) signals, `bind` signals once when - the queue is bound, and a pool goroutine signals after each job - (`initPoolNode`). The signal is a non-blocking send on a channel of capacity - 1 (`notifyToPullNextJobs`, `eventLoopSignalCap` in `varmq/worker.go`), so - signals coalesce. No per-job `LLEN`: `creditManager.Len` returns the ready - hint (`batchAckSource.ready`, no I/O), and the credit branch of the event - loop never calls `worker.pending`. -- No mutex across Redis calls on the hot path: the v1.5.0 `Queue` keeps its - config in atomics (the `Queue` struct, `redisq/queue.go`) and holds no - lock around a command, script or pipeline, so adds, pops and acks from - many goroutines run concurrently. The Redis calls under a lock are at - Close only: varmq's `Wait` (`varmq/worker_wait.go`) holds `w.mx` while - `NumPending` runs its `LLEN`, and `Queue.Close` runs `releaseScript` - inside its `closeOnce` `sync.Once` (`redisq/queue.go`). -- Idle wait: when the source is dry it arms a 1 s resync (`markDry`, - `armResync`, `resync` in `varmq/source.go`): one `Queue.Len` (`LLEN`) per - second while the worker is active, the hint is dry and this is its only - source; it pokes if items wait. That is how a second process's adds would - be found, up to 1 s late; the harness keeps this subject at 1 instance, - where the producer is the consumer's own `Add` (`varmqConsumer`, - `redis/varmq.go`). -- Round trips per job, consumer side: 1 ack pipeline per job plus 1 pop - script per k jobs, where k is the free slots at each wake, at most - `min(workers, 64)` and further limited by `popLen`. The first pass, with - every worker idle, asks for the full credit (up to 10 at W10, up to 64 at - W100 and W1000) and pops what is queued, one or a few jobs with the `1u` - workload; later passes ask for what finished since the last one, because - signals coalesce and a slot is freed only after the handler and its ack - return (`dispatchCredit`, `initPoolNode`). On `Sleep1ms` at W10 k is - likely nearer 1 than 10, an estimate that assumes pop and ack round-trip - times, not only the code; with a trickle k is 1, 2 round trips per job. - Not measured. Producer side: 1 per job (`RPUSH`). Not per job: the background - work below. -- Not per job: `newQueue` (`redisq/queue.go`) runs `RequeueNackedItems` - once and starts `sweep`, one `tickScript` per second per `Queue` object, - which requeues items past their visibility deadline, renews this object's - heartbeat and requeues the items of owners whose heartbeat ran out - (`tickBody`). It also calls `PUBSUB NUMSUB` for each live owner's wake - channel and ignores the result here, since only a distributed owner has a - presence row. In the end-to-end runs the producer is the consumer's own - `Queue` object (`varmqConsumer`, `redis/varmq.go`), so one sweep runs; - `BenchmarkEnqueue`'s producer (`varmqProducer`) is a separate object with - its own. Heartbeats are on by default: `SetHeartbeatTimeout` defaults to - 30 s (`newQueueBase`), and each pop that hands out items beats inside its - script (`beatFn`), so no extra round trip. The adapter sets neither the - heartbeat nor the visibility timeout, which stays at 5 min (`newQueueBase`). -- Pool size: `redisq.New` (`redisq/queues.go`) parses the URL with - `redis.ParseURL`, which reads `pool_size` (`setupConnParams`, - `go-redis/v9/options.go`), so the adapter appends it with `withPoolSize` - (`redis/types.go`). `New` also sets a 3 s read timeout and a 512 ms max - retry backoff unless the URL sets them, and one dial attempt, which a URL - cannot change (`DialerRetries`). The ack pipelines go through go-redis's - separate pipeline pool, up to 10 at a time (`DefaultPipelinePoolSize`, - `go-redis/v9/options.go`); the rest spill to the main pool - (`withPipelineConn`, `go-redis/v9/redis.go`), so with more than 10 acks - in flight, as at W100 and W1000, the others run on `pool_size` connections. - `pipeline_pool_size` is a URL option the adapter does not set. -- Batch size: `maxCredit` is 64 (`varmq/worker_credit.go`), the most jobs - one pop takes. `ackSource.maxBatch` stays 1 (`varmq/source.go`); it only - applies to the classic loop that drains jobs parked by a stop or pause. -- Serialization: `job.Json` (`varmq/job.go`) marshals `{id, status, data}` - with the payload as `data` (`id` is empty here); the consumer parses it - back in `toJob` (`varmq/source.go`). -- Close: the adapter calls `WaitAndStop` (`varmq/worker_wait.go`), which - polls `NumPending` (`varmq/worker.go`; one `LLEN` per check, re-checked - every 10 ms while nothing runs, `waitRecheck`) until the queue and the - processing count are 0, then `Stop`. `Queue.Close` (`redisq/queue.go`) - then cancels the sweep and runs `releaseScript` once if the object ever - popped: an `HKEYS` scan of `bench:nacked` that requeues this object's - un-acked items and drops its heartbeat (`releaseBody`, 3 s timeout). After - `Wait` it finds nothing to move. -- Logging: varmq prints nothing (its default error handler is a no-op, - `varmq/config.go`). `redisq` logs through the std `log` package; `TestMain` - discards it. +| Benchmark | Varies | Metric | +|---|---|---| +| Durable | tasks `Noop`, `Sleep1ms`; workers 10, 100, 1000; instances 1, 4; workloads `1u-100Kt` (1 producer x 100,000 jobs), `100u-1Kt` (100 x 1,000) | jobs/s | +| Enqueue | workloads `1u-100Kt`, `100u-1Kt` | jobs/s | +| Latency | `1u-1Kt`, W10 C1 | p50-ms, p99-ms, max-ms | -### Asynq +Names: `BenchmarkDurable/WC//`, `BenchmarkEnqueue/Enqueue//`, `BenchmarkLatency/LatencyW10C1/1u-1Kt/`. -Library version `asynq v0.26.0`. Paths are inside the module (`go env GOMODCACHE`). +Each subject runs at its library defaults except worker concurrency and the Redis pool size, `max(workers, 10*GOMAXPROCS)`; the settings a library forces are listed in [NOTES.md](NOTES.md). -- Dequeue: `processor.exec` (`processor.go`) calls `RDB.Dequeue` - (`internal/rdb/rdb.go`), which runs `dequeueCmd`, a Lua script, with - `EVALSHA` (falling back to `EVAL` on `NOSCRIPT`, `Script.Run` in - `go-redis/v9/script.go`). Keys: `asynq:{bench}:pending`, `:paused`, `:active`, - `:lease`. The script checks `EXISTS` on the paused key, `RPOPLPUSH` pending to - active, `HSET`+`HDEL` on the task hash `asynq:{bench}:t:`, `ZADD` on the - lease zset, then `HGET`s the message. Enqueue is `RDB.Enqueue`: one - `enqueueCmd` script (`EXISTS`, `HSET`, `LPUSH`), plus one `SADD` of the queue - name on a client's first enqueue (`Client.EnqueueContext`, `client.go`). -- Dequeue concurrency: one goroutine (`processor.start`) loops `exec`, so one - `Dequeue` is in flight per server. The handler and its ack run in a goroutine - per task, up to `Concurrency` (the `sema` channel). -- Ack: a handler that returns nil goes to `processor.handleSucceededMessage`. - `Retention` is 0 unless the caller sets it (`composeOptions`, `client.go`), - so it calls `markAsDone` and `RDB.Done`: one `doneCmd` script (`LREM` active, - `ZREM` lease, `DEL` task hash, `INCR` the daily processed counter plus - `EXPIREAT` on its first hit, `GET` then `INCR`/`SET` of the total). Completed - tasks are not kept. -- Wake: none. Polling only. The comment in `processor.exec` says it polls the - queues instead of using a blocking pop. An empty - `Dequeue` makes the processor sleep. Pub/sub exists (`subscriber.go`, - `RDB.CancelationPubSub`), but its use here is task cancelation, not job wake - (read from the file name and calls; not traced further). -- Idle wait: when `Dequeue` returns `ErrNoProcessableTask`, `processor.exec` - runs `time.Sleep(taskCheckInterval/2 + rand.N(taskCheckInterval))`. - `TaskCheckInterval` defaults to 1 s (`defaultTaskCheckInterval`, - `server.go`; `NewServerFromRedisClient`), so each idle sleep is uniform in - [0.5 s, 1.5 s). The sleep is not interruptible and holds a worker token. - Jobs enqueued during it wait it out. Measured in a separate 40-job probe, not - the `Latency` benchmark: median enqueue-to-handled latency about 990 ms and - max 1.4 s over 40 sequential jobs, so the `Latency` benchmark runs 1,000 - jobs, one at a time, for every subject: Asynq's default idle poll would make - a 10,000-job paced run take about 2.75 hours per iteration. -- Shutdown: `Server.Shutdown` (`server.go`) calls `processor.shutdown`, whose - `stop` does `p.done <- struct{}{}`. That send is received only after the - processor goroutine finishes its current `exec`, including the sleep above. - So an idle `Shutdown` inside the timed region blocks for the rest of a - 0.5 to 1.5 s sleep. Measured on an idle server: 41 ms, 296 ms, 432 ms, - 795 ms, 1.07 s over 5 runs; 6 ms when stopped right after `Start`. The - 8 s `ShutdownTimeout` (`defaultShutdownTimeout`) only bounds in-flight - handlers, and idle shutdown does not wait for it. We do not tune either. -- Round trips per job, consumer side: 2 (`Dequeue` script, `Done` script). - Not per job: `heartbeater.beat` (`heartbeat.go`) writes server state and - extends leases for active tasks every 5 s. Producer side: 1 per job (one - `EVALSHA`), plus 1 `SADD` per client. -- Serialization: `base.EncodeMessage` (`internal/base/base.go`) marshals a - protobuf `TaskMessage` (`internal/proto/asynq.proto`) carrying type, payload - (our JSON bytes), id (UUID), queue, retry, timeout and the other fields. It - is stored in the task hash field `msg`; the pending list holds only the id. -- Pool size: `RedisClientOpt.PoolSize` goes to `redis.Options.PoolSize` - (`asynq.go`, `MakeRedisClient`). The server uses one pool for the processor, - heartbeater and the other background jobs. The adapter sets `poolSize(workers)` - on the server and on the client; the client passes 0 workers, which gives - `10*GOMAXPROCS`, the go-redis default. -- Forced settings: queue `bench` with priority 1 (`Config.Queues`; asynq falls - back to a `default` queue if none is set, `NewServerFromRedisClient`), - `Concurrency = workers`, `Logger` no-op and `LogLevel = FatalLevel`. Task - options are the defaults: `MaxRetry` 25 and `Timeout` 30 min (`client.go`), - lease 30 s (`rdb.LeaseDuration`), no `Retention`, no unique key. -- Logging: `internal/log` writes to stderr when no logger is set - (`NewLogger`). The adapter passes a no-op `asynq.Logger`. Nothing else in - the library's non-test code prints to stdout or stderr: no startup banner, - and the only std `log.Printf` is a bad-call path in `internal/errors`, which - `TestMain` discards. +VarMQ's persistent queue runs one instance, so it has no `C4` rows. -### VarMQDistributed +## Running -Library versions `varmq 415ad73` (unreleased, `replace` directive) and -`redisq v1.5.0`. - -- Dequeue and ack: the same credit path as VarMQ (persistent). - `redisq.DistributedQueue` embeds `*Queue` (`redisq/distributed.go`) and - its own `DequeueBatchWithAckIds` passes the consumer id to the same - `dequeueBatch` scripts (`redisq/queue.go`), so `dispatchCredit` - (`varmq/worker_credit.go`) pops up to `min(free workers, 64)` jobs per - script, sized by `popLen`, and each job is acked with one `HDEL`+`ZREM` - pipeline (`job.acknowledge` in `varmq/job.go`, `Queue.Acknowledge`). With - a consumer id the pop script also joins the idle set in the same step: - `reply` in `popHead` runs `SADD bench:idle ` when the queue is empty - after the pop and the pop took fewer items than the caller had slots. - varmq's `fetch` (`varmq/source.go`) treats a full pop as not dry for a - subscribed source, so a full pop that empties the queue is followed by - one more pop, which returns nothing and joins the idle set. -- No mutex across Redis calls, and the ack synchronous in the pool goroutine - before the slot is freed: as for VarMQ (persistent), with one `redisq.Queue` - per instance. -- Enqueue: `distributedQueue.Add` (`varmq/distributed.go`) calls `enqueue` - (`varmq/interface.go`), the plain path as for VarMQ (no job id), so - `DistributedQueue.Enqueue` (`redisq/distributed.go`) runs one `listPushWake` - script: `RPUSH`, then `wake` (`wakeFn`, `redisq/notification.go`), which - `SPOP`s `bench:idle` and `PUBLISH`es `enqueued` on `bench:wake:`, up to - once per waiting item, stopping when the set runs out; an id whose `PUBLISH` - reaches no subscriber does not count. One round trip per job whatever it - wakes. `Notification.Send` and the shared `bench:notifications` broadcast - are gone in v1.5.0. -- Wake: push to one consumer per item, plus a nudge. `newDistributedQueue` - (`redisq/distributed.go`) builds the `Notification`, whose constructor - calls `Client.Subscribe` on `bench:wake:` (`newNotification`) - and whose `Start` runs the forwarding goroutine (`PubSub.Channel`) and - `nudgeLoop`. `WithDistributedQueue` (`varmq/worker_binder.go`) binds the - queue as a `batchAckSource`, which signals the event loop once at bind - (`bind`, `varmq/source.go`), then `subscribe` marks the source subscribed - and registers a handler that pokes the ready hint and calls - `handleQueueSubscription`, a non-blocking signal to the event loop - (`notifyToPullNextJobs`, `varmq/worker_eventloop.go`). - `Notification.Subscribe` makes the instance a consumer and `SADD`s it to - the idle set (`markIdle`). A `PUBLISH` reaches one idle consumer, not - every instance. A job finishing signals the event loop as for VarMQ. Once - a second `nudgeLoop` runs the `nudge` script (`LLEN`, then `SREM` of this - consumer from the idle set if items wait, else `SADD` if its own last - look found nothing) and, when items wait, delivers `enqueued` to the - handlers itself, so a lost wake costs at most about 1 s. The sweep and - `Close` of a distributed queue wake up to one idle consumer per item they - requeue (`setOnRequeue(q.wake)`, `wakeIdle`). There is no resync timer: - `armResync` (`varmq/source.go`) returns at once for a subscribed source. - The go-redis pub/sub channel health check still sends a `PING` on the - pub/sub connection when no message has arrived for 3 s (`newChannel`, - `initHealthCheck` in `go-redis/v9/pubsub.go`; ping timeout 5 s, reconnect - timeout 10 s). It has no effect on job pickup. -- Start-up: `Client.Subscribe` (`go-redis/v9/redis.go`) writes `SUBSCRIBE` - on the pub/sub connection before it returns (`PubSub.subscribe` and - `_subscribe` call `writeCmd` and do not read the reply), so the `SUBSCRIBE` - has been written when `NewDistributedQueue` returns, though go-redis does - not wait for Redis to confirm it. `NewWorker` starts the worker - (`WithAutoRun` default) before `WithDistributedQueue` binds the queue; the - bind signals a first pop, `Subscribe` joins the idle set, and jobs already - waiting are found by that pop or by the nudge. That first pop can run before - `Subscribe` sets the consumer id, in which case it does not join the idle set - in-script (`Subscribe` does right after) and, if it comes up short, arms one - 1 s resync (`armResync`): it fires once, runs one `lenIdle` script if the - hint is still dry (`resync`), and is not re-armed, since the source is - subscribed by then. -- No `Listen` is needed: `Queue.Listen` (`redisq/queue.go`) only waits for - SIGINT or SIGTERM. The adapter does not call it. -- Round trips per job, consumer side: 1 ack pipeline per job plus 1 pop - script per k jobs, k as for VarMQ (persistent). Producer side: 1 script - per job (`RPUSH` plus the wakes inside it). -- Not per job: per consumer, the `nudge` script once a second; per `Queue` - object (the producer's included), the `sweep` script once a second - (`tickScript`). In both subjects the sweep counts the subscribers of each - live owner's wake channel with `PUBSUB NUMSUB`; only a distributed owner - has a presence row, so only it can be taken for gone after 5 s without a - subscriber (`tickBody`, `presenceGrace`). The producer's `Notification` - subscribes to its own wake channel too, but its nudge loop does nothing, - since the producer never calls `Subscribe` (`consumer` stays false). - Heartbeat timeout 30 s, visibility timeout 5 min and dedup window 5 min - stay at their defaults (`newQueueBase`). Each pop that hands out items - beats inside its script, as for VarMQ. -- Pool size: `redisq.New` parses `pool_size` from the URL, as for VarMQ - (persistent). The producer keeps `poolSize(0)`, which is `10*GOMAXPROCS`. - The pub/sub connection comes from go-redis's separate pub/sub pool - (`Client.pubSub` in `go-redis/v9/redis.go`), so it never counts against - `pool_size`. The ack pipelines use its pipeline pool, up to 10 at a time - (`DefaultPipelinePoolSize`, `go-redis/v9/options.go`); the rest spill to - the main pool (`withPipelineConn`, `go-redis/v9/redis.go`), as for VarMQ. -- Close: the consumer calls `WaitAndStop` first (its `NumPending` runs the - `lenIdle` script per check: `LLEN`, plus `SADD` to the idle set when 0), - then `DistributedQueue.Close` (`redisq/distributed.go`): `leave` (`SREM` - from the idle set), `Queue.Close` (cancel the sweep, `releaseScript` once - if the object ever popped) and `Notification.Stop` (`SREM` again, cancel - the nudge loop, close the pub/sub). Then the client. -- Serialization: as for VarMQ (persistent). -- Logging: `Notification` and `Queue` use the std `log`, which `TestMain` - discards. - -- Known issue (observed on redisq v1.4.0, not rerun on v1.5.0): the row - `Sleep1msW1000C4/1u-100Kt/VarMQDistributed` (4 instances x 1000 workers, - `Sleep1ms`, 1 producer x 100,000 jobs) stalled with 99,819/100,000 jobs - handled, 0 duplicates, until the harness's 5-minute limit (`runEndToEnd`) - failed it. That happened in an earlier full run on redisq v1.4.0 that is not - committed; `bench/redis.txt` is regenerated at the v1.10.0 run. The stall is - intermittent: an isolated rerun of 1 iteration passed, an isolated rerun of 8 - iterations stalled the same way, and isolated reruns of 10 and 40 iterations - passed. The cause is not diagnosed (Redis was not inspected during a stall). - On v1.4.0 an idle instance was woken only by a later `enqueued` broadcast, so - a missed wake-up was the suspect, unverified; v1.5.0 replaced that broadcast - with the per-consumer wake channels and the 1 s nudge above, so that - mechanism no longer exists. The v1.4.0 start-up probes (5 pre-filled jobs - drained in 150 of 150 rounds, `TestSubjects` at 4 instances passing 30 runs - in a row) were measured against that broadcast too and have not been rerun. - `go test` carried on after the FAIL and completed - `Sleep1msW1000C4/1u-100Kt/Rmq`, then the run was stopped by hand, so that run - has no VarMQDistributed `Sleep1msW1000C4/1u-100Kt` numbers, and no - `Sleep1msW1000C4/100u-1Kt` rows for any subject. Treat them as unavailable - until the v1.5.0 run shows otherwise. - -### Rmq - -Library version `rmq/v5 v5.2.0`. Paths are inside the module (`go env GOMODCACHE`). -The adapter opens one `rmq.OpenConnectionWithRedisClient` connection per -consumer instance and one for the producer, each on its own go-redis v9 -client. - -- Enqueue: `Queue.Publish` (`queue.go`) calls `RedisWrapper.LPush` - (`redis_wrapper.go`): one `LPUSH` of the payload onto - `rmq::queue::[bench]::ready`. One round trip per job. The producer's - `Publish` takes no lock of its own. -- Fetch: `StartConsuming` (`queue.go`) starts one goroutine, `redisQueue.consume`, - per queue. Each pass runs `consumeBatch`: one `LLEN` of this connection's - unacked list (`unackedCount`), then, for `prefetchLimit - unacked` deliveries, - one `RPOPLPUSH` ready to `rmq::connection::::queue::[bench]::unacked` - per delivery (`RedisWrapper.RPopLPush`, not pipelined), each pushed into a - channel of size `prefetchLimit`. An empty list ends the pass. -- Ack: `redisDelivery.Ack` (`delivery.go`) runs one `LREM unacked 1 ` - per job, one round trip. Nothing else is written per job. An ack that finds - nothing to remove returns `ErrorNotFound`; the adapter ignores it. -- Round trips per job, consumer side: 2 (`RPOPLPUSH` and `LREM`), plus one - `LLEN` per fetch pass, plus one `RPOPLPUSH` that returns nil when a pass - drains the list. -- Wake and idle wait: polling only, no blocking pop and no push. - `consume` calls `time.Sleep(jitteredDuration(pollDuration))` after every pass, - including a pass that fetched jobs, not only an empty one. `jitteredDuration` - (`queue.go`) is +/-10%, so 90 to 110 ms at our 100 ms. No back-off was found in - `consume`: the sleep is the same on an empty queue. Redis errors only add an - `errChan` send. -- Throughput cap: `consume` sleeps after every pass and a pass fetches at most - `prefetchLimit - unacked` deliveries (`consumeBatch`), so one connection moves - at most about `prefetchLimit / pollDuration` jobs per second: 1000 / 0.1 s = - 10,000 jobs/s per instance at `workers <= 500` (about 11,000 at the shortest - jittered sleep of 0.09 s), and `2*workers / 0.1 s` above that. The cap is - derived from the code, not measured. A pass also costs one serial - `RPOPLPUSH` per delivery, which may bind before the cap. -- Heartbeat: `openConnection` (`connection.go`) starts a goroutine that runs - `SET rmq::connection::::heartbeat 1` with a 1 minute TTL every second - (`heartbeatInterval`, `heartbeatDuration`). It is per connection, not per - job. `openConnection` also runs `SADD rmq::connections`, `OpenQueue` runs - `SADD rmq::queues`, `StartConsuming` runs one `SADD` for the connection's - queue set, and each `AddConsumerFunc` (`addConsumer`) runs one `SADD`, serially. At 1000 workers that is - 1000 setup round trips, inside the timed region. -- Cleaner: `NewCleaner` (`cleaner.go`) has no caller inside rmq, so no cleaner - runs unless the application starts one. The adapter does not. Unacked - deliveries left by a stopped connection stay in its unacked list. -- Tag: `openConnection` names the connection `-`, so the tag - `bench` need not be unique. Consumers get `-` too. -- Stop: `StopAllConsuming` (`connection.go`) calls `Queue.StopConsuming` for - each opened queue. Its channel closes after `stopWg.Wait`, which waits for - every consumer goroutine, but not for the fetch goroutine or the heartbeat - goroutine. The fetch goroutine exits at its next check, so it can run up to - one sleep longer; the adapter closes the go-redis client right after, so - anything it still sends fails. `TestRmqStopEndsPollers` checks that the - fetch and consumer goroutines end. rmq has no exported way to stop the - heartbeat goroutine (`stopHeartbeat` is unexported). After the client closes, - its `SET` fails once a second, and at `HeartbeatErrorLimit` (45) it sends one - blocking error to `errChan` and exits. The adapter gives `errChan` a - buffer of 1024 so that send completes with no reader. Net effect: each - stopped connection leaves one idle goroutine for about 45 s. -- Serialization: `Publish` takes `...string` (`queue.go`), so the adapter sends - `string(payload.marshal())`, the same JSON bytes as the other subjects. - `newDelivery` calls `ExtractHeaderAndPayload` (`header.go`), which only - strips a header when the payload starts with the signature `\xFF\x00\xBE\xBEJ`. - Our JSON starts with `{`, so it passes through. -- Pool size: with `OpenConnectionWithRedisClient` rmq does not create the - client, so the adapter sets `PoolSize` on its own go-redis client: - `poolSize(workers)` per consumer instance, `poolSize(0)` for the producer. -- Logging: rmq does not log. Errors go to `errChan`, which a goroutine drains - until stop. - -### Taskq - -Library version `taskq/v3 v3.2.9`, redis backend `redisq` imported as -`taskqredis`, which uses go-redis **v8** (`github.com/go-redis/redis/v8 v8.11.5`) -rather than the v9 the other subjects use. Paths are inside the module (`go env -GOMODCACHE`). The adapter builds one go-redis v8 client, one `redisq` factory and -one queue named `bench` per consumer instance, and the same per producer. - -- Enqueue: `Queue.Add` (`redisq/queue.go`) calls `Queue.add`, which runs one - `XADD` on the stream `taskq:{bench}:stream` with a single field `body`. One - round trip per job, not pipelined. `add` also fills in a random UUID as the - message ID, unrelated to the stream entry ID. `isDuplicate` only touches Redis - when the message has a `Name`; ours has none. -- Serialization: `Message.MarshalBinary` (`message.go`) msgpack-encodes the - message (task name, args bytes, reserved count, ID). The args are - `msgpack.Marshal([]interface{}{payloadJSON})` (`Message.MarshalArgs`), so the - adapter's JSON bytes ride as one msgpack `bin` inside a msgpack message - inside the stream field. `MarshalBinary` compresses the args with s2 only at - 512 bytes or more; our JSON is about 140 bytes (computed, not measured on the - wire), so no compression applies. -- Fetch: `Consumer.fetchMessages` (`consumer.go`) calls `Queue.ReserveN`, which - runs `XREADGROUP GROUP taskq COUNT BLOCK - STREAMS taskq:{bench}:stream >`. `n` is `ReservationSize`. On `NOGROUP` it - runs `XGROUP CREATE ... MKSTREAM` from `0` and retries. -- Fetchers: with `MinNumWorker == MaxNumWorker`, `Consumer.Start` does not - start the autotuner (`consumer.go`, `Start`: it only runs when min < max). It - calls `replaceConfig` with `NumFetcher: 0`, and `ensureFetcher` - (called from `waitMessage`) then starts one fetcher, id 0. Nothing raises - the count afterwards, so each consumer instance has one fetcher, regardless - of worker count, feeding a buffered channel of `BufferSize` (default = - `ReservationSize`, 10). The fetcher takes up to 10 jobs per `XREADGROUP` - and blocks on the channel when it is full. -- Ack: `Consumer.Put` calls `Consumer.delete`, which calls `Queue.Delete` - (`redisq/queue.go`): `XACK` and then `XDEL`, two separate commands, two - round trips, run by the worker goroutine after the handler returns. The - handler always returns nil, because a returned error makes taskq `Release` - the message for a retry. -- Round trips per job: 2 consumer-side (`XACK`, `XDEL`) plus one `XREADGROUP` - per up to 10 jobs; 1 producer-side (`XADD`). -- Idle wait: the fetcher blocks in `XREADGROUP` for `WaitTimeout`. The default - is 10 s in `QueueOptions.Init` (`queue.go`), but `redisq.NewQueue` sets it to - 1 s first when it is zero (`redisq/queue.go`), so it is 1 s here. A worker - with an empty buffer waits on a 1 s timer (`waitMessage`, - `workerIdleTimeout`) and then loops. Redis wakes the fetcher as soon as an - `XADD` arrives, so blocking is a push wake for a single consumer. -- Scheduler loops: `NewQueue` starts three goroutines per queue, producers - included (`scheduler`: `delayed`, `pending`, `clean_zombie_consumers`). - Each pass takes a Redis lock with `redislock.Obtain` and releases it - (`withRedisLock`), runs one query, and sleeps `1000 + rand(500)` ms when it - found nothing (`schedulerBackoff`). They are idle work, not job work, but they - issue a few Redis commands per second per queue and the producer's one - queue runs them too (the harness calls the producer factory once per - iteration; the N producer goroutines share its one enqueue function), so each - iteration runs 3 loops for the producer plus 3 per consumer instance. `pending` - (`schedulePending`) re-queues entries unacked for `ReservationTimeout` - (5 min), so a run longer than 5 min with slow acks could redeliver; the - collector counts duplicates, and none were seen in `TestSubjects`. -- Stop: `Consumer.Stop` (`consumer.go`, `StopTimeout`) stops the fetchers first - and waits for them, which means waiting out the fetcher's current - `XREADGROUP` block (up to 1 s); idle workers return immediately on `stopCh`. - The adapter then calls `factory.Close`, which closes the queue - (`Queue.CloseTimeout` sets `_closed` and runs `XGROUP DELCONSUMER`), and - then closes the client. The scheduler goroutines are not waited on - (`CloseTimeout` never touches the queue's `WaitGroup`): they exit at their - next wake because `scheduler` checks `closed()` first, and any call they have - in flight when the client closes fails. So every stop costs up to about - 1 s, inside the timed region. `TestTaskqStopLeavesNothingWriting` checks - that nothing writes to Redis after stop returns (a mutant that skips the - close makes it fail: a scheduler recreates the stream group). -- Registry: `taskq.RegisterTask` is global and panics on a second register of - the same name (`task.go`, `RegisterTask`, which wraps `registry.go` - `TaskMap.Register`, the function that returns the error), so the adapter registers - the task `bench` once at package level and routes to the current handler - through an `atomic.Pointer`. All instances of one run share one handler, and - the harness stops a round before the next starts. The queue registry is per - factory (`internal/base/factory.go`, `Factory.Register`), so each instance - has its own factory. -- Pool size: `poolSize(workers)` on our go-redis v8 `Options.PoolSize` per - consumer instance, `poolSize(0)` per producer (v8's own default is - `10 * GOMAXPROCS` as well). -- Logging: taskq logs through `internal.Logger`, set with `taskq.SetLogger`, - and go-redis v8 through `redis.SetLogger`; the adapter sets both to no-ops - in `init`. - -### GocraftWork +```sh +task redis:up # Redis 7.2 (Debian image) on localhost:6390, pinned to CPU 14, no volume +task redis:test # smoke tests +task redis:bench # every benchmark once (-benchtime=1x) +task redis:txt # full run into bench/redis.txt (hours) +task redis:down +``` -Library version `github.com/gocraft/work v0.5.1`, which imports redigo as -`github.com/gomodule/redigo/redis` (`worker_pool.go`, `enqueue.go`), so the -adapter uses redigo `v1.9.3` and no old `garyburd` import is involved. Paths are -inside the module (`go env GOMODCACHE`). The adapter builds one redigo pool per -consumer instance (one `WorkerPool`), and one per producer (one `Enqueuer`). -Namespace `bench`, job name `bench`, so the job list is `bench:jobs:bench`. +One slice, after `task redis:up`: -- Enqueue: `Enqueuer.Enqueue` (`enqueue.go`) runs one `LPUSH bench:jobs:bench - `, then `addToKnownJobs`, which runs `SADD bench:known_jobs bench` - at least once per `Enqueuer` and again after 300 s. The check is not atomic - (read under `RLock`, then `SADD`, then write under `Lock`), so concurrent first - enqueues each issue their own `SADD`: 8 and 10 seen in two runs with 100 producers (`INFO - commandstats` after `BenchmarkEnqueue/100u-1Kt`, against 100,000 `LPUSH`). So - one round trip per job, not pipelined, plus a few extra at the start. The adapter - holds one `Enqueuer` per producer factory call; the N producer goroutines of - a run share it and its pool. -- Serialization: `Job.serialize` (`job.go`) is `json.Marshal` of a `Job` - (`name`, `id`, `t`, `args`). The adapter's JSON rides as the string argument - `p` inside `args`, so it is JSON-escaped inside the job JSON. The `id` is 12 - bytes from `crypto/rand` as hex (`identifier.go`, `makeIdentifier`), made on - every `Enqueue`. The consumer side runs `json.Unmarshal` into a `Job` - (`newJob`, `job.go`) and the adapter then unmarshals `p` a second time. -- Fetch: each worker is one goroutine running `worker.loop` (`worker.go`), - which calls `fetchJob` and `processJob` in turn, so `concurrency` workers mean - `concurrency` jobs in flight. `fetchJob` runs one Lua script through - `redis.Script.Do` (`redisLuaFetchJob`, `redis.go`), which sends `EVALSHA` and - falls back to `EVAL` once on `NOSCRIPT` (redigo `redis/script.go`, `Do`). For a - non-empty queue the script runs `GET max_concurrency`, `LLEN`, `GET paused`, - `GET lock`, `INCR lock`, `HINCRBY lock_info` and `RPOPLPUSH - bench:jobs:bench bench:jobs:bench::inprogress`: 1 round trip and 7 - commands inside the script. On an empty queue it stops after the first two - (`GET`, `LLEN`) and returns nil. The in-progress list is per `WorkerPool`. -- Priority sampling: `prioritySampler.sample` (`priority_sampler.go`) runs on - every fetch, but its loop only runs while more than one job type is - registered; we register one, so it does nothing. The default priority is 1 - (`applyDefaultsAndValidate`, `worker_pool.go`). -- Ack: after the handler returns, `removeJobFromInProgress` (`worker.go`) sends - `MULTI`, `LREM 1 `, `DECR lock` and `HINCRBY - lock_info -1` with `conn.Send`, then runs `EXEC` with `conn.Do`, - which flushes all five commands and reads all five replies (redigo - `redis/conn.go`, `DoWithTimeout`): 1 round trip. The handler returns nil, so `jobFate` is not - reached: no retry or dead-queue write. -- Per job, consumer side: 2 round trips (the fetch script, then the - `MULTI`/`EXEC` pipeline). Idle polls and the background loops below come on - top. `Job.Unique` is false, so `deleteUniqueJob` (an extra `DEL`) is skipped. -- Idle wait: polling only, no blocking pop and no push wake-up. - `sleepBackoffsInMilliseconds = {0, 10, 100, 1000, 5000}` (`worker.go`). - `loop` counts consecutive empty fetches; the first empty fetch sleeps 10 ms - (index 1; index 0 is never used after an empty fetch), the second 100 ms, the - third 1 s, and the fourth and every later one 5 s. A fetched job resets the - count and the timer to 0. The sleep is a timer in the same `select` as the - stop channel, so `Stop` does not wait out a sleep; it waits for a worker's - current job to finish. -- Background loops, per `WorkerPool` (`WorkerPool.Start`, `worker_pool.go`): - - observer, one per worker (`observer.loop`, `observer.go`): 1 s ticker, - writes `HMSET`+`EXPIRE` (or `DEL` when idle) only when something changed - since the last write, and writes immediately on its first observation. The - worker hands it a start and a done observation per job over a 1,024-slot - channel without touching Redis. So up to one 2-command pipeline per worker - per second. - - heartbeater (`heartbeater.go`, `beatPeriod`): 5 s, `SADD` + `HMSET` - pipelined, and once right at start; `SREM` + `DEL` on stop. - - retry and scheduled requeuers (`requeuer.loop`, `requeuer.go`): 1 s ticker - each, one Lua `ZRANGEBYSCORE` per tick on `bench:retry` and - `bench:scheduled`, which stay empty. - - dead pool reaper (`dead_pool_reaper.go`): first pass after `deadTime` - 10 s, then every `reapPeriod` 10 min plus up to 29 s of jitter. It treats a - pool as dead when its `heartbeat_at` is 10 s old or its heartbeat key is - gone (`findDeadPools`), and then requeues that pool's in-progress jobs - (`requeueInProgressJobs`). Every instance runs one. With the 5 s heartbeat a - live pool is not reaped unless its heartbeat is late by more than 5 s; if it - were, its in-flight jobs would be redelivered. Four probe runs of about 10 to 17 s - (W10C1 `Sleep1ms` on both workloads, W10C4 `Sleep1ms` and W1000C4 `Noop` on - `1u-100Kt`) saw no duplicates; that was not kept as a test. - - periodic enqueuer (`periodic_enqueuer.go`): `GET last_periodic_enqueue`, and a - `SET` if the key is absent or more than 2 s old (`shouldEnqueue` compares - against `int64(periodicEnqueuerSleep/time.Minute)`, which is 2 seconds), at - start and then every 2 min plus up to 29 s of jitter. We register no - periodic jobs. - - `Start` also runs `SET max_concurrency 0` for the job synchronously and - launches `SADD bench:known_jobs bench` in a goroutine it never waits for - (`writeConcurrencyControlsToRedis`, `writeKnownJobsToRedis`). - So each instance runs 2 goroutines per worker (loop and observer) plus 5 - background goroutines. -- Stop: `WorkerPool.Stop` (`worker_pool.go`) sends a stop message to every - worker (which also drains and stops its observer), then to the heartbeater, - both requeuers, the reaper and the periodic enqueuer, and waits for each - reply, so all of them have returned when it returns. The only goroutine it - does not wait for is the known-jobs `SADD` above, which normally finishes - right after `Start`. The adapter then closes the pool. - `TestGocraftStopLeavesNothingRunning` checks that no goroutine inside - `gocraft/work` remains after stop, that nothing writes after `FLUSHDB` (waits - 6 s, longer than the 5 s heartbeat), and that stdout stays empty (a mutant that - skips `wp.Stop()` fails it). -- Pool size: `poolSize(workers)` for `MaxActive` and `MaxIdle` per consumer - instance, `poolSize(0)` per producer. `Wait: true` is our choice, not a - default: without it `Pool.Get` returns `ErrPoolExhausted` at `MaxActive` - (redigo `redis/pool.go`), which gocraft/work would log instead of waiting. -- Logging: `logError` (`log.go`) is `fmt.Printf` to **stdout**, not the std - `log` package, and has no hook, so `log.SetOutput` does not silence it. It is - only called when a Redis call or a job fails (fetch, ack, heartbeat, requeue - and observer errors, handler panics), so a healthy run prints nothing; the - stop test above pins that for a short run. A line there would break the - `vizb` parse of `redis.txt` and is a run failure to investigate. +```sh +go test -run xxx -bench 'Durable/NoopW10C1' -benchtime=1x -timeout 0 +``` -### Work table +Set `REDIS_URL` to use another Redis (default `redis://localhost:6390/0`). The +tests and benchmarks skip when it isn't reachable. `FLUSHDB` runs before every +iteration, so don't point it at a Redis you care about. -| Subject | Ack on hot path | Wake mechanism | Idle wait | Round trips per job | Serialization | Pool size | Forced settings | -|---------|-----------------|----------------|-----------|---------------------|---------------|-----------|-----------------| -| VarMQ (persistent) | one pop script per up to k jobs (`listAckPop`, `redisq/queue.go`: `HMGET` guard, `LRANGE`+`LTRIM`, `HSET`, `ZADD` deadline, `ZADD` heartbeat, `LLEN`; `LPOP` variant at k = 1), then one `HDEL`+`ZREM` pipeline per job (`Queue.Acknowledge`): 2 round trips per job at k = 1, falling toward 1 as k grows; k = 64 is the upper bound, not the expected value | in-process: `Add` pokes the ready hint and signals the event loop (`persistentQueue.Add`, `varmq/persistent.go`); no polling on the hot path | 1 `LLEN` per second while the hint is dry (`resync`, `varmq/source.go`), so a second process's adds would be seen up to 1 s late; the subject runs 1 instance | consumer side 1 ack pipeline per job plus 1 pop script per k jobs, k = the free slots at each wake, at most min(workers, 64), sized by `popLen`; the first pass asks for the full credit and pops what is queued, later passes ask for what finished since (not measured); producer side 1 (`RPUSH`); not per job: 1 sweep script per second per queue object | `varmq.Job` JSON (`{id, status, data}`) wrapping the payload | `poolSize(workers)` via `pool_size` in the URL; acks use go-redis's pipeline pool, up to 10 at a time, the rest spill to the main pool | `concurrency = workers` (`varmq.NewWorker(fn, workers)`, `redis/varmq.go`), queue key `bench`, `WithAutoRun(false)` on the Enqueue-only producer; defaults kept: visibility timeout 5 min, heartbeat timeout 30 s, dedup window 5 min | -| Asynq | `EVALSHA` Lua scripts: dequeue (`RPOPLPUSH` pending to active, `HSET`/`HDEL`, `ZADD` lease, `HGET`), then done (`LREM`, `ZREM`, `DEL`, `INCR`/`GET`/`INCR`), 2 round trips | polling: no blocking pop, no push wake | `time.Sleep(TaskCheckInterval/2 + rand.N(TaskCheckInterval))` on an empty queue, `TaskCheckInterval` default 1 s, so 0.5 to 1.5 s; idle `Shutdown` waits out the current sleep | 2 consumer-side, 1 producer-side (plus 1 `SADD` per client) | protobuf `TaskMessage` wrapping the JSON payload, in a task hash | `poolSize(workers)` via `RedisClientOpt.PoolSize` | queue `bench`; defaults kept: retry 25, timeout 30 min, lease 30 s, no retention | -| VarMQDistributed | same pop script and ack pipeline as VarMQ, with the consumer id so a short pop on an empty queue joins `bench:idle` in the same script | push to one consumer per item: the enqueue script `SPOP`s `bench:idle` and `PUBLISH`es `enqueued` on `bench:wake:` (`listPushWake`, `redisq/distributed.go`); a 1 s `nudge` script per consumer re-delivers `enqueued` while items wait; sweep and `Close` wake for what they requeue | no polling on the hot path; the 1 s `nudge` script per consumer is a safety net for lost wakes; sweep script every 1 s per queue object; go-redis pub/sub `PING` every 3 s idle (`pubsub.go`, `initHealthCheck`) | consumer side 1 ack pipeline per job plus 1 pop script per k jobs, as VarMQ; producer side 1 script per job (`RPUSH` plus the wakes) | `varmq.Job` JSON wrapping the payload | `poolSize(workers)` via `pool_size` in the URL, `poolSize(0)` for the producer; pub/sub uses go-redis's own pub/sub pool; acks use its pipeline pool, up to 10 at a time, the rest spill to the main pool | `concurrency = workers` (`varmq.NewWorker(fn, workers)`, `redis/varmq_distributed.go`), queue key `bench`; defaults kept: visibility timeout 5 min, heartbeat timeout 30 s, dedup window 5 min | -| Rmq | `LREM unacked 1 ` per job (`redisDelivery.Ack`, `delivery.go`), 1 round trip; fetch is one `RPOPLPUSH` ready to unacked per job (`consumeBatch`, `queue.go`) | polling only: no blocking pop, no push | `time.Sleep(jitteredDuration(pollDuration))` after every fetch pass, +/-10% (90 to 110 ms at our setting), not only when empty; no back-off found in `consume` | 2 consumer-side (`RPOPLPUSH`, `LREM`) plus 1 `LLEN` per pass, 1 producer-side (`LPUSH`) | plain string payload (the JSON) | `poolSize(workers)` on our go-redis client (rmq does not create it) | poll duration 100 ms and prefetch limit `max(1000, 2*workers)`: rmq has no default for either; both follow `example/consumer/main.go` in rmq v5.2.0 (`prefetchLimit = 1000`, `pollDuration = 100 * time.Millisecond`), with the prefetch raised to 2 x workers because rmq's `README.md` says the prefetch limit should always be greater than the number of consumers; `consume` sleeps after every batch, so a connection is capped near prefetch / poll (about 10,000 jobs/s at 1000 / 100 ms; derived from `consume`, not measured); queue `bench`, tag `bench`; no cleaner | -| Taskq | `XACK`, then `XDEL`, run separately by the worker after the handler (`Queue.Delete`, `redisq/queue.go`), 2 round trips | blocking: `XREADGROUP ... BLOCK` by one fetcher per instance, woken by `XADD` | `WaitTimeout` 1 s: `redisq.NewQueue` sets it before the 10 s default in `QueueOptions.Init`; workers re-check an empty buffer every 1 s; 3 scheduler loops per queue sleep 1 to 1.5 s between passes; `Stop` waits out the fetcher's current block (up to 1 s) | 2 consumer-side (`XACK`, `XDEL`) plus 1 `XREADGROUP` per up to 10 jobs, 1 producer-side (`XADD`) | msgpack `Message` holding msgpack args holding the JSON payload as bytes, in the stream field `body` | `poolSize(workers)` on our go-redis v8 client (`Options.PoolSize`) | `MinNumWorker = MaxNumWorker = workers` (disables autotune, so one fetcher); defaults kept (all in `QueueOptions.Init`, `queue.go`, except as noted): `ReservationSize` 10, `BufferSize` = `ReservationSize`, `ReservationTimeout` 5 min, `WaitTimeout` 1 s (`redisq.NewQueue`, `redisq/queue.go`), retry limit 64 (`TaskOptions.init`, `task.go`); queue `bench`, task `bench`; handler always returns nil | -| GocraftWork | `LREM 1 ` in a `MULTI`/`EXEC` with `DECR lock` and `HINCRBY lock_info` (`removeJobFromInProgress`, `worker.go`), after the handler, 1 round trip; fetch is one Lua script (`redisLuaFetchJob`, `redis.go`) doing `RPOPLPUSH` to a per-pool in-progress list, 1 round trip | polling only: no blocking pop, no push | per-worker backoff `{0, 10, 100, 1000, 5000}` ms after consecutive empty fetches, reset to 0 by a job (`sleepBackoffsInMilliseconds`, `worker.loop`, `worker.go`); `Stop` does not wait out a sleep; other loops: observer 1 s per worker, heartbeat 5 s, requeuers 1 s, reaper first at 10 s then every 10 min, periodic enqueuer 2 min | 2 consumer-side (fetch script, `MULTI`/`EXEC`) plus 1 script per idle poll, 1 producer-side (`LPUSH`; plus at least 1 `SADD` per `Enqueuer`, one per concurrent first enqueue (8 and 10 seen in two runs with 100 producers), and again every 300 s) | JSON `Job` whose `args.p` holds the JSON payload as a string | `poolSize(workers)` for redigo `MaxActive` and `MaxIdle`, `Wait: true` (our choice) | none beyond pool size; `MaxFails` 4 and priority 1 stay at their defaults (`applyDefaultsAndValidate`, `worker_pool.go`) and are not reached because the handler returns nil; namespace `bench`, job `bench`; `logError` prints to stdout (`log.go`) and cannot be redirected | +`task redis:txt` runs the client with `taskset -c 0-13,16-23`, so Redis keeps core 14; compare runs on this setup only. diff --git a/sqlite/README.md b/sqlite/README.md index 9d4f7ca..787d20d 100644 --- a/sqlite/README.md +++ b/sqlite/README.md @@ -1,85 +1,77 @@ -# SQLite queue benchmarks +# SQLite message queue benchmarks -End-to-end benchmarks for [sqliteq](https://github.com/goptics/sqliteq) v0.3.0, -VarMQ's SQLite storage adapter. Jobs go in through a VarMQ persistent queue, a -worker runs them, and the benchmark waits until the queue is empty. Unlike -[redis/](../redis/README.md) there are no rival libraries, so the results show -how sqliteq behaves under different layouts and checkpoint sizes. +VarMQ with [sqliteq](https://github.com/goptics/sqliteq) against [goqite](https://github.com/maragudk/goqite), [backlite](https://github.com/mikestefanello/backlite) and [River](https://github.com/riverqueue/river)'s SQLite driver, end to end in one process. +Chart: https://benchmarks.goptics.org/?id=sqlite -It lives in its own Go module so sqliteq's cgo SQLite driver stays out of the -other modules. It needs a C compiler and nothing else. - -## Run - -```sh -task sqlite:test # vet and compile -task sqlite:bench # every scenario once -task sqlite:txt # full run into bench/sqlite.txt -``` +## Results -- `SQLITEQ_BENCH_DIR` is where the databases are created (default - `/varmq-bench-sqlite`). **Use a real disk.** Durable writes - pay for fsync, and `/tmp` is often a tmpfs where that cost vanishes. Each - iteration gets a fresh subdirectory and removes it afterwards. +Run of 2026-10-25: varmq 415ad73 (unreleased, `replace` in go.mod), sqliteq v0.3.0, goqite v0.4.0, backlite v0.8.0, River v0.49.0, `-benchtime=2x`, 32 rows in `bench/sqlite.txt`, ext4 over NVMe. jobs/s, higher is better; walMB is the peak WAL size, lower is better. + +| Scenario | Subject | ckpt1000 | ckpt10000 | walMB 1000 / 10000 | +|----------|---------|---------:|----------:|-------------------:| +| `Mixed1Q` | VarMQ | 6,265 | 12,439 | 4.2 / 41.2 | +| `Mixed1Q` | Goqite | 2,031 | 3,848 | 4.1 / 41.2 | +| `Mixed1Q` | Backlite | 267 | 153 | 200.2 / 140.2 | +| `Mixed1Q` | River | 1,302 | 2,404 | 4.2 / 41.3 | +| `Drain1Q` | VarMQ | 15,185 | 24,581 | 4.2 / 41.2 | +| `Drain1Q` | Goqite | 2,754 | 4,051 | 4.1 / 41.2 | +| `Drain1Q` | Backlite | 1,141 | 1,492 | 179.8 / 152.5 | +| `Drain1Q` | River | 3,137 | 3,671 | 4.3 / 41.4 | +| `DrainPrio` | VarMQ | 13,614 | 20,566 | 4.2 / 41.2 | +| `DrainPrio` | Goqite | 2,880 | 3,962 | 4.1 / 41.2 | +| `DrainPrio` | River | 3,101 | 3,554 | 4.5 / 41.4 | +| `Mixed10Q` | VarMQ | 30,560 | 103,728 | 4.1 / 39.3 | +| `Mixed10Q` | VarMQSingleFile | 4,445 | 11,226 | 4.2 / 41.3 | +| `Mixed10Q` | Goqite | 2,152 | 4,449 | 4.1 / 41.2 | +| `Mixed10Q` | Backlite | 4,864 | 5,362 | 367.9 / 369.9 | +| `Mixed10Q` | River | 660 | 1,105 | 4.3 / 41.3 | + +VarMQ is first in all 16 rows; on `Mixed1Q` at ckpt1000 it runs 3.1x goqite, 4.8x River and 23x backlite. A 10,000-page checkpoint is 1.1 to 3.4x faster than 1,000 for VarMQ, goqite and River at a WAL about ten times larger (39.3 to 41.4 MB against 4.1 to 4.5 MB); ten queues in separate files (VarMQ) run 6.9x and 9.2x the same ten in one file (VarMQSingleFile). Backlite's WAL peaks at 140 to 370 MB whatever the checkpoint size, and on `Mixed1Q` it is slower at the larger one. +Absolute numbers vary between runs on the same machine; compare ratios within one run. + +## Subjects + +| Subject | Library | Version | SQLite connections | Consumer | +|---------|---------|---------|--------------------|----------| +| VarMQ | sqliteq through a varmq worker | sqliteq v0.3.0, varmq 415ad73 | pool of 8 per file (sqliteq) | one database file per queue (sqliteq's default), 16 concurrent jobs per queue | +| VarMQSingleFile | same | same | same | every queue in one file (`WithSingleFile`); `Mixed10Q` only | +| Goqite | maragu.dev/goqite with its `jobs` runner | v0.4.0 | one (its README example) | one runner per queue, limit 16, 100 ms poll between empty receives | +| Backlite | mikestefanello/backlite | v0.8.0 | default pool, unbounded | one client, 16 workers per queue, dispatcher woken in-process on every add | +| River | riverqueue/river with riverdriver/riversqlite | v0.49.0 | one (its driver doc) | one client, 16 workers per queue, 1 ms fetch cooldown | + +Every subject opens SQLite with WAL, synchronous NORMAL, a 5 s busy timeout and the row's `wal_autocheckpoint`; everything else is the library default. The one forced setting is River's `FetchCooldown`: River fetches at most `MaxWorkers` jobs per cooldown, so its 100 ms default caps 16 workers at 160 jobs/s whatever the database does (measured 159); the 1 ms minimum lets SQLite set the number. ## Scenarios -Every job is an `int`; the worker handler does nothing and runs 16 jobs at a -time (`WithConcurrency(16)`). - -| Name | Queues | Producers per queue | Jobs | Timed | -|------|-------:|--------------------:|-----:|-------| -| `Mixed1Q` | 1 | 4 | 20,000 | first `Add` to `Wait`, producing and consuming at once | -| `Drain1Q` | 1 | 4 | 20,000 | worker paused, everything added, then `Resume` to `Wait` | -| `DrainPrio` | 1 | 4 | 10,000 | as `Drain1Q` on a priority queue, priority `i % 4` | -| `Mixed10Q` | 10 | 1 | 20,000 | as `Mixed1Q`, one worker per queue | +Every job is an `int`; the handler does nothing. -## Names and metrics +| Name | Queues | Producers per queue | Jobs | Timed | Subjects | +|------|-------:|--------------------:|-----:|-------|----------| +| `Mixed1Q` | 1 | 4 | 20,000 | first add to last job handled, producing and consuming at once | all | +| `Drain1Q` | 1 | 4 | 20,000 | everything added first, then consumer start to last job handled | all | +| `DrainPrio` | 1 | 4 | 10,000 | as `Drain1Q` on a priority queue, priority `i % 4` | VarMQ, Goqite, River | +| `Mixed10Q` | 10 | 1 | 20,000 | as `Mixed1Q` over ten queues, 16 workers each | all, plus VarMQSingleFile | -Row names are `BenchmarkSQLite///ckpt`, ten rows in all. +- Rows are named `BenchmarkSQLite//ckpt/`. +- `ckpt` is the WAL checkpoint size in pages, 1000 (SQLite's default) or 10000, set on every connection. +- `jobs/s` is the job count divided by the timed part; setup, teardown and the checks below are untimed. +- `walMB` is the largest size any `-wal` file in the run's directory reached, sampled every 50 ms, untimed phases included. +- A run fails if any add failed, the handler did not run exactly once per job, or rows remain in the queue tables. -- Layout `Folder` is one database file per queue; `SingleFile` is every queue - in one file. Only `Mixed10Q` runs both, since with one queue they are the - same thing; the others run `SingleFile`. -- `ckpt` is the WAL checkpoint size in pages, 1000 or 10000. -- `jobs/s` is the job count divided by the timed part. Setup, teardown and the - checks below are not timed. -- `walMB` is the largest size, in MB (10^6 bytes), that any one `-wal` file of - the run reached. A goroutine reads the size of every `-wal` file in the run's - directory every 50 ms, from the store's opening until just before it closes, - so a drain row includes its untimed adding phase. With several iterations the - largest peak is reported. A peak that lasts under 50 ms can be missed. +## Running -After `Wait`, a run fails if any `Add` returned false, if the handler ran a -different number of times than jobs were added, or if any row is still in a -queue table (counted with `database/sql`, not through sqliteq). A lost or stuck -job therefore fails the benchmark instead of making it look fast. +Needs Go 1.26 and a C compiler. -## Dataset on the site +```sh +task sqlite:test # vet, then every subject through a small job set +task sqlite:bench # every scenario and subject once +task sqlite:txt # full run into bench/sqlite.txt (about 20 min) +``` -`bench/sqlite.txt` becomes the `sqlite-persistent` dataset: groups are the -scenarios, the y axis is the layout and the x axis is the checkpoint size. -`walMB` is marked lower-is-better. +One slice: -## Results +```sh +go test -run xxx -bench 'SQLite/Mixed10Q' -benchtime=1x +``` -`bench/sqlite.txt` is one run from 2026-10-24: varmq 415ad73 (unreleased, -through the `replace` directive in `go.mod`), sqliteq v0.3.0, `-benchtime=2x`, -default CPUs, ext4 over NVMe. jobs/s, higher is better; `walMB` is the peak -WAL size. - -| Scenario | Layout | ckpt1000 | ckpt10000 | walMB 1000 / 10000 | -|----------|--------|---------:|----------:|-------------------:| -| `Mixed1Q` | SingleFile | 6,579 | 9,640 | 4.2 / 41.2 | -| `Drain1Q` | SingleFile | 12,397 | 17,577 | 4.2 / 41.2 | -| `DrainPrio` | SingleFile | 11,027 | 16,918 | 4.2 / 41.2 | -| `Mixed10Q` | SingleFile | 4,290 | 8,678 | 4.2 / 41.3 | -| `Mixed10Q` | Folder | 22,675 | 34,935 | 4.1 / 39.4 | - -A 10,000-page checkpoint runs 1.4 to 2.0x faster than the 1,000-page default -and holds a WAL about ten times larger (41 MB against 4 MB at this payload). -Ten queues in separate files run 4 to 5x faster than the same ten in one -file, which fits SQLite allowing one writer per database file. Two runs an -hour apart on the same machine differed by up to 2x on the ckpt10000 rows, so -read the ratios, not the absolute numbers, and compare runs on the same machine -only. +`SQLITEQ_BENCH_DIR` is where the databases are created (default `/varmq-bench-sqlite`). Use a real disk: durable writes pay for fsync, and `/tmp` is often a tmpfs where that cost vanishes. diff --git a/worker/README.md b/worker/README.md new file mode 100644 index 0000000..5bb0e4a --- /dev/null +++ b/worker/README.md @@ -0,0 +1,15 @@ +# Worker + +Cloudflare Worker that serves the dashboard and the dataset JSON at https://benchmarks.goptics.org from Workers Static Assets. `public/` is build output (`task site:build`) and gitignored. + +| URL | Serves | +|-----|--------| +| `/` | The dashboard; loads the catalog, then the first dataset | +| `/?id=` | The dashboard with one dataset selected | +| `/` | One dataset, no switcher | +| `/dataset` | The catalog, `[{id, name}]` in dashboard order | +| `/dataset/` | One dataset as JSON | + +Local: `task site:dev` builds against `http://localhost:8787/dataset` and runs `wrangler dev` (needs Node). `task site:deploy` rebuilds for production and deploys. + +CI ([.github/workflows/site.yml](../.github/workflows/site.yml)) builds on every pull request and deploys on pushes to `main`, with two repository secrets: `CLOUDFLARE_API_TOKEN` (Workers Scripts: Edit, plus Zone goptics.org: DNS Edit and Workers Routes Edit for the custom domain) and `CLOUDFLARE_ACCOUNT_ID`. From 59f7000347d2c98341e1f53524434fc1e27e9ab8 Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 04:46:16 +0600 Subject: [PATCH 6/9] feat(redis): full rerun with rmq polling every 1 ms, 2026-10-25 150 rows, -benchtime=2x, same pinned setup as the first run. rmq moves from 5.9k to 10.3k jobs/s at C1 to 27k to 33k and leads every single-producer Noop row; its pickup latency drops from 102 ms to 1.5 ms. README tables and the root headline regenerated from the file. Co-Authored-By: Claude Fable 5.1 --- README.md | 8 +- redis/README.md | 45 +++---- redis/bench/redis.txt | 302 +++++++++++++++++++++--------------------- 3 files changed, 177 insertions(+), 178 deletions(-) diff --git a/README.md b/README.md index fd7c547..5a96203 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,15 @@ Benchmark suites for [VarMQ](https://github.com/goptics/varmq) against other Go ## Results -Pool and Redis runs of 2026-10-24, SQLite run of 2026-10-25, all `-benchtime=2x`. Full tables in the suite READMEs. +Pool run of 2026-10-24, Redis and SQLite runs of 2026-10-25, all `-benchtime=2x`. Full tables in the suite READMEs. -- Pool: VarMQ is the fastest subject in 40, 36 and 20 of the 55 rows at 24, 8 and 4 CPUs. It is slower than the buffered-channel baseline on the one-worker `Loop10` rows. -- Redis: with the `Noop` task, VarMQ is first in 2 of the 6 one-process rows and VarMQDistributed in 3 of the 6 four-process rows, every win with 100 producers; gocraft/work leads the single-producer rows. Pickup latency p50: taskq 0.063 ms, VarMQ 0.142 ms, rmq 102.2 ms, Asynq 995.3 ms. +- Pool: VarMQ is the fastest subject in 40, 36 and 20 of the 55 rows at 24, 8 and 4 CPUs. It is slower than the buffered-channel baseline on the one-worker `Loop10` rows, except `1Mu-1t`, where the two are level. +- Redis: with the `Noop` task, VarMQ is first in 2 of the 6 one-process rows and VarMQDistributed in 2 of the 6 four-process rows, all at 100 producers; rmq leads every single-producer row. Pickup latency p50: taskq 0.03876 ms, VarMQDistributed 0.06492 ms, VarMQ 0.09407 ms, rmq 1.464 ms, Asynq 979.7 ms. - SQLite: VarMQ (sqliteq) is first in all 16 rows: on `Mixed1Q` at ckpt1000 it runs 3.1x goqite, 4.8x River and 23x backlite, and ten queues in separate files reach 103,728 jobs/s at ckpt10000. ## Environment -Intel Core i7-13700 (24 threads), linux/amd64, Go 1.26.2. Pool suite at GOMAXPROCS 24, 8 and 4. Redis 7.2 (Debian image) pinned to CPU 14, client on the other cores. SQLite databases on ext4 over NVMe. +Intel Core i7-13700 (24 threads), linux/amd64, Go 1.26.2. Pool suite at GOMAXPROCS 24, 8 and 4. Redis 7.2 (Debian image) pinned to CPU 14, client on cores 0-13 and 16-23. SQLite databases on ext4 over NVMe. | Library | Version | |---------|---------| diff --git a/redis/README.md b/redis/README.md index 130de0c..2a3f99d 100644 --- a/redis/README.md +++ b/redis/README.md @@ -5,47 +5,46 @@ Chart: https://benchmarks.goptics.org/?id=redis ## Results -Run of 2026-10-24: varmq 415ad73 (unreleased, `replace` in go.mod), redisq v1.5.0, `-benchtime=2x`, Redis 7.2 (Debian image) pinned to one core, 150 rows in `bench/redis.txt`. +Run of 2026-10-25: varmq 415ad73 (unreleased, `replace` in go.mod), redisq v1.5.0, `-benchtime=2x`, Redis 7.2 (Debian image) pinned to one core, 150 rows in `bench/redis.txt`. `C1`: jobs/s, `Noop` task, one consumer process. | Row | VarMQ | Asynq | Rmq | Taskq | GocraftWork | |---|---:|---:|---:|---:|---:| -| NoopW10C1 / 1u-100Kt | 21,459 | 15,988 | 6,195 | 18,963 | 25,057 | -| NoopW10C1 / 100u-1Kt | 41,972 | 18,030 | 5,933 | 35,648 | 49,503 | -| NoopW100C1 / 1u-100Kt | 20,859 | 16,978 | 6,129 | 18,439 | 25,315 | -| NoopW100C1 / 100u-1Kt | 60,551 | 19,828 | 5,859 | 35,560 | 45,110 | -| NoopW1000C1 / 1u-100Kt | 21,027 | 15,484 | 10,271 | 16,939 | 24,912 | -| NoopW1000C1 / 100u-1Kt | 59,182 | 18,693 | 9,317 | 28,531 | 40,710 | +| NoopW10C1 / 1u-100Kt | 21,108 | 15,390 | 33,195 | 18,853 | 24,935 | +| NoopW10C1 / 100u-1Kt | 41,970 | 17,604 | 28,880 | 34,628 | 49,213 | +| NoopW100C1 / 1u-100Kt | 20,665 | 17,048 | 33,439 | 18,352 | 24,990 | +| NoopW100C1 / 100u-1Kt | 60,025 | 19,439 | 29,022 | 34,578 | 44,659 | +| NoopW1000C1 / 1u-100Kt | 19,710 | 16,467 | 32,678 | 16,674 | 24,408 | +| NoopW1000C1 / 100u-1Kt | 58,523 | 17,932 | 27,349 | 28,638 | 40,679 | `C4`: jobs/s, `Noop` task, four consumer processes. | Row | VarMQDistributed | Asynq | Rmq | Taskq | GocraftWork | |---|---:|---:|---:|---:|---:| -| NoopW10C4 / 1u-100Kt | 21,946 | 13,057 | 21,816 | 10,968 | 25,650 | -| NoopW10C4 / 100u-1Kt | 55,294 | 19,377 | 16,459 | 17,191 | 48,839 | -| NoopW100C4 / 1u-100Kt | 22,484 | 13,135 | 22,400 | 10,629 | 25,512 | -| NoopW100C4 / 100u-1Kt | 65,606 | 21,198 | 16,889 | 16,018 | 43,263 | -| NoopW1000C4 / 1u-100Kt | 22,347 | 14,519 | 23,041 | 7,663 | 19,542 | -| NoopW1000C4 / 100u-1Kt | 64,993 | 16,488 | 25,137 | 11,377 | 32,672 | +| NoopW10C4 / 1u-100Kt | 22,057 | 11,896 | 29,616 | 10,904 | 24,339 | +| NoopW10C4 / 100u-1Kt | 53,754 | 20,889 | 59,649 | 17,323 | 48,722 | +| NoopW100C4 / 1u-100Kt | 22,263 | 13,350 | 29,953 | 10,576 | 23,683 | +| NoopW100C4 / 100u-1Kt | 63,710 | 22,677 | 58,620 | 16,077 | 41,730 | +| NoopW1000C4 / 1u-100Kt | 22,231 | 12,747 | 27,784 | 8,267 | 21,068 | +| NoopW1000C4 / 100u-1Kt | 64,281 | 19,119 | 52,549 | 11,100 | 36,809 | `Sleep1ms` rows are bound by workers x 1 ms and are only on the chart. -Enqueue only (`BenchmarkEnqueue`, jobs/s): VarMQ 42,867 at one producer, the best of the six; at 100 producers Rmq 202,068, GocraftWork 201,297 and VarMQ 201,078 tie, and VarMQDistributed trails at 143,183. +Enqueue only (`BenchmarkEnqueue`, jobs/s): at one producer VarMQ 37,292, Rmq 33,394, GocraftWork 29,720, VarMQDistributed 27,183, Taskq 26,780, Asynq 24,023; at 100 producers VarMQ 207,752, GocraftWork 202,835, Rmq 197,240, Taskq 188,437, VarMQDistributed 144,838, Asynq 121,046. Pickup latency (`BenchmarkLatency`, 1,000 jobs one at a time, ms): | Subject | p50 | p99 | max | |---|---|---|---| -| Taskq | 0.06330 | 0.1897 | 0.6119 | -| GocraftWork | 0.09234 | 0.4743 | 10.80 | -| VarMQ | 0.1425 | 0.3843 | 3.583 | -| VarMQDistributed | 0.1457 | 0.5407 | 2.183 | -| Rmq | 102.2 | 112.3 | 113.3 | -| Asynq | 995.3 | 1492 | 1507 | - -Rmq's 100 ms poll and Asynq's 0.5 to 1.5 s idle sleep show directly. VarMQ's -batch pop p50 is 0.1425 ms against Taskq's 0.06330 ms for its blocking `XREADGROUP`. +| Taskq | 0.03876 | 0.1623 | 3.195 | +| VarMQDistributed | 0.06492 | 0.2351 | 2.436 | +| VarMQ | 0.09407 | 0.5321 | 3.431 | +| GocraftWork | 0.1274 | 0.5047 | 10.94 | +| Rmq | 1.464 | 2.891 | 6.902 | +| Asynq | 979.7 | 1491 | 1501 | + +Asynq's 0.5 to 1.5 s idle sleep shows directly, and rmq's 1 ms poll puts it at 1.464 ms. Taskq's blocking `XREADGROUP` is the fastest pickup at 0.03876 ms; VarMQ's batch pop is at 0.09407 ms and VarMQDistributed's push wake at 0.06492 ms. In `C4` rows the four instances are stopped one after another inside the timed region, so Asynq and Taskq pay their idle poll up to four times. diff --git a/redis/bench/redis.txt b/redis/bench/redis.txt index 0de8b63..13d4094 100644 --- a/redis/bench/redis.txt +++ b/redis/bench/redis.txt @@ -2,155 +2,155 @@ goos: linux goarch: amd64 pkg: github.com/goptics/benchmarks/redis cpu: 13th Gen Intel(R) Core(TM) i7-13700 -BenchmarkDurable/NoopW10C1/1u-100Kt/VarMQ-22 2 4660138216 ns/op 21459 jobs/s 341970780 B/op 8050450 allocs/op -BenchmarkDurable/NoopW10C1/1u-100Kt/Asynq-22 2 6254632532 ns/op 15988 jobs/s 619451756 B/op 10710585 allocs/op -BenchmarkDurable/NoopW10C1/1u-100Kt/VarMQDistributed-22 2 4760586681 ns/op 21006 jobs/s 372611672 B/op 8855654 allocs/op -BenchmarkDurable/NoopW10C1/1u-100Kt/Rmq-22 2 16140937250 ns/op 6195 jobs/s 186486828 B/op 3606014 allocs/op -BenchmarkDurable/NoopW10C1/1u-100Kt/Taskq-22 2 5273383156 ns/op 18963 jobs/s 563257368 B/op 9554556 allocs/op -BenchmarkDurable/NoopW10C1/1u-100Kt/GocraftWork-22 2 3990879753 ns/op 25057 jobs/s 465620900 B/op 8559079 allocs/op -BenchmarkDurable/NoopW10C1/100u-1Kt/VarMQ-22 2 2382556832 ns/op 41972 jobs/s 272205268 B/op 5808170 allocs/op -BenchmarkDurable/NoopW10C1/100u-1Kt/Asynq-22 2 5546432302 ns/op 18030 jobs/s 624823420 B/op 10718085 allocs/op -BenchmarkDurable/NoopW10C1/100u-1Kt/VarMQDistributed-22 2 2530875355 ns/op 39512 jobs/s 301576840 B/op 6527396 allocs/op -BenchmarkDurable/NoopW10C1/100u-1Kt/Rmq-22 2 16855669360 ns/op 5933 jobs/s 193368184 B/op 3618965 allocs/op -BenchmarkDurable/NoopW10C1/100u-1Kt/Taskq-22 2 2805170852 ns/op 35648 jobs/s 493553924 B/op 7909298 allocs/op -BenchmarkDurable/NoopW10C1/100u-1Kt/GocraftWork-22 2 2020064260 ns/op 49503 jobs/s 464611588 B/op 8612467 allocs/op -BenchmarkDurable/NoopW10C4/1u-100Kt/Asynq-22 2 7659010916 ns/op 13057 jobs/s 620344536 B/op 10713142 allocs/op -BenchmarkDurable/NoopW10C4/1u-100Kt/VarMQDistributed-22 2 4556737486 ns/op 21946 jobs/s 466225080 B/op 11613077 allocs/op -BenchmarkDurable/NoopW10C4/1u-100Kt/Rmq-22 2 4583724296 ns/op 21816 jobs/s 188107792 B/op 3609605 allocs/op -BenchmarkDurable/NoopW10C4/1u-100Kt/Taskq-22 2 9117086182 ns/op 10968 jobs/s 560283404 B/op 9624622 allocs/op -BenchmarkDurable/NoopW10C4/1u-100Kt/GocraftWork-22 2 3898627187 ns/op 25650 jobs/s 466574524 B/op 8593932 allocs/op -BenchmarkDurable/NoopW10C4/100u-1Kt/Asynq-22 2 5160755838 ns/op 19377 jobs/s 626413060 B/op 10721929 allocs/op -BenchmarkDurable/NoopW10C4/100u-1Kt/VarMQDistributed-22 2 1808504742 ns/op 55294 jobs/s 309991992 B/op 6504471 allocs/op -BenchmarkDurable/NoopW10C4/100u-1Kt/Rmq-22 2 6075652520 ns/op 16459 jobs/s 194704272 B/op 3621811 allocs/op -BenchmarkDurable/NoopW10C4/100u-1Kt/Taskq-22 2 5817066848 ns/op 17191 jobs/s 492643232 B/op 7911916 allocs/op -BenchmarkDurable/NoopW10C4/100u-1Kt/GocraftWork-22 2 2047538030 ns/op 48839 jobs/s 465169076 B/op 8617294 allocs/op -BenchmarkDurable/NoopW100C1/1u-100Kt/VarMQ-22 2 4794078386 ns/op 20859 jobs/s 342034268 B/op 8073940 allocs/op -BenchmarkDurable/NoopW100C1/1u-100Kt/Asynq-22 2 5889967712 ns/op 16978 jobs/s 618914556 B/op 10708204 allocs/op -BenchmarkDurable/NoopW100C1/1u-100Kt/VarMQDistributed-22 2 4681586288 ns/op 21360 jobs/s 373718500 B/op 8873048 allocs/op -BenchmarkDurable/NoopW100C1/1u-100Kt/Rmq-22 2 16316678295 ns/op 6129 jobs/s 186544472 B/op 3607186 allocs/op -BenchmarkDurable/NoopW100C1/1u-100Kt/Taskq-22 2 5423331751 ns/op 18439 jobs/s 563100892 B/op 9554740 allocs/op -BenchmarkDurable/NoopW100C1/1u-100Kt/GocraftWork-22 2 3950294246 ns/op 25315 jobs/s 469507828 B/op 8628049 allocs/op -BenchmarkDurable/NoopW100C1/100u-1Kt/VarMQ-22 2 1651498950 ns/op 60551 jobs/s 252967448 B/op 5091237 allocs/op -BenchmarkDurable/NoopW100C1/100u-1Kt/Asynq-22 2 5043473432 ns/op 19828 jobs/s 624761552 B/op 10717897 allocs/op -BenchmarkDurable/NoopW100C1/100u-1Kt/VarMQDistributed-22 2 1821080060 ns/op 54912 jobs/s 283038844 B/op 5795919 allocs/op -BenchmarkDurable/NoopW100C1/100u-1Kt/Rmq-22 2 17068249388 ns/op 5859 jobs/s 193402076 B/op 3620288 allocs/op -BenchmarkDurable/NoopW100C1/100u-1Kt/Taskq-22 2 2812115118 ns/op 35560 jobs/s 495896112 B/op 7912688 allocs/op -BenchmarkDurable/NoopW100C1/100u-1Kt/GocraftWork-22 2 2216823090 ns/op 45110 jobs/s 468298980 B/op 8628288 allocs/op -BenchmarkDurable/NoopW100C4/1u-100Kt/Asynq-22 2 7613365668 ns/op 13135 jobs/s 620267520 B/op 10712920 allocs/op -BenchmarkDurable/NoopW100C4/1u-100Kt/VarMQDistributed-22 2 4447665626 ns/op 22484 jobs/s 466069140 B/op 11611854 allocs/op -BenchmarkDurable/NoopW100C4/1u-100Kt/Rmq-22 2 4464379980 ns/op 22400 jobs/s 188468272 B/op 3615649 allocs/op -BenchmarkDurable/NoopW100C4/1u-100Kt/Taskq-22 2 9408326273 ns/op 10629 jobs/s 561641016 B/op 9629614 allocs/op -BenchmarkDurable/NoopW100C4/1u-100Kt/GocraftWork-22 2 3919793386 ns/op 25512 jobs/s 477637056 B/op 8680958 allocs/op -BenchmarkDurable/NoopW100C4/100u-1Kt/Asynq-22 2 4717378588 ns/op 21198 jobs/s 626365468 B/op 10721667 allocs/op -BenchmarkDurable/NoopW100C4/100u-1Kt/VarMQDistributed-22 2 1524251192 ns/op 65606 jobs/s 313615728 B/op 5977815 allocs/op -BenchmarkDurable/NoopW100C4/100u-1Kt/Rmq-22 2 5921019568 ns/op 16889 jobs/s 195142320 B/op 3627461 allocs/op -BenchmarkDurable/NoopW100C4/100u-1Kt/Taskq-22 2 6242838893 ns/op 16018 jobs/s 492062196 B/op 7916362 allocs/op -BenchmarkDurable/NoopW100C4/100u-1Kt/GocraftWork-22 2 2311448048 ns/op 43263 jobs/s 478617656 B/op 8620196 allocs/op -BenchmarkDurable/NoopW1000C1/1u-100Kt/VarMQ-22 2 4755794292 ns/op 21027 jobs/s 341894300 B/op 8064427 allocs/op -BenchmarkDurable/NoopW1000C1/1u-100Kt/Asynq-22 2 6458217219 ns/op 15484 jobs/s 619055228 B/op 10706891 allocs/op -BenchmarkDurable/NoopW1000C1/1u-100Kt/VarMQDistributed-22 2 4690984052 ns/op 21317 jobs/s 374191276 B/op 8881169 allocs/op -BenchmarkDurable/NoopW1000C1/1u-100Kt/Rmq-22 2 9736617143 ns/op 10271 jobs/s 188602416 B/op 3623251 allocs/op -BenchmarkDurable/NoopW1000C1/1u-100Kt/Taskq-22 2 5903633940 ns/op 16939 jobs/s 558403808 B/op 9550894 allocs/op -BenchmarkDurable/NoopW1000C1/1u-100Kt/GocraftWork-22 2 4014070310 ns/op 24912 jobs/s 493408596 B/op 8762806 allocs/op -BenchmarkDurable/NoopW1000C1/100u-1Kt/VarMQ-22 2 1689692550 ns/op 59182 jobs/s 254575644 B/op 5086733 allocs/op -BenchmarkDurable/NoopW1000C1/100u-1Kt/Asynq-22 2 5349566296 ns/op 18693 jobs/s 625184892 B/op 10717725 allocs/op -BenchmarkDurable/NoopW1000C1/100u-1Kt/VarMQDistributed-22 2 1799143516 ns/op 55582 jobs/s 284194840 B/op 5790297 allocs/op -BenchmarkDurable/NoopW1000C1/100u-1Kt/Rmq-22 2 10732525464 ns/op 9317 jobs/s 194564512 B/op 3633891 allocs/op -BenchmarkDurable/NoopW1000C1/100u-1Kt/Taskq-22 2 3505002214 ns/op 28531 jobs/s 491325160 B/op 7910658 allocs/op -BenchmarkDurable/NoopW1000C1/100u-1Kt/GocraftWork-22 2 2456385560 ns/op 40710 jobs/s 492562652 B/op 8701017 allocs/op -BenchmarkDurable/NoopW1000C4/1u-100Kt/Asynq-22 2 6887565968 ns/op 14519 jobs/s 621648720 B/op 10710477 allocs/op -BenchmarkDurable/NoopW1000C4/1u-100Kt/VarMQDistributed-22 2 4474889088 ns/op 22347 jobs/s 467041912 B/op 11605436 allocs/op -BenchmarkDurable/NoopW1000C4/1u-100Kt/Rmq-22 2 4340041156 ns/op 23041 jobs/s 193136380 B/op 3675198 allocs/op -BenchmarkDurable/NoopW1000C4/1u-100Kt/Taskq-22 2 13050093492 ns/op 7663 jobs/s 557707020 B/op 9638354 allocs/op -BenchmarkDurable/NoopW1000C4/1u-100Kt/GocraftWork-22 2 5117109332 ns/op 19542 jobs/s 582255088 B/op 9256869 allocs/op -BenchmarkDurable/NoopW1000C4/100u-1Kt/Asynq-22 2 6065173054 ns/op 16488 jobs/s 628754844 B/op 10722390 allocs/op -BenchmarkDurable/NoopW1000C4/100u-1Kt/VarMQDistributed-22 2 1538623278 ns/op 64993 jobs/s 317572140 B/op 5987060 allocs/op -BenchmarkDurable/NoopW1000C4/100u-1Kt/Rmq-22 2 3978273324 ns/op 25137 jobs/s 199570512 B/op 3682592 allocs/op -BenchmarkDurable/NoopW1000C4/100u-1Kt/Taskq-22 2 8789774646 ns/op 11377 jobs/s 490088456 B/op 7934199 allocs/op -BenchmarkDurable/NoopW1000C4/100u-1Kt/GocraftWork-22 2 3060691912 ns/op 32672 jobs/s 579524248 B/op 9170004 allocs/op -BenchmarkDurable/Sleep1msW10C1/1u-100Kt/VarMQ-22 2 16643942770 ns/op 6008 jobs/s 295160040 B/op 6718560 allocs/op -BenchmarkDurable/Sleep1msW10C1/1u-100Kt/Asynq-22 2 18417404712 ns/op 5430 jobs/s 628565024 B/op 10809109 allocs/op -BenchmarkDurable/Sleep1msW10C1/1u-100Kt/VarMQDistributed-22 2 16874262141 ns/op 5926 jobs/s 322420828 B/op 7383057 allocs/op -BenchmarkDurable/Sleep1msW10C1/1u-100Kt/Rmq-22 2 17209670053 ns/op 5811 jobs/s 186697376 B/op 3605568 allocs/op -BenchmarkDurable/Sleep1msW10C1/1u-100Kt/Taskq-22 2 16610113127 ns/op 6020 jobs/s 488904832 B/op 7905780 allocs/op -BenchmarkDurable/Sleep1msW10C1/1u-100Kt/GocraftWork-22 2 16717330972 ns/op 5982 jobs/s 462102976 B/op 8607628 allocs/op -BenchmarkDurable/Sleep1msW10C1/100u-1Kt/VarMQ-22 2 20223700824 ns/op 4945 jobs/s 274352292 B/op 5887699 allocs/op -BenchmarkDurable/Sleep1msW10C1/100u-1Kt/Asynq-22 2 20003021726 ns/op 4999 jobs/s 635266188 B/op 10821824 allocs/op -BenchmarkDurable/Sleep1msW10C1/100u-1Kt/VarMQDistributed-22 2 20758417156 ns/op 4817 jobs/s 303251040 B/op 6591055 allocs/op -BenchmarkDurable/Sleep1msW10C1/100u-1Kt/Rmq-22 2 21803618795 ns/op 4586 jobs/s 193706736 B/op 3619736 allocs/op -BenchmarkDurable/Sleep1msW10C1/100u-1Kt/Taskq-22 2 19506354846 ns/op 5127 jobs/s 489174716 B/op 7907319 allocs/op -BenchmarkDurable/Sleep1msW10C1/100u-1Kt/GocraftWork-22 2 18989631297 ns/op 5266 jobs/s 463470924 B/op 8611652 allocs/op -BenchmarkDurable/Sleep1msW10C4/1u-100Kt/Asynq-22 2 7012835107 ns/op 14260 jobs/s 631919704 B/op 10818480 allocs/op -BenchmarkDurable/Sleep1msW10C4/1u-100Kt/VarMQDistributed-22 2 4563259863 ns/op 21914 jobs/s 480222500 B/op 11851642 allocs/op -BenchmarkDurable/Sleep1msW10C4/1u-100Kt/Rmq-22 2 3688909585 ns/op 27108 jobs/s 189686824 B/op 3611543 allocs/op -BenchmarkDurable/Sleep1msW10C4/1u-100Kt/Taskq-22 2 9083554352 ns/op 11009 jobs/s 558646056 B/op 9622804 allocs/op -BenchmarkDurable/Sleep1msW10C4/1u-100Kt/GocraftWork-22 2 3666089961 ns/op 27277 jobs/s 463776852 B/op 8557982 allocs/op -BenchmarkDurable/Sleep1msW10C4/100u-1Kt/Asynq-22 2 8528030540 ns/op 11726 jobs/s 638238008 B/op 10828737 allocs/op -BenchmarkDurable/Sleep1msW10C4/100u-1Kt/VarMQDistributed-22 2 5045046645 ns/op 19821 jobs/s 332798904 B/op 7215201 allocs/op -BenchmarkDurable/Sleep1msW10C4/100u-1Kt/Rmq-22 2 5382100096 ns/op 18580 jobs/s 196635944 B/op 3625114 allocs/op -BenchmarkDurable/Sleep1msW10C4/100u-1Kt/Taskq-22 2 9077449858 ns/op 11016 jobs/s 489692632 B/op 7911058 allocs/op -BenchmarkDurable/Sleep1msW10C4/100u-1Kt/GocraftWork-22 2 5506263562 ns/op 18161 jobs/s 464862984 B/op 8619113 allocs/op -BenchmarkDurable/Sleep1msW100C1/1u-100Kt/VarMQ-22 2 4557653314 ns/op 21941 jobs/s 340412832 B/op 7924454 allocs/op -BenchmarkDurable/Sleep1msW100C1/1u-100Kt/Asynq-22 2 5977082705 ns/op 16731 jobs/s 630095824 B/op 10813508 allocs/op -BenchmarkDurable/Sleep1msW100C1/1u-100Kt/VarMQDistributed-22 2 4684417872 ns/op 21347 jobs/s 372092712 B/op 8740852 allocs/op -BenchmarkDurable/Sleep1msW100C1/1u-100Kt/Rmq-22 2 18963055915 ns/op 5273 jobs/s 188997796 B/op 3611962 allocs/op -BenchmarkDurable/Sleep1msW100C1/1u-100Kt/Taskq-22 2 5192678320 ns/op 19258 jobs/s 554622740 B/op 9498814 allocs/op -BenchmarkDurable/Sleep1msW100C1/1u-100Kt/GocraftWork-22 2 3887319798 ns/op 25725 jobs/s 473665032 B/op 8763470 allocs/op -BenchmarkDurable/Sleep1msW100C1/100u-1Kt/VarMQ-22 2 2139577707 ns/op 46738 jobs/s 256403348 B/op 5197319 allocs/op -BenchmarkDurable/Sleep1msW100C1/100u-1Kt/Asynq-22 2 5396639856 ns/op 18530 jobs/s 636382528 B/op 10823905 allocs/op -BenchmarkDurable/Sleep1msW100C1/100u-1Kt/VarMQDistributed-22 2 2304332544 ns/op 43397 jobs/s 286540704 B/op 5901736 allocs/op -BenchmarkDurable/Sleep1msW100C1/100u-1Kt/Rmq-22 2 20059464481 ns/op 4985 jobs/s 196514200 B/op 3626616 allocs/op -BenchmarkDurable/Sleep1msW100C1/100u-1Kt/Taskq-22 2 3557707562 ns/op 28108 jobs/s 490732132 B/op 7909131 allocs/op -BenchmarkDurable/Sleep1msW100C1/100u-1Kt/GocraftWork-22 2 2227034738 ns/op 44903 jobs/s 467811520 B/op 8627337 allocs/op -BenchmarkDurable/Sleep1msW100C4/1u-100Kt/Asynq-22 2 7240356190 ns/op 13811 jobs/s 634489344 B/op 10822917 allocs/op -BenchmarkDurable/Sleep1msW100C4/1u-100Kt/VarMQDistributed-22 2 4556859994 ns/op 21945 jobs/s 475020660 B/op 11728013 allocs/op -BenchmarkDurable/Sleep1msW100C4/1u-100Kt/Rmq-22 2 4300819781 ns/op 23251 jobs/s 194323220 B/op 3626478 allocs/op -BenchmarkDurable/Sleep1msW100C4/1u-100Kt/Taskq-22 2 9429194839 ns/op 10605 jobs/s 558514160 B/op 9624120 allocs/op -BenchmarkDurable/Sleep1msW100C4/1u-100Kt/GocraftWork-22 2 4063563170 ns/op 24609 jobs/s 488757272 B/op 8985640 allocs/op -BenchmarkDurable/Sleep1msW100C4/100u-1Kt/Asynq-22 2 5239620461 ns/op 19085 jobs/s 639633996 B/op 10830687 allocs/op -BenchmarkDurable/Sleep1msW100C4/100u-1Kt/VarMQDistributed-22 2 1524584969 ns/op 65592 jobs/s 319547608 B/op 6015097 allocs/op -BenchmarkDurable/Sleep1msW100C4/100u-1Kt/Rmq-22 2 5898368070 ns/op 16954 jobs/s 202651212 B/op 3642513 allocs/op -BenchmarkDurable/Sleep1msW100C4/100u-1Kt/Taskq-22 2 6171626708 ns/op 16203 jobs/s 491739076 B/op 7926330 allocs/op -BenchmarkDurable/Sleep1msW100C4/100u-1Kt/GocraftWork-22 2 2386187782 ns/op 41908 jobs/s 481367020 B/op 8678739 allocs/op -BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/VarMQ-22 2 4555447100 ns/op 21952 jobs/s 340801044 B/op 7926812 allocs/op -BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/Asynq-22 2 5947630838 ns/op 16813 jobs/s 630423816 B/op 10812722 allocs/op -BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/VarMQDistributed-22 2 4591782780 ns/op 21778 jobs/s 373138592 B/op 8753765 allocs/op -BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/Rmq-22 2 11494451908 ns/op 8700 jobs/s 190112508 B/op 3625866 allocs/op -BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/Taskq-22 2 6155874342 ns/op 16245 jobs/s 553025016 B/op 9496302 allocs/op -BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/GocraftWork-22 2 4037605520 ns/op 24767 jobs/s 503046624 B/op 8998504 allocs/op -BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/VarMQ-22 2 1309555424 ns/op 76362 jobs/s 257743648 B/op 5093603 allocs/op -BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/Asynq-22 2 5716113041 ns/op 17494 jobs/s 637217912 B/op 10825879 allocs/op -BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/VarMQDistributed-22 2 1508183506 ns/op 66305 jobs/s 289225692 B/op 5800515 allocs/op -BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/Rmq-22 2 13060444879 ns/op 7657 jobs/s 197131604 B/op 3639473 allocs/op -BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/Taskq-22 2 3618938928 ns/op 27632 jobs/s 490821488 B/op 7918685 allocs/op -BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/GocraftWork-22 2 2673733311 ns/op 37401 jobs/s 496178008 B/op 8817710 allocs/op -BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/Asynq-22 2 6862344362 ns/op 14572 jobs/s 634505480 B/op 10818596 allocs/op -BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/VarMQDistributed-22 2 4548695022 ns/op 21984 jobs/s 477146296 B/op 11727409 allocs/op -BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/Rmq-22 2 3617738874 ns/op 27642 jobs/s 196878632 B/op 3684994 allocs/op -BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/Taskq-22 2 12424276828 ns/op 8049 jobs/s 557853024 B/op 9642113 allocs/op -BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/GocraftWork-22 2 5298705130 ns/op 18873 jobs/s 594248236 B/op 9599640 allocs/op -BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/Asynq-22 2 5461390939 ns/op 18310 jobs/s 641290840 B/op 10829984 allocs/op -BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/VarMQDistributed-22 2 1541417678 ns/op 64875 jobs/s 337269972 B/op 6080406 allocs/op -BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/Rmq-22 2 3839008409 ns/op 26048 jobs/s 207091216 B/op 3701341 allocs/op -BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/Taskq-22 2 8476866406 ns/op 11797 jobs/s 494305536 B/op 7954337 allocs/op -BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/GocraftWork-22 2 3184057496 ns/op 31406 jobs/s 584325768 B/op 9302284 allocs/op -BenchmarkEnqueue/Enqueue/1u-100Kt/VarMQ-22 2 2332792788 ns/op 42867 jobs/s 65148524 B/op 1101343 allocs/op -BenchmarkEnqueue/Enqueue/1u-100Kt/Asynq-22 2 3539772315 ns/op 28250 jobs/s 178011480 B/op 2501215 allocs/op -BenchmarkEnqueue/Enqueue/1u-100Kt/VarMQDistributed-22 2 3111788525 ns/op 32136 jobs/s 94078876 B/op 1801422 allocs/op -BenchmarkEnqueue/Enqueue/1u-100Kt/Rmq-22 2 2478423252 ns/op 40348 jobs/s 64382528 B/op 1300967 allocs/op -BenchmarkEnqueue/Enqueue/1u-100Kt/Taskq-22 2 3546222905 ns/op 28199 jobs/s 200423772 B/op 2902498 allocs/op -BenchmarkEnqueue/Enqueue/1u-100Kt/GocraftWork-22 2 2813743100 ns/op 35540 jobs/s 140161420 B/op 2001324 allocs/op -BenchmarkEnqueue/Enqueue/100u-1Kt/VarMQ-22 2 497319834 ns/op 201078 jobs/s 72197000 B/op 1114903 allocs/op -BenchmarkEnqueue/Enqueue/100u-1Kt/Asynq-22 2 811696062 ns/op 123199 jobs/s 185114372 B/op 2517912 allocs/op -BenchmarkEnqueue/Enqueue/100u-1Kt/VarMQDistributed-22 2 698407826 ns/op 143183 jobs/s 101071404 B/op 1815110 allocs/op -BenchmarkEnqueue/Enqueue/100u-1Kt/Rmq-22 2 494882505 ns/op 202068 jobs/s 71396168 B/op 1314731 allocs/op -BenchmarkEnqueue/Enqueue/100u-1Kt/Taskq-22 2 529472407 ns/op 188867 jobs/s 201499304 B/op 2907174 allocs/op -BenchmarkEnqueue/Enqueue/100u-1Kt/GocraftWork-22 2 496777764 ns/op 201297 jobs/s 142279948 B/op 2006900 allocs/op -BenchmarkLatency/LatencyW10C1/1u-1Kt/VarMQ-22 2 168390007 ns/op 3.583 max-ms 0.1425 p50-ms 0.3843 p99-ms 4786096 B/op 89824 allocs/op -BenchmarkLatency/LatencyW10C1/1u-1Kt/Asynq-22 2 994214390165 ns/op 1507 max-ms 995.3 p50-ms 1492 p99-ms 9208528 B/op 182621 allocs/op -BenchmarkLatency/LatencyW10C1/1u-1Kt/VarMQDistributed-22 2 212051525 ns/op 2.183 max-ms 0.1457 p50-ms 0.5407 p99-ms 5600852 B/op 107450 allocs/op -BenchmarkLatency/LatencyW10C1/1u-1Kt/Rmq-22 2 97284939168 ns/op 113.3 max-ms 102.2 p50-ms 112.3 p99-ms 3609100 B/op 76320 allocs/op -BenchmarkLatency/LatencyW10C1/1u-1Kt/Taskq-22 2 1102165634 ns/op 0.6119 max-ms 0.06330 p50-ms 0.1897 p99-ms 5946532 B/op 99985 allocs/op -BenchmarkLatency/LatencyW10C1/1u-1Kt/GocraftWork-22 2 155181875 ns/op 10.80 max-ms 0.09234 p50-ms 0.4743 p99-ms 5382416 B/op 89832 allocs/op +BenchmarkDurable/NoopW10C1/1u-100Kt/VarMQ-22 2 4737438070 ns/op 21108 jobs/s 341026392 B/op 8027254 allocs/op +BenchmarkDurable/NoopW10C1/1u-100Kt/Asynq-22 2 6497566644 ns/op 15390 jobs/s 619150836 B/op 10709170 allocs/op +BenchmarkDurable/NoopW10C1/1u-100Kt/VarMQDistributed-22 2 4655721094 ns/op 21479 jobs/s 373106820 B/op 8865085 allocs/op +BenchmarkDurable/NoopW10C1/1u-100Kt/Rmq-22 2 3012495728 ns/op 33195 jobs/s 186743172 B/op 3606305 allocs/op +BenchmarkDurable/NoopW10C1/1u-100Kt/Taskq-22 2 5304248071 ns/op 18853 jobs/s 562057276 B/op 9549268 allocs/op +BenchmarkDurable/NoopW10C1/1u-100Kt/GocraftWork-22 2 4010362228 ns/op 24935 jobs/s 464907344 B/op 8555597 allocs/op +BenchmarkDurable/NoopW10C1/100u-1Kt/VarMQ-22 2 2382655080 ns/op 41970 jobs/s 272082848 B/op 5804945 allocs/op +BenchmarkDurable/NoopW10C1/100u-1Kt/Asynq-22 2 5680491625 ns/op 17604 jobs/s 624789372 B/op 10718751 allocs/op +BenchmarkDurable/NoopW10C1/100u-1Kt/VarMQDistributed-22 2 2587269500 ns/op 38651 jobs/s 301549696 B/op 6525087 allocs/op +BenchmarkDurable/NoopW10C1/100u-1Kt/Rmq-22 2 3462561683 ns/op 28880 jobs/s 193259708 B/op 3617675 allocs/op +BenchmarkDurable/NoopW10C1/100u-1Kt/Taskq-22 2 2887843080 ns/op 34628 jobs/s 493567940 B/op 7908554 allocs/op +BenchmarkDurable/NoopW10C1/100u-1Kt/GocraftWork-22 2 2031968278 ns/op 49213 jobs/s 463985276 B/op 8612546 allocs/op +BenchmarkDurable/NoopW10C4/1u-100Kt/Asynq-22 2 8406050550 ns/op 11896 jobs/s 620240800 B/op 10713445 allocs/op +BenchmarkDurable/NoopW10C4/1u-100Kt/VarMQDistributed-22 2 4533710218 ns/op 22057 jobs/s 465966712 B/op 11604269 allocs/op +BenchmarkDurable/NoopW10C4/1u-100Kt/Rmq-22 2 3376506525 ns/op 29616 jobs/s 194006636 B/op 3883568 allocs/op +BenchmarkDurable/NoopW10C4/1u-100Kt/Taskq-22 2 9171341014 ns/op 10904 jobs/s 560210816 B/op 9624720 allocs/op +BenchmarkDurable/NoopW10C4/1u-100Kt/GocraftWork-22 2 4108569260 ns/op 24339 jobs/s 466205936 B/op 8590048 allocs/op +BenchmarkDurable/NoopW10C4/100u-1Kt/Asynq-22 2 4787284142 ns/op 20889 jobs/s 626522172 B/op 10721832 allocs/op +BenchmarkDurable/NoopW10C4/100u-1Kt/VarMQDistributed-22 2 1860338896 ns/op 53754 jobs/s 310027640 B/op 6505593 allocs/op +BenchmarkDurable/NoopW10C4/100u-1Kt/Rmq-22 2 1676463868 ns/op 59649 jobs/s 194937364 B/op 3621642 allocs/op +BenchmarkDurable/NoopW10C4/100u-1Kt/Taskq-22 2 5772566082 ns/op 17323 jobs/s 492128052 B/op 7910985 allocs/op +BenchmarkDurable/NoopW10C4/100u-1Kt/GocraftWork-22 2 2052441984 ns/op 48722 jobs/s 465034272 B/op 8617653 allocs/op +BenchmarkDurable/NoopW100C1/1u-100Kt/VarMQ-22 2 4839135504 ns/op 20665 jobs/s 341097444 B/op 8061259 allocs/op +BenchmarkDurable/NoopW100C1/1u-100Kt/Asynq-22 2 5865654935 ns/op 17048 jobs/s 618993728 B/op 10708615 allocs/op +BenchmarkDurable/NoopW100C1/1u-100Kt/VarMQDistributed-22 2 4722041126 ns/op 21177 jobs/s 372318384 B/op 8851369 allocs/op +BenchmarkDurable/NoopW100C1/1u-100Kt/Rmq-22 2 2990525104 ns/op 33439 jobs/s 186724912 B/op 3607498 allocs/op +BenchmarkDurable/NoopW100C1/1u-100Kt/Taskq-22 2 5448863032 ns/op 18352 jobs/s 561847816 B/op 9551659 allocs/op +BenchmarkDurable/NoopW100C1/1u-100Kt/GocraftWork-22 2 4001537638 ns/op 24990 jobs/s 469650868 B/op 8629058 allocs/op +BenchmarkDurable/NoopW100C1/100u-1Kt/VarMQ-22 2 1665971696 ns/op 60025 jobs/s 253037404 B/op 5091637 allocs/op +BenchmarkDurable/NoopW100C1/100u-1Kt/Asynq-22 2 5144403775 ns/op 19439 jobs/s 624776196 B/op 10717407 allocs/op +BenchmarkDurable/NoopW100C1/100u-1Kt/VarMQDistributed-22 2 1839197908 ns/op 54372 jobs/s 282529256 B/op 5794993 allocs/op +BenchmarkDurable/NoopW100C1/100u-1Kt/Rmq-22 2 3445694808 ns/op 29022 jobs/s 193391192 B/op 3619363 allocs/op +BenchmarkDurable/NoopW100C1/100u-1Kt/Taskq-22 2 2892029526 ns/op 34578 jobs/s 496025640 B/op 7913004 allocs/op +BenchmarkDurable/NoopW100C1/100u-1Kt/GocraftWork-22 2 2239186595 ns/op 44659 jobs/s 468432272 B/op 8627882 allocs/op +BenchmarkDurable/NoopW100C4/1u-100Kt/Asynq-22 2 7490693340 ns/op 13350 jobs/s 620213568 B/op 10713194 allocs/op +BenchmarkDurable/NoopW100C4/1u-100Kt/VarMQDistributed-22 2 4491673114 ns/op 22263 jobs/s 465774388 B/op 11602247 allocs/op +BenchmarkDurable/NoopW100C4/1u-100Kt/Rmq-22 2 3338540877 ns/op 29953 jobs/s 194027004 B/op 3885606 allocs/op +BenchmarkDurable/NoopW100C4/1u-100Kt/Taskq-22 2 9454978185 ns/op 10576 jobs/s 561454508 B/op 9628976 allocs/op +BenchmarkDurable/NoopW100C4/1u-100Kt/GocraftWork-22 2 4222429252 ns/op 23683 jobs/s 477282368 B/op 8681518 allocs/op +BenchmarkDurable/NoopW100C4/100u-1Kt/Asynq-22 2 4409670350 ns/op 22677 jobs/s 626358784 B/op 10723243 allocs/op +BenchmarkDurable/NoopW100C4/100u-1Kt/VarMQDistributed-22 2 1569616254 ns/op 63710 jobs/s 313488668 B/op 5977473 allocs/op +BenchmarkDurable/NoopW100C4/100u-1Kt/Rmq-22 2 1705892744 ns/op 58620 jobs/s 194965300 B/op 3627167 allocs/op +BenchmarkDurable/NoopW100C4/100u-1Kt/Taskq-22 2 6220088208 ns/op 16077 jobs/s 491657860 B/op 7916339 allocs/op +BenchmarkDurable/NoopW100C4/100u-1Kt/GocraftWork-22 2 2396357290 ns/op 41730 jobs/s 477676892 B/op 8611751 allocs/op +BenchmarkDurable/NoopW1000C1/1u-100Kt/VarMQ-22 2 5073679365 ns/op 19710 jobs/s 340711900 B/op 8034086 allocs/op +BenchmarkDurable/NoopW1000C1/1u-100Kt/Asynq-22 2 6072720174 ns/op 16467 jobs/s 618951276 B/op 10706501 allocs/op +BenchmarkDurable/NoopW1000C1/1u-100Kt/VarMQDistributed-22 2 4816265233 ns/op 20763 jobs/s 372373644 B/op 8850861 allocs/op +BenchmarkDurable/NoopW1000C1/1u-100Kt/Rmq-22 2 3060171730 ns/op 32678 jobs/s 188105540 B/op 3623123 allocs/op +BenchmarkDurable/NoopW1000C1/1u-100Kt/Taskq-22 2 5997253353 ns/op 16674 jobs/s 558063188 B/op 9549889 allocs/op +BenchmarkDurable/NoopW1000C1/1u-100Kt/GocraftWork-22 2 4097077086 ns/op 24408 jobs/s 494407972 B/op 8792079 allocs/op +BenchmarkDurable/NoopW1000C1/100u-1Kt/VarMQ-22 2 1708742578 ns/op 58523 jobs/s 255497792 B/op 5088913 allocs/op +BenchmarkDurable/NoopW1000C1/100u-1Kt/Asynq-22 2 5576535246 ns/op 17932 jobs/s 625220400 B/op 10717921 allocs/op +BenchmarkDurable/NoopW1000C1/100u-1Kt/VarMQDistributed-22 2 1850557600 ns/op 54038 jobs/s 283555012 B/op 5788797 allocs/op +BenchmarkDurable/NoopW1000C1/100u-1Kt/Rmq-22 2 3656424156 ns/op 27349 jobs/s 194542084 B/op 3634009 allocs/op +BenchmarkDurable/NoopW1000C1/100u-1Kt/Taskq-22 2 3491891646 ns/op 28638 jobs/s 491565708 B/op 7910718 allocs/op +BenchmarkDurable/NoopW1000C1/100u-1Kt/GocraftWork-22 2 2458252442 ns/op 40679 jobs/s 493324396 B/op 8715177 allocs/op +BenchmarkDurable/NoopW1000C4/1u-100Kt/Asynq-22 2 7844820804 ns/op 12747 jobs/s 621515116 B/op 10710809 allocs/op +BenchmarkDurable/NoopW1000C4/1u-100Kt/VarMQDistributed-22 2 4498312184 ns/op 22231 jobs/s 467163976 B/op 11609222 allocs/op +BenchmarkDurable/NoopW1000C4/1u-100Kt/Rmq-22 2 3599253554 ns/op 27784 jobs/s 198207960 B/op 3954676 allocs/op +BenchmarkDurable/NoopW1000C4/1u-100Kt/Taskq-22 2 12096374343 ns/op 8267 jobs/s 557636904 B/op 9638070 allocs/op +BenchmarkDurable/NoopW1000C4/1u-100Kt/GocraftWork-22 2 4746615117 ns/op 21068 jobs/s 582678200 B/op 9267493 allocs/op +BenchmarkDurable/NoopW1000C4/100u-1Kt/Asynq-22 2 5230494184 ns/op 19119 jobs/s 628713008 B/op 10723194 allocs/op +BenchmarkDurable/NoopW1000C4/100u-1Kt/VarMQDistributed-22 2 1555681388 ns/op 64281 jobs/s 317009508 B/op 5986455 allocs/op +BenchmarkDurable/NoopW1000C4/100u-1Kt/Rmq-22 2 1903002884 ns/op 52549 jobs/s 200777528 B/op 3702527 allocs/op +BenchmarkDurable/NoopW1000C4/100u-1Kt/Taskq-22 2 9008665973 ns/op 11100 jobs/s 490551948 B/op 7936318 allocs/op +BenchmarkDurable/NoopW1000C4/100u-1Kt/GocraftWork-22 2 2716736732 ns/op 36809 jobs/s 580105500 B/op 9181653 allocs/op +BenchmarkDurable/Sleep1msW10C1/1u-100Kt/VarMQ-22 2 16975405437 ns/op 5891 jobs/s 296007236 B/op 6744187 allocs/op +BenchmarkDurable/Sleep1msW10C1/1u-100Kt/Asynq-22 2 18031921406 ns/op 5546 jobs/s 628583360 B/op 10809039 allocs/op +BenchmarkDurable/Sleep1msW10C1/1u-100Kt/VarMQDistributed-22 2 17323488366 ns/op 5773 jobs/s 321571952 B/op 7356499 allocs/op +BenchmarkDurable/Sleep1msW10C1/1u-100Kt/Rmq-22 2 14289314844 ns/op 6998 jobs/s 187720096 B/op 3636065 allocs/op +BenchmarkDurable/Sleep1msW10C1/1u-100Kt/Taskq-22 2 16613143034 ns/op 6019 jobs/s 488939372 B/op 7907918 allocs/op +BenchmarkDurable/Sleep1msW10C1/1u-100Kt/GocraftWork-22 2 15803118532 ns/op 6328 jobs/s 462089000 B/op 8608221 allocs/op +BenchmarkDurable/Sleep1msW10C1/100u-1Kt/VarMQ-22 2 17703894781 ns/op 5648 jobs/s 272794148 B/op 5840886 allocs/op +BenchmarkDurable/Sleep1msW10C1/100u-1Kt/Asynq-22 2 19639993235 ns/op 5092 jobs/s 635237564 B/op 10821562 allocs/op +BenchmarkDurable/Sleep1msW10C1/100u-1Kt/VarMQDistributed-22 2 16953234180 ns/op 5899 jobs/s 302154428 B/op 6556753 allocs/op +BenchmarkDurable/Sleep1msW10C1/100u-1Kt/Rmq-22 2 16078921326 ns/op 6219 jobs/s 194823272 B/op 3652884 allocs/op +BenchmarkDurable/Sleep1msW10C1/100u-1Kt/Taskq-22 2 17682003338 ns/op 5655 jobs/s 489063848 B/op 7907409 allocs/op +BenchmarkDurable/Sleep1msW10C1/100u-1Kt/GocraftWork-22 2 16831549626 ns/op 5941 jobs/s 463283040 B/op 8610850 allocs/op +BenchmarkDurable/Sleep1msW10C4/1u-100Kt/Asynq-22 2 7603420871 ns/op 13152 jobs/s 631794316 B/op 10817883 allocs/op +BenchmarkDurable/Sleep1msW10C4/1u-100Kt/VarMQDistributed-22 2 4623266389 ns/op 21630 jobs/s 479232980 B/op 11851846 allocs/op +BenchmarkDurable/Sleep1msW10C4/1u-100Kt/Rmq-22 2 3317805643 ns/op 30140 jobs/s 195755524 B/op 3902461 allocs/op +BenchmarkDurable/Sleep1msW10C4/1u-100Kt/Taskq-22 2 9120015555 ns/op 10965 jobs/s 558593828 B/op 9622380 allocs/op +BenchmarkDurable/Sleep1msW10C4/1u-100Kt/GocraftWork-22 2 3703473648 ns/op 27002 jobs/s 463809776 B/op 8556497 allocs/op +BenchmarkDurable/Sleep1msW10C4/100u-1Kt/Asynq-22 2 10006484871 ns/op 9994 jobs/s 638150872 B/op 10828962 allocs/op +BenchmarkDurable/Sleep1msW10C4/100u-1Kt/VarMQDistributed-22 2 5162233310 ns/op 19371 jobs/s 329987408 B/op 7128424 allocs/op +BenchmarkDurable/Sleep1msW10C4/100u-1Kt/Rmq-22 2 4816785614 ns/op 20761 jobs/s 198323860 B/op 3675405 allocs/op +BenchmarkDurable/Sleep1msW10C4/100u-1Kt/Taskq-22 2 9131294374 ns/op 10951 jobs/s 489582612 B/op 7910347 allocs/op +BenchmarkDurable/Sleep1msW10C4/100u-1Kt/GocraftWork-22 2 5504545180 ns/op 18167 jobs/s 465024872 B/op 8619131 allocs/op +BenchmarkDurable/Sleep1msW100C1/1u-100Kt/VarMQ-22 2 4567467762 ns/op 21894 jobs/s 340581300 B/op 7927290 allocs/op +BenchmarkDurable/Sleep1msW100C1/1u-100Kt/Asynq-22 2 5955557612 ns/op 16791 jobs/s 630227600 B/op 10813498 allocs/op +BenchmarkDurable/Sleep1msW100C1/1u-100Kt/VarMQDistributed-22 2 4708011441 ns/op 21240 jobs/s 372068756 B/op 8732092 allocs/op +BenchmarkDurable/Sleep1msW100C1/1u-100Kt/Rmq-22 2 3419672064 ns/op 29243 jobs/s 188764212 B/op 3610885 allocs/op +BenchmarkDurable/Sleep1msW100C1/1u-100Kt/Taskq-22 2 5204325130 ns/op 19215 jobs/s 554546600 B/op 9500405 allocs/op +BenchmarkDurable/Sleep1msW100C1/1u-100Kt/GocraftWork-22 2 3826134429 ns/op 26136 jobs/s 471422880 B/op 8717503 allocs/op +BenchmarkDurable/Sleep1msW100C1/100u-1Kt/VarMQ-22 2 2114217461 ns/op 47299 jobs/s 257280288 B/op 5200857 allocs/op +BenchmarkDurable/Sleep1msW100C1/100u-1Kt/Asynq-22 2 6145263588 ns/op 16273 jobs/s 636936476 B/op 10824798 allocs/op +BenchmarkDurable/Sleep1msW100C1/100u-1Kt/VarMQDistributed-22 2 2298511486 ns/op 43506 jobs/s 286437188 B/op 5902072 allocs/op +BenchmarkDurable/Sleep1msW100C1/100u-1Kt/Rmq-22 2 3600370070 ns/op 27775 jobs/s 196447060 B/op 3625305 allocs/op +BenchmarkDurable/Sleep1msW100C1/100u-1Kt/Taskq-22 2 3553053764 ns/op 28145 jobs/s 490300488 B/op 7908541 allocs/op +BenchmarkDurable/Sleep1msW100C1/100u-1Kt/GocraftWork-22 2 2240211370 ns/op 44639 jobs/s 467174156 B/op 8628047 allocs/op +BenchmarkDurable/Sleep1msW100C4/1u-100Kt/Asynq-22 2 7377894384 ns/op 13554 jobs/s 633708384 B/op 10821791 allocs/op +BenchmarkDurable/Sleep1msW100C4/1u-100Kt/VarMQDistributed-22 2 4596687992 ns/op 21755 jobs/s 475379252 B/op 11722711 allocs/op +BenchmarkDurable/Sleep1msW100C4/1u-100Kt/Rmq-22 2 3280117060 ns/op 30487 jobs/s 198798284 B/op 3912922 allocs/op +BenchmarkDurable/Sleep1msW100C4/1u-100Kt/Taskq-22 2 9523637162 ns/op 10500 jobs/s 558482908 B/op 9623862 allocs/op +BenchmarkDurable/Sleep1msW100C4/1u-100Kt/GocraftWork-22 2 4051939248 ns/op 24680 jobs/s 487990608 B/op 8964549 allocs/op +BenchmarkDurable/Sleep1msW100C4/100u-1Kt/Asynq-22 2 5467076548 ns/op 18291 jobs/s 639667376 B/op 10831284 allocs/op +BenchmarkDurable/Sleep1msW100C4/100u-1Kt/VarMQDistributed-22 2 1493192542 ns/op 66971 jobs/s 319070632 B/op 6013430 allocs/op +BenchmarkDurable/Sleep1msW100C4/100u-1Kt/Rmq-22 2 1700872054 ns/op 58793 jobs/s 198375096 B/op 3634041 allocs/op +BenchmarkDurable/Sleep1msW100C4/100u-1Kt/Taskq-22 2 6222446422 ns/op 16071 jobs/s 491450996 B/op 7925966 allocs/op +BenchmarkDurable/Sleep1msW100C4/100u-1Kt/GocraftWork-22 2 2399497240 ns/op 41675 jobs/s 480627004 B/op 8685380 allocs/op +BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/VarMQ-22 2 4603835694 ns/op 21721 jobs/s 340510700 B/op 7911198 allocs/op +BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/Asynq-22 2 6004440232 ns/op 16654 jobs/s 630622504 B/op 10813037 allocs/op +BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/VarMQDistributed-22 2 4679465504 ns/op 21370 jobs/s 372385644 B/op 8731354 allocs/op +BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/Rmq-22 2 3318264990 ns/op 30136 jobs/s 189465848 B/op 3625265 allocs/op +BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/Taskq-22 2 6080259004 ns/op 16447 jobs/s 553552056 B/op 9500902 allocs/op +BenchmarkDurable/Sleep1msW1000C1/1u-100Kt/GocraftWork-22 2 4684468824 ns/op 21347 jobs/s 504565452 B/op 9084086 allocs/op +BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/VarMQ-22 2 1313525447 ns/op 76131 jobs/s 257869872 B/op 5093835 allocs/op +BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/Asynq-22 2 5693365986 ns/op 17564 jobs/s 637273280 B/op 10824570 allocs/op +BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/VarMQDistributed-22 2 1508823920 ns/op 66277 jobs/s 286880116 B/op 5795926 allocs/op +BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/Rmq-22 2 3772718159 ns/op 26506 jobs/s 197071988 B/op 3639529 allocs/op +BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/Taskq-22 2 3925744511 ns/op 25473 jobs/s 490793968 B/op 7919083 allocs/op +BenchmarkDurable/Sleep1msW1000C1/100u-1Kt/GocraftWork-22 2 2691135690 ns/op 37159 jobs/s 495509780 B/op 8811057 allocs/op +BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/Asynq-22 2 7368567767 ns/op 13571 jobs/s 634808804 B/op 10819802 allocs/op +BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/VarMQDistributed-22 2 4562941816 ns/op 21916 jobs/s 476136884 B/op 11714985 allocs/op +BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/Rmq-22 2 3504072729 ns/op 28538 jobs/s 201967092 B/op 3984820 allocs/op +BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/Taskq-22 2 12378383354 ns/op 8079 jobs/s 557830900 B/op 9642591 allocs/op +BenchmarkDurable/Sleep1msW1000C4/1u-100Kt/GocraftWork-22 2 4500468964 ns/op 22220 jobs/s 597118796 B/op 9659439 allocs/op +BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/Asynq-22 2 5357113323 ns/op 18667 jobs/s 640973252 B/op 10829827 allocs/op +BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/VarMQDistributed-22 2 1552455188 ns/op 64414 jobs/s 337293580 B/op 6081138 allocs/op +BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/Rmq-22 2 1895690176 ns/op 52751 jobs/s 204442696 B/op 3707262 allocs/op +BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/Taskq-22 2 8834287302 ns/op 11320 jobs/s 494801208 B/op 7956723 allocs/op +BenchmarkDurable/Sleep1msW1000C4/100u-1Kt/GocraftWork-22 2 2881543944 ns/op 34704 jobs/s 587656744 B/op 9309996 allocs/op +BenchmarkEnqueue/Enqueue/1u-100Kt/VarMQ-22 2 2681565862 ns/op 37292 jobs/s 65151780 B/op 1101480 allocs/op +BenchmarkEnqueue/Enqueue/1u-100Kt/Asynq-22 2 4162681442 ns/op 24023 jobs/s 178009060 B/op 2501209 allocs/op +BenchmarkEnqueue/Enqueue/1u-100Kt/VarMQDistributed-22 2 3678822207 ns/op 27183 jobs/s 94078436 B/op 1801438 allocs/op +BenchmarkEnqueue/Enqueue/1u-100Kt/Rmq-22 2 2994516472 ns/op 33394 jobs/s 64376064 B/op 1300941 allocs/op +BenchmarkEnqueue/Enqueue/1u-100Kt/Taskq-22 2 3734093622 ns/op 26780 jobs/s 200430536 B/op 2902598 allocs/op +BenchmarkEnqueue/Enqueue/1u-100Kt/GocraftWork-22 2 3364781361 ns/op 29720 jobs/s 140163960 B/op 2001378 allocs/op +BenchmarkEnqueue/Enqueue/100u-1Kt/VarMQ-22 2 481343117 ns/op 207752 jobs/s 72205612 B/op 1115062 allocs/op +BenchmarkEnqueue/Enqueue/100u-1Kt/Asynq-22 2 826132021 ns/op 121046 jobs/s 185081888 B/op 2516974 allocs/op +BenchmarkEnqueue/Enqueue/100u-1Kt/VarMQDistributed-22 2 690428136 ns/op 144838 jobs/s 101074584 B/op 1815102 allocs/op +BenchmarkEnqueue/Enqueue/100u-1Kt/Rmq-22 2 506996633 ns/op 197240 jobs/s 71395984 B/op 1314733 allocs/op +BenchmarkEnqueue/Enqueue/100u-1Kt/Taskq-22 2 530681269 ns/op 188437 jobs/s 201459868 B/op 2906889 allocs/op +BenchmarkEnqueue/Enqueue/100u-1Kt/GocraftWork-22 2 493013117 ns/op 202835 jobs/s 142000352 B/op 2006769 allocs/op +BenchmarkLatency/LatencyW10C1/1u-1Kt/VarMQ-22 2 148147256 ns/op 3.431 max-ms 0.09407 p50-ms 0.5321 p99-ms 4611192 B/op 89617 allocs/op +BenchmarkLatency/LatencyW10C1/1u-1Kt/Asynq-22 2 992527538434 ns/op 1501 max-ms 979.7 p50-ms 1491 p99-ms 9158936 B/op 182452 allocs/op +BenchmarkLatency/LatencyW10C1/1u-1Kt/VarMQDistributed-22 2 92842058 ns/op 2.436 max-ms 0.06492 p50-ms 0.2351 p99-ms 5735248 B/op 107564 allocs/op +BenchmarkLatency/LatencyW10C1/1u-1Kt/Rmq-22 2 1632593948 ns/op 6.902 max-ms 1.464 p50-ms 2.891 p99-ms 3441984 B/op 74417 allocs/op +BenchmarkLatency/LatencyW10C1/1u-1Kt/Taskq-22 2 1101978352 ns/op 3.195 max-ms 0.03876 p50-ms 0.1623 p99-ms 5977976 B/op 100125 allocs/op +BenchmarkLatency/LatencyW10C1/1u-1Kt/GocraftWork-22 2 183893194 ns/op 10.94 max-ms 0.1274 p50-ms 0.5047 p99-ms 5421312 B/op 89955 allocs/op PASS -ok github.com/goptics/benchmarks/redis 6032.314s +ok github.com/goptics/benchmarks/redis 5302.628s From 88cdb6d66285491cd6e056917a774ff033e77574 Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 04:46:16 +0600 Subject: [PATCH 7/9] fix(sqlite): review findings in the harness and adapters - River's 1 ms FetchCooldown moves to the queue config, so the client-level value that also paces its insert notifications stays at the default. - walMB is the largest total of the run's -wal files, so one file per queue is measured like every queue in one file; sampling starts before open. - Drain runs build the VarMQ worker with WithAutoRun(false) and Start it, instead of a non-blocking Pause that could let a credit pass run jobs during the untimed fill. - goqite's priority runs in the same order as varmq and River. - A failed row closes its consumer; a failed add fails the row at once; backlite and River stop errors are returned; the leftover poll after the last job is every 10 ms. Co-Authored-By: Claude Fable 5.1 --- sqlite/Taskfile.yml | 2 +- sqlite/backlite.go | 9 ++++++-- sqlite/goqite.go | 2 +- sqlite/harness_test.go | 51 ++++++++++++++++++++++++++++-------------- sqlite/river.go | 28 ++++++++++++----------- sqlite/subjects.go | 7 +++++- sqlite/varmq.go | 21 ++++++++--------- worker/README.md | 2 +- 8 files changed, 74 insertions(+), 48 deletions(-) diff --git a/sqlite/Taskfile.yml b/sqlite/Taskfile.yml index 36062ed..f7f66b5 100644 --- a/sqlite/Taskfile.yml +++ b/sqlite/Taskfile.yml @@ -13,7 +13,7 @@ tasks: - go test -run xxx -bench . -benchtime=1x -timeout 0 txt: - desc: Full run into bench/sqlite.txt (real disk; SQLITEQ_BENCH_DIR picks it; about 30 min) + desc: Full run into bench/sqlite.txt (real disk; SQLITEQ_BENCH_DIR picks it; about 20 min) cmds: - mkdir -p bench - set -o pipefail; go test -run xxx -bench . -benchtime=2x -timeout 0 | tee bench/sqlite.txt diff --git a/sqlite/backlite.go b/sqlite/backlite.go index c6eac31..ed0f8c0 100644 --- a/sqlite/backlite.go +++ b/sqlite/backlite.go @@ -3,6 +3,7 @@ package sqlite import ( "context" "database/sql" + "errors" "path/filepath" "sync/atomic" "testing" @@ -135,12 +136,16 @@ func (c *backliteConsumer) leftover() (int, error) { } func (c *backliteConsumer) close() error { + var err error + if c.started { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - c.client.Stop(ctx) + if !c.client.Stop(ctx) { + err = errors.New("backlite: workers still busy a minute after stop") + } } - return c.db.Close() + return errors.Join(err, c.db.Close()) } diff --git a/sqlite/goqite.go b/sqlite/goqite.go index 954407b..adc5bdb 100644 --- a/sqlite/goqite.go +++ b/sqlite/goqite.go @@ -82,7 +82,7 @@ func openGoqite(tb testing.TB, dir string, sc scenario, ckpt int, ran *atomic.In func (c *goqiteConsumer) add(q, i int) bool { m := goqite.Message{Body: strconv.AppendInt(nil, int64(i), 10)} if c.prio { - m.Priority = i % 4 // higher first + m.Priority = 3 - i%4 // goqite receives higher first; varmq and River take lower first } _, err := jobs.Create(context.Background(), c.queues[q], "bench", m) diff --git a/sqlite/harness_test.go b/sqlite/harness_test.go index 789b716..feee6eb 100644 --- a/sqlite/harness_test.go +++ b/sqlite/harness_test.go @@ -58,9 +58,10 @@ const waitDeadline = 5 * time.Minute // runScenario runs sc b.N times, each on a fresh database, and reports jobs/s // over the timed part only: setup, teardown and the leftover check are not -// timed. Mixed times the first add to the last job handled. Drain times the -// consumer start to the last job handled. It also reports walMB, the largest -// size any one -wal file reached in any iteration, untimed parts included. +// timed. Mixed times the first add to the last job acknowledged. Drain times +// the consumer start to the last job acknowledged. It also reports walMB, the +// largest total size the run's -wal files reached in any iteration, untimed +// parts included. func runScenario(b *testing.B, sc scenario, subj subject, ckpt int) { b.Helper() @@ -81,20 +82,26 @@ func runScenario(b *testing.B, sc scenario, subj subject, ckpt int) { // walSampleEvery is how often sampleWAL reads the -wal file sizes. const walSampleEvery = 50 * time.Millisecond -// sampleWAL reads the size of every -wal file in dir every walSampleEvery, on -// its own goroutine, until the returned stop is called. stop takes one last -// sample and returns the largest size any one file reached; it may be called -// more than once. +// sampleWAL reads the total size of the -wal files in dir every +// walSampleEvery, on its own goroutine, until the returned stop is called. +// stop takes one last sample and returns the largest total seen; it may be +// called more than once. The total, not the largest file, so a subject with +// one file per queue is measured like one with every queue in one file. func sampleWAL(dir string) (stop func() int64) { var peak int64 // owned by the goroutine until done closes sample := func() { files, _ := filepath.Glob(filepath.Join(dir, "*-wal")) + + var total int64 + for _, f := range files { if fi, err := os.Stat(f); err == nil { - peak = max(peak, fi.Size()) + total += fi.Size() } } + + peak = max(peak, total) } quit, done := make(chan struct{}), make(chan struct{}) @@ -133,17 +140,26 @@ func runOnce(b *testing.B, sc scenario, subj subject, ckpt int) int64 { dir := freshDir(b) + stopWAL := sampleWAL(dir) + defer stopWAL() // a failed iteration still stops the sampler + var ran atomic.Int64 // handler runs over all queues c := subj.open(b, dir, sc, ckpt, &ran) - stopWAL := sampleWAL(dir) - defer stopWAL() // a failed iteration still stops the sampler + closed := false - var failed int64 + defer func() { // a failed iteration still stops its consumer + if !closed { + _ = c.close() + } + }() if sc.drain { - failed = produce(c, sc) + if failed := produce(c, sc); failed > 0 { + b.Fatalf("%d adds failed", failed) + } + b.StartTimer() if err := c.start(); err != nil { @@ -155,7 +171,11 @@ func runOnce(b *testing.B, sc scenario, subj subject, ckpt int) int64 { } b.StartTimer() - failed = produce(c, sc) + + if failed := produce(c, sc); failed > 0 { + b.StopTimer() + b.Fatalf("%d adds failed", failed) + } } if err := c.wait(waitDeadline); err != nil { @@ -169,10 +189,6 @@ func runOnce(b *testing.B, sc scenario, subj subject, ckpt int) int64 { b.Fatalf("%s: handler ran %d times, want %d: a job was lost or run twice", sc.name, n, sc.total) } - if failed > 0 { - b.Fatalf("%d adds failed", failed) - } - if left, err := c.leftover(); err != nil { b.Fatalf("count leftover rows: %v", err) } else if left > 0 { @@ -181,6 +197,7 @@ func runOnce(b *testing.B, sc scenario, subj subject, ckpt int) int64 { // Closing checkpoints and removes the WAL, so the sampling stops first walPeak := stopWAL() + closed = true if err := c.close(); err != nil { b.Fatalf("close: %v", err) diff --git a/sqlite/river.go b/sqlite/river.go index 0428bb8..3b1b121 100644 --- a/sqlite/river.go +++ b/sqlite/river.go @@ -3,6 +3,7 @@ package sqlite import ( "context" "database/sql" + "errors" "fmt" "log/slog" "path/filepath" @@ -68,18 +69,19 @@ func openRiver(tb testing.TB, dir string, sc scenario, ckpt int, ran *atomic.Int queues := make(map[string]river.QueueConfig, sc.queues) for i := range sc.queues { - queues[fmt.Sprintf("q%d", i)] = river.QueueConfig{MaxWorkers: 16} + // Forced: a queue's producer fetches at most MaxWorkers jobs, then waits + // FetchCooldown before the next fetch, so the default 100 ms caps 16 + // workers at 160 jobs/s whatever the database does. The 1 ms minimum + // lets SQLite and River's own per-job work set the number. It is set per + // queue so the client-level value, which also paces River's + // insert-notification writes, stays at its default. + queues[fmt.Sprintf("q%d", i)] = river.QueueConfig{MaxWorkers: 16, FetchCooldown: river.FetchCooldownMin} } client, err := river.NewClient(driver, &river.Config{ - // Forced: River fetches at most MaxWorkers jobs, then waits FetchCooldown - // before the next fetch, so the default 100 ms caps 16 workers at 160 - // jobs/s whatever the database does. The 1 ms minimum lets SQLite and - // River's own per-job work set the number instead. - FetchCooldown: river.FetchCooldownMin, - Logger: slog.New(slog.DiscardHandler), - Queues: queues, - Workers: workers, + Logger: slog.New(slog.DiscardHandler), + Queues: queues, + Workers: workers, }) if err != nil { tb.Fatalf("river client: %v", err) @@ -116,14 +118,14 @@ func (c *riverConsumer) leftover() (int, error) { } func (c *riverConsumer) close() error { + var err error + if c.started { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - if err := c.client.Stop(ctx); err != nil { - return err - } + err = c.client.Stop(ctx) } - return c.db.Close() + return errors.Join(err, c.db.Close()) } diff --git a/sqlite/subjects.go b/sqlite/subjects.go index 01181b5..4fe432c 100644 --- a/sqlite/subjects.go +++ b/sqlite/subjects.go @@ -95,6 +95,11 @@ func waitHandled(ran *atomic.Int64, total int, leftover func() (int, error), dea } } + // leftover is a table scan for some subjects, on a pool of one connection + // that the last acknowledgements need too, so it is polled more gently + slow := time.NewTicker(10 * time.Millisecond) + defer slow.Stop() + for { n, err := leftover() if err != nil { @@ -106,7 +111,7 @@ func waitHandled(ran *atomic.Int64, total int, leftover func() (int, error), dea } select { - case <-tick.C: + case <-slow.C: case <-timeout.C: return fmt.Errorf("%d rows still queued %s after the last job", n, deadline) } diff --git a/sqlite/varmq.go b/sqlite/varmq.go index b1c01e2..7025ab2 100644 --- a/sqlite/varmq.go +++ b/sqlite/varmq.go @@ -49,7 +49,12 @@ type bound struct { func bind(tb testing.TB, qs sqliteq.Queues, sc scenario, name string, ran *atomic.Int64) bound { tb.Helper() - w := varmq.NewWorker(func(varmq.Job[int]) { ran.Add(1) }, varmq.WithConcurrency(16)) + configs := []any{varmq.WithConcurrency(16)} + if sc.drain { + configs = append(configs, varmq.WithAutoRun(false)) // start() runs it after the fill + } + + w := varmq.NewWorker(func(varmq.Job[int]) { ran.Add(1) }, configs...) if sc.priority { q, err := qs.NewPriorityQueue(name) @@ -92,15 +97,7 @@ func openVarMQ(l layout) func(testing.TB, string, scenario, int, *atomic.Int64) c := &varmqConsumer{qs: openStore(tb, path, l, ckpt), path: path, l: l, drain: sc.drain} for i := range sc.queues { - bd := bind(tb, c.qs, sc, fmt.Sprintf("q%d", i), ran) - - if sc.drain { - if err := bd.worker.Pause(); err != nil { - tb.Fatalf("pause: %v", err) - } - } - - c.bounds = append(c.bounds, bd) + c.bounds = append(c.bounds, bind(tb, c.qs, sc, fmt.Sprintf("q%d", i), ran)) } return c @@ -109,7 +106,7 @@ func openVarMQ(l layout) func(testing.TB, string, scenario, int, *atomic.Int64) func (c *varmqConsumer) add(q, i int) bool { return c.bounds[q].add(i) } -// start resumes the paused workers of a drain run; otherwise they have been +// start runs the workers of a drain run; a mixed run's workers have been // running since NewWorker. func (c *varmqConsumer) start() error { if !c.drain { @@ -117,7 +114,7 @@ func (c *varmqConsumer) start() error { } for _, bd := range c.bounds { - if err := bd.worker.Resume(); err != nil { + if err := bd.worker.Start(); err != nil { return err } } diff --git a/worker/README.md b/worker/README.md index 5bb0e4a..ea6676f 100644 --- a/worker/README.md +++ b/worker/README.md @@ -12,4 +12,4 @@ Cloudflare Worker that serves the dashboard and the dataset JSON at https://benc Local: `task site:dev` builds against `http://localhost:8787/dataset` and runs `wrangler dev` (needs Node). `task site:deploy` rebuilds for production and deploys. -CI ([.github/workflows/site.yml](../.github/workflows/site.yml)) builds on every pull request and deploys on pushes to `main`, with two repository secrets: `CLOUDFLARE_API_TOKEN` (Workers Scripts: Edit, plus Zone goptics.org: DNS Edit and Workers Routes Edit for the custom domain) and `CLOUDFLARE_ACCOUNT_ID`. +CI ([.github/workflows/site.yml](../.github/workflows/site.yml)) builds on pull requests and deploys on pushes to `main` that touch the bench data, the Taskfile, `worker/` or the workflow itself, with two repository secrets: `CLOUDFLARE_API_TOKEN` (Workers Scripts: Edit, plus Zone goptics.org: DNS Edit and Workers Routes Edit for the custom domain) and `CLOUDFLARE_ACCOUNT_ID`. From fec96aa238b869409e96a89a606c12ae16305630 Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 05:00:54 +0600 Subject: [PATCH 8/9] feat(sqlite): rerun after the review fixes, 2026-10-25 32 rows, -benchtime=2x. River at a 1 ms per-queue fetch cooldown, walMB as the total of the run's WAL files, drain runs started from a not-yet-running worker. sqlite README and the root headline regenerated from the file. Co-Authored-By: Claude Fable 5.1 --- README.md | 2 +- sqlite/README.md | 50 +++++++++++++++---------------- sqlite/bench/sqlite.txt | 66 ++++++++++++++++++++--------------------- 3 files changed, 59 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 5a96203..b746818 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Pool run of 2026-10-24, Redis and SQLite runs of 2026-10-25, all `-benchtime=2x` - Pool: VarMQ is the fastest subject in 40, 36 and 20 of the 55 rows at 24, 8 and 4 CPUs. It is slower than the buffered-channel baseline on the one-worker `Loop10` rows, except `1Mu-1t`, where the two are level. - Redis: with the `Noop` task, VarMQ is first in 2 of the 6 one-process rows and VarMQDistributed in 2 of the 6 four-process rows, all at 100 producers; rmq leads every single-producer row. Pickup latency p50: taskq 0.03876 ms, VarMQDistributed 0.06492 ms, VarMQ 0.09407 ms, rmq 1.464 ms, Asynq 979.7 ms. -- SQLite: VarMQ (sqliteq) is first in all 16 rows: on `Mixed1Q` at ckpt1000 it runs 3.1x goqite, 4.8x River and 23x backlite, and ten queues in separate files reach 103,728 jobs/s at ckpt10000. +- SQLite: VarMQ (sqliteq) is first in all 8 scenario and checkpoint groups: on `Mixed1Q` at ckpt1000 it runs 3.1x goqite, 4.1x River and 23x backlite, and ten queues in separate files reach 107,459 jobs/s at ckpt10000. ## Environment diff --git a/sqlite/README.md b/sqlite/README.md index 787d20d..914ed4d 100644 --- a/sqlite/README.md +++ b/sqlite/README.md @@ -5,28 +5,28 @@ Chart: https://benchmarks.goptics.org/?id=sqlite ## Results -Run of 2026-10-25: varmq 415ad73 (unreleased, `replace` in go.mod), sqliteq v0.3.0, goqite v0.4.0, backlite v0.8.0, River v0.49.0, `-benchtime=2x`, 32 rows in `bench/sqlite.txt`, ext4 over NVMe. jobs/s, higher is better; walMB is the peak WAL size, lower is better. +Run of 2026-10-25: varmq 415ad73 (unreleased, `replace` in go.mod), sqliteq v0.3.0, goqite v0.4.0, backlite v0.8.0, River v0.49.0, `-benchtime=2x`, 32 rows in `bench/sqlite.txt`, ext4 over NVMe. jobs/s, higher is better; walMB is the peak total size of the run's WAL files, lower is better. | Scenario | Subject | ckpt1000 | ckpt10000 | walMB 1000 / 10000 | |----------|---------|---------:|----------:|-------------------:| -| `Mixed1Q` | VarMQ | 6,265 | 12,439 | 4.2 / 41.2 | -| `Mixed1Q` | Goqite | 2,031 | 3,848 | 4.1 / 41.2 | -| `Mixed1Q` | Backlite | 267 | 153 | 200.2 / 140.2 | -| `Mixed1Q` | River | 1,302 | 2,404 | 4.2 / 41.3 | -| `Drain1Q` | VarMQ | 15,185 | 24,581 | 4.2 / 41.2 | -| `Drain1Q` | Goqite | 2,754 | 4,051 | 4.1 / 41.2 | -| `Drain1Q` | Backlite | 1,141 | 1,492 | 179.8 / 152.5 | -| `Drain1Q` | River | 3,137 | 3,671 | 4.3 / 41.4 | -| `DrainPrio` | VarMQ | 13,614 | 20,566 | 4.2 / 41.2 | -| `DrainPrio` | Goqite | 2,880 | 3,962 | 4.1 / 41.2 | -| `DrainPrio` | River | 3,101 | 3,554 | 4.5 / 41.4 | -| `Mixed10Q` | VarMQ | 30,560 | 103,728 | 4.1 / 39.3 | -| `Mixed10Q` | VarMQSingleFile | 4,445 | 11,226 | 4.2 / 41.3 | -| `Mixed10Q` | Goqite | 2,152 | 4,449 | 4.1 / 41.2 | -| `Mixed10Q` | Backlite | 4,864 | 5,362 | 367.9 / 369.9 | -| `Mixed10Q` | River | 660 | 1,105 | 4.3 / 41.3 | - -VarMQ is first in all 16 rows; on `Mixed1Q` at ckpt1000 it runs 3.1x goqite, 4.8x River and 23x backlite. A 10,000-page checkpoint is 1.1 to 3.4x faster than 1,000 for VarMQ, goqite and River at a WAL about ten times larger (39.3 to 41.4 MB against 4.1 to 4.5 MB); ten queues in separate files (VarMQ) run 6.9x and 9.2x the same ten in one file (VarMQSingleFile). Backlite's WAL peaks at 140 to 370 MB whatever the checkpoint size, and on `Mixed1Q` it is slower at the larger one. +| `Mixed1Q` | VarMQ | 6,245 | 13,906 | 4.2 / 41.2 | +| `Mixed1Q` | Goqite | 2,039 | 3,682 | 4.1 / 41.2 | +| `Mixed1Q` | Backlite | 266 | 926 | 113.8 / 182.3 | +| `Mixed1Q` | River | 1,523 | 2,283 | 4.2 / 41.3 | +| `Drain1Q` | VarMQ | 14,923 | 25,420 | 4.1 / 41.2 | +| `Drain1Q` | Goqite | 2,834 | 4,229 | 4.2 / 41.2 | +| `Drain1Q` | Backlite | 1,286 | 1,168 | 126.3 / 166.9 | +| `Drain1Q` | River | 3,252 | 3,774 | 4.3 / 41.2 | +| `DrainPrio` | VarMQ | 14,044 | 30,925 | 4.2 / 41.2 | +| `DrainPrio` | Goqite | 2,862 | 4,052 | 4.1 / 41.2 | +| `DrainPrio` | River | 3,083 | 3,584 | 4.7 / 41.2 | +| `Mixed10Q` | VarMQ | 28,971 | 107,459 | 41.3 / 385.4 | +| `Mixed10Q` | VarMQSingleFile | 4,759 | 10,902 | 4.2 / 41.3 | +| `Mixed10Q` | Goqite | 2,187 | 5,048 | 4.1 / 41.2 | +| `Mixed10Q` | Backlite | 4,807 | 5,781 | 352.9 / 369.6 | +| `Mixed10Q` | River | 1,383 | 2,173 | 4.3 / 41.2 | + +VarMQ is first in all 8 scenario and checkpoint groups; on `Mixed1Q` at ckpt1000 it runs 3.1x goqite, 4.1x River and 23x backlite. A 10,000-page checkpoint is 1.2 to 3.7x faster than 1,000 for VarMQ, goqite and River and holds a WAL 9 to 10 times larger (4.2 MB against 41.2 MB per file). Ten queues in separate files (VarMQ) run 6.1x and 9.9x the same ten in one file (VarMQSingleFile), with ten WAL files instead of one: 41.3 and 385.4 MB in total against 4.2 and 41.3. Backlite's WAL peaks at 114 to 370 MB whatever the checkpoint size and on `Drain1Q` it is slower at the larger one. Absolute numbers vary between runs on the same machine; compare ratios within one run. ## Subjects @@ -36,10 +36,10 @@ Absolute numbers vary between runs on the same machine; compare ratios within on | VarMQ | sqliteq through a varmq worker | sqliteq v0.3.0, varmq 415ad73 | pool of 8 per file (sqliteq) | one database file per queue (sqliteq's default), 16 concurrent jobs per queue | | VarMQSingleFile | same | same | same | every queue in one file (`WithSingleFile`); `Mixed10Q` only | | Goqite | maragu.dev/goqite with its `jobs` runner | v0.4.0 | one (its README example) | one runner per queue, limit 16, 100 ms poll between empty receives | -| Backlite | mikestefanello/backlite | v0.8.0 | default pool, unbounded | one client, 16 workers per queue, dispatcher woken in-process on every add | -| River | riverqueue/river with riverdriver/riversqlite | v0.49.0 | one (its driver doc) | one client, 16 workers per queue, 1 ms fetch cooldown | +| Backlite | mikestefanello/backlite | v0.8.0 | default pool, unbounded | one client with 16 x queues workers shared by every queue, dispatcher woken in-process on every add | +| River | riverqueue/river with riverdriver/riversqlite | v0.49.0 | one (its driver doc) | one client, 16 workers per queue, 1 ms fetch cooldown per queue, completions written in batches by its completer | -Every subject opens SQLite with WAL, synchronous NORMAL, a 5 s busy timeout and the row's `wal_autocheckpoint`; everything else is the library default. The one forced setting is River's `FetchCooldown`: River fetches at most `MaxWorkers` jobs per cooldown, so its 100 ms default caps 16 workers at 160 jobs/s whatever the database does (measured 159); the 1 ms minimum lets SQLite set the number. +Every subject opens SQLite with WAL, synchronous NORMAL, a 5 s busy timeout and the row's `wal_autocheckpoint`. Everything else is the library default, apart from three settings: River's per-queue `FetchCooldown` is its 1 ms minimum, since a queue's producer fetches at most `MaxWorkers` jobs per cooldown and the 100 ms default caps 16 workers at 160 jobs/s whatever the database does (the client-level value, which also paces River's insert notifications, stays at the default); River's logger is discarded; backlite's `ReleaseAfter`, which has no default, is 10 minutes. ## Scenarios @@ -47,15 +47,15 @@ Every job is an `int`; the handler does nothing. | Name | Queues | Producers per queue | Jobs | Timed | Subjects | |------|-------:|--------------------:|-----:|-------|----------| -| `Mixed1Q` | 1 | 4 | 20,000 | first add to last job handled, producing and consuming at once | all | -| `Drain1Q` | 1 | 4 | 20,000 | everything added first, then consumer start to last job handled | all | +| `Mixed1Q` | 1 | 4 | 20,000 | first add to last job acknowledged, producing and consuming at once | all | +| `Drain1Q` | 1 | 4 | 20,000 | everything added first, then consumer start (River's client start-up included) to last job acknowledged | all | | `DrainPrio` | 1 | 4 | 10,000 | as `Drain1Q` on a priority queue, priority `i % 4` | VarMQ, Goqite, River | | `Mixed10Q` | 10 | 1 | 20,000 | as `Mixed1Q` over ten queues, 16 workers each | all, plus VarMQSingleFile | - Rows are named `BenchmarkSQLite//ckpt/`. - `ckpt` is the WAL checkpoint size in pages, 1000 (SQLite's default) or 10000, set on every connection. - `jobs/s` is the job count divided by the timed part; setup, teardown and the checks below are untimed. -- `walMB` is the largest size any `-wal` file in the run's directory reached, sampled every 50 ms, untimed phases included. +- `walMB` is the largest total size the `-wal` files in the run's directory reached, sampled every 50 ms from before the store opens, untimed phases included. - A run fails if any add failed, the handler did not run exactly once per job, or rows remain in the queue tables. ## Running diff --git a/sqlite/bench/sqlite.txt b/sqlite/bench/sqlite.txt index 8a34e6e..f70fca1 100644 --- a/sqlite/bench/sqlite.txt +++ b/sqlite/bench/sqlite.txt @@ -2,37 +2,37 @@ goos: linux goarch: amd64 pkg: github.com/goptics/benchmarks/sqlite cpu: 13th Gen Intel(R) Core(TM) i7-13700 -BenchmarkSQLite/Mixed1Q/ckpt1000/VarMQ-24 2 3192392801 ns/op 6265 jobs/s 4.153 walMB -BenchmarkSQLite/Mixed1Q/ckpt1000/Goqite-24 2 9849167800 ns/op 2031 jobs/s 4.145 walMB -BenchmarkSQLite/Mixed1Q/ckpt1000/Backlite-24 2 74830086386 ns/op 267.3 jobs/s 200.2 walMB -BenchmarkSQLite/Mixed1Q/ckpt1000/River-24 2 15362132646 ns/op 1302 jobs/s 4.211 walMB -BenchmarkSQLite/Mixed1Q/ckpt10000/VarMQ-24 2 1607840522 ns/op 12439 jobs/s 41.22 walMB -BenchmarkSQLite/Mixed1Q/ckpt10000/Goqite-24 2 5197534856 ns/op 3848 jobs/s 41.22 walMB -BenchmarkSQLite/Mixed1Q/ckpt10000/Backlite-24 2 130632159101 ns/op 153.1 jobs/s 140.2 walMB -BenchmarkSQLite/Mixed1Q/ckpt10000/River-24 2 8317833819 ns/op 2404 jobs/s 41.27 walMB -BenchmarkSQLite/Drain1Q/ckpt1000/VarMQ-24 2 1317111602 ns/op 15185 jobs/s 4.153 walMB -BenchmarkSQLite/Drain1Q/ckpt1000/Goqite-24 2 7263340616 ns/op 2754 jobs/s 4.149 walMB -BenchmarkSQLite/Drain1Q/ckpt1000/Backlite-24 2 17531593564 ns/op 1141 jobs/s 179.8 walMB -BenchmarkSQLite/Drain1Q/ckpt1000/River-24 2 6375015794 ns/op 3137 jobs/s 4.256 walMB -BenchmarkSQLite/Drain1Q/ckpt10000/VarMQ-24 2 813634553 ns/op 24581 jobs/s 41.22 walMB -BenchmarkSQLite/Drain1Q/ckpt10000/Goqite-24 2 4936705099 ns/op 4051 jobs/s 41.22 walMB -BenchmarkSQLite/Drain1Q/ckpt10000/Backlite-24 2 13402619364 ns/op 1492 jobs/s 152.5 walMB -BenchmarkSQLite/Drain1Q/ckpt10000/River-24 2 5448609552 ns/op 3671 jobs/s 41.40 walMB -BenchmarkSQLite/DrainPrio/ckpt1000/VarMQ-24 2 734529722 ns/op 13614 jobs/s 4.153 walMB -BenchmarkSQLite/DrainPrio/ckpt1000/Goqite-24 2 3472367467 ns/op 2880 jobs/s 4.149 walMB -BenchmarkSQLite/DrainPrio/ckpt1000/River-24 2 3225075666 ns/op 3101 jobs/s 4.544 walMB -BenchmarkSQLite/DrainPrio/ckpt10000/VarMQ-24 2 486231908 ns/op 20566 jobs/s 41.21 walMB -BenchmarkSQLite/DrainPrio/ckpt10000/Goqite-24 2 2524238889 ns/op 3962 jobs/s 41.22 walMB -BenchmarkSQLite/DrainPrio/ckpt10000/River-24 2 2813890148 ns/op 3554 jobs/s 41.39 walMB -BenchmarkSQLite/Mixed10Q/ckpt1000/VarMQ-24 2 654451480 ns/op 30560 jobs/s 4.132 walMB -BenchmarkSQLite/Mixed10Q/ckpt1000/VarMQSingleFile-24 2 4499681254 ns/op 4445 jobs/s 4.240 walMB -BenchmarkSQLite/Mixed10Q/ckpt1000/Goqite-24 2 9295114232 ns/op 2152 jobs/s 4.141 walMB -BenchmarkSQLite/Mixed10Q/ckpt1000/Backlite-24 2 4112004616 ns/op 4864 jobs/s 367.9 walMB -BenchmarkSQLite/Mixed10Q/ckpt1000/River-24 2 30302010174 ns/op 660.0 jobs/s 4.310 walMB -BenchmarkSQLite/Mixed10Q/ckpt10000/VarMQ-24 2 192812872 ns/op 103728 jobs/s 39.28 walMB -BenchmarkSQLite/Mixed10Q/ckpt10000/VarMQSingleFile-24 2 1781507324 ns/op 11226 jobs/s 41.32 walMB -BenchmarkSQLite/Mixed10Q/ckpt10000/Goqite-24 2 4495456860 ns/op 4449 jobs/s 41.22 walMB -BenchmarkSQLite/Mixed10Q/ckpt10000/Backlite-24 2 3729655254 ns/op 5362 jobs/s 369.9 walMB -BenchmarkSQLite/Mixed10Q/ckpt10000/River-24 2 18103584976 ns/op 1105 jobs/s 41.26 walMB +BenchmarkSQLite/Mixed1Q/ckpt1000/VarMQ-24 2 3202674808 ns/op 6245 jobs/s 4.157 walMB +BenchmarkSQLite/Mixed1Q/ckpt1000/Goqite-24 2 9808583668 ns/op 2039 jobs/s 4.149 walMB +BenchmarkSQLite/Mixed1Q/ckpt1000/Backlite-24 2 75226771368 ns/op 265.9 jobs/s 113.8 walMB +BenchmarkSQLite/Mixed1Q/ckpt1000/River-24 2 13128044256 ns/op 1523 jobs/s 4.240 walMB +BenchmarkSQLite/Mixed1Q/ckpt10000/VarMQ-24 2 1438192279 ns/op 13906 jobs/s 41.22 walMB +BenchmarkSQLite/Mixed1Q/ckpt10000/Goqite-24 2 5431655877 ns/op 3682 jobs/s 41.22 walMB +BenchmarkSQLite/Mixed1Q/ckpt10000/Backlite-24 2 21608168903 ns/op 925.6 jobs/s 182.3 walMB +BenchmarkSQLite/Mixed1Q/ckpt10000/River-24 2 8759306841 ns/op 2283 jobs/s 41.30 walMB +BenchmarkSQLite/Drain1Q/ckpt1000/VarMQ-24 2 1340240240 ns/op 14923 jobs/s 4.149 walMB +BenchmarkSQLite/Drain1Q/ckpt1000/Goqite-24 2 7056277727 ns/op 2834 jobs/s 4.153 walMB +BenchmarkSQLite/Drain1Q/ckpt1000/Backlite-24 2 15547598584 ns/op 1286 jobs/s 126.3 walMB +BenchmarkSQLite/Drain1Q/ckpt1000/River-24 2 6150176069 ns/op 3252 jobs/s 4.305 walMB +BenchmarkSQLite/Drain1Q/ckpt10000/VarMQ-24 2 786794170 ns/op 25420 jobs/s 41.22 walMB +BenchmarkSQLite/Drain1Q/ckpt10000/Goqite-24 2 4729168064 ns/op 4229 jobs/s 41.22 walMB +BenchmarkSQLite/Drain1Q/ckpt10000/Backlite-24 2 17128919170 ns/op 1168 jobs/s 166.9 walMB +BenchmarkSQLite/Drain1Q/ckpt10000/River-24 2 5298945460 ns/op 3774 jobs/s 41.24 walMB +BenchmarkSQLite/DrainPrio/ckpt1000/VarMQ-24 2 712025269 ns/op 14044 jobs/s 4.153 walMB +BenchmarkSQLite/DrainPrio/ckpt1000/Goqite-24 2 3493455254 ns/op 2862 jobs/s 4.149 walMB +BenchmarkSQLite/DrainPrio/ckpt1000/River-24 2 3243669480 ns/op 3083 jobs/s 4.676 walMB +BenchmarkSQLite/DrainPrio/ckpt10000/VarMQ-24 2 323363232 ns/op 30925 jobs/s 41.21 walMB +BenchmarkSQLite/DrainPrio/ckpt10000/Goqite-24 2 2468107606 ns/op 4052 jobs/s 41.21 walMB +BenchmarkSQLite/DrainPrio/ckpt10000/River-24 2 2789877922 ns/op 3584 jobs/s 41.22 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/VarMQ-24 2 690340771 ns/op 28971 jobs/s 41.34 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/VarMQSingleFile-24 2 4202283922 ns/op 4759 jobs/s 4.244 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/Goqite-24 2 9146798806 ns/op 2187 jobs/s 4.149 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/Backlite-24 2 4160713082 ns/op 4807 jobs/s 352.9 walMB +BenchmarkSQLite/Mixed10Q/ckpt1000/River-24 2 14459254609 ns/op 1383 jobs/s 4.305 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/VarMQ-24 2 186117114 ns/op 107459 jobs/s 385.4 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/VarMQSingleFile-24 2 1834591130 ns/op 10902 jobs/s 41.30 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/Goqite-24 2 3962347738 ns/op 5048 jobs/s 41.21 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/Backlite-24 2 3459530112 ns/op 5781 jobs/s 369.6 walMB +BenchmarkSQLite/Mixed10Q/ckpt10000/River-24 2 9202100887 ns/op 2173 jobs/s 41.24 walMB PASS -ok github.com/goptics/benchmarks/sqlite 1272.094s +ok github.com/goptics/benchmarks/sqlite 857.403s From 2fad3a15247af2856baa72f84fb1af8e54a44b88 Mon Sep 17 00:00:00 2001 From: fahimfaisaal Date: Sun, 25 Oct 2026 05:03:25 +0600 Subject: [PATCH 9/9] docs(redis): say that the harness picks rmq's poll duration and prefetch Co-Authored-By: Claude Fable 5.1 --- redis/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/README.md b/redis/README.md index 2a3f99d..4e36afc 100644 --- a/redis/README.md +++ b/redis/README.md @@ -74,7 +74,7 @@ What each library does per job, read from source: [NOTES.md](NOTES.md). Names: `BenchmarkDurable/WC//`, `BenchmarkEnqueue/Enqueue//`, `BenchmarkLatency/LatencyW10C1/1u-1Kt/`. -Each subject runs at its library defaults except worker concurrency and the Redis pool size, `max(workers, 10*GOMAXPROCS)`; the settings a library forces are listed in [NOTES.md](NOTES.md). +Each subject runs at its library defaults except worker concurrency and the Redis pool size, `max(workers, 10*GOMAXPROCS)`; the settings a library forces are listed in [NOTES.md](NOTES.md). rmq has no default for its poll duration or prefetch limit; the harness uses 1 ms and `max(1000, 2*workers)` (the example's 100 ms capped a connection near prefetch / 0.1 s), see [NOTES.md](NOTES.md). VarMQ's persistent queue runs one instance, so it has no `C4` rows.