test: add durable, batched and roll publish benchmarks #3

Merged
sam merged 1 commit from feature/publish-benchmarks into main 2026-09-25 06:51:53 +00:00
Member

Finishes Phase 5 of the server-persistence plan. WithFlushInterval shipped in main (PR #1), but the benchmarks that were supposed to decide its default cadence did not.

Why this is a new PR rather than a reopen of #1

PR #1 is merged (74c236d) and cannot be reopened. The benchmarks lived on the orphan commit dc1a72a ("bench: add durable vs batched publish and roll benchmarks (phase 5)"), which branched from 3064914 — before the PR #1 review fixes — and was never merged:

3064914 ──┬── c4b69a0  fix: resolve PR #1 review ...   ← merged as PR #1
          └── dc1a72a  bench: add durable vs batched ... ← orphan, no remote ref

Merging that commit wholesale would have reverted the review fixes. Relative to main, its per-file diff is:

file added deleted what that actually is
bench_test.go 105 0 the benchmark work
protocol.go 2 4 review fixes absent from the orphan
server.go 35 133 review fixes absent
server_test.go 0 114 review fixes absent
store.go 58 341 review fixes absent
store_test.go 1 492 review fixes absent

So this branch takes only bench_test.go, on top of main, exactly 105 added lines. The review fix (3064914 → main) never touched bench_test.go, so the addition applies cleanly with no conflict. The orphan commit is preserved locally at dc1a72a and is left untouched.

What it measures

The default is still per-publish fsync (flushInterval zero). linux/arm64, 500 iterations x3:

BenchmarkPublishDurable  ~370000 ns/op    per-publish fsync, current default
BenchmarkPublishBatched    ~6700 ns/op    WithFlushInterval batches fsyncs
BenchmarkPublishRoll     ~375000 ns/op    one segment roll ~ one fsync

A batched cadence is roughly 55x faster per publish, and a roll costs about one fsync — the crash window a non-zero interval trades away. The benchmarks are left alongside the count-only ones already in bench_test.go (BenchmarkServerPublish, BenchmarkServerPull, BenchmarkServerPublishDedup, BenchmarkBudgetSweepNonResident, ...).

Verification

gofmt -l .                                          # clean
go build ./...                                      # ok
go vet ./...                                        # ok
go test -run '^$' -bench 'Publish(Durable|Batched|Roll)' -benchtime=500x -count=3 .   # ok

This does not change behavior

Test-only: no production file is touched, and the fsync default is deliberately left as-is. Choosing a non-zero default from these numbers is a separate decision for you.

Finishes Phase 5 of the server-persistence plan. `WithFlushInterval` shipped in `main` (PR #1), but the benchmarks that were supposed to **decide its default cadence** did not. ## Why this is a new PR rather than a reopen of #1 PR #1 is merged (`74c236d`) and cannot be reopened. The benchmarks lived on the orphan commit `dc1a72a` ("bench: add durable vs batched publish and roll benchmarks (phase 5)"), which branched from `3064914` — *before* the PR #1 review fixes — and was never merged: ``` 3064914 ──┬── c4b69a0 fix: resolve PR #1 review ... ← merged as PR #1 └── dc1a72a bench: add durable vs batched ... ← orphan, no remote ref ``` Merging that commit wholesale would have **reverted the review fixes**. Relative to `main`, its per-file diff is: | file | added | deleted | what that actually is | |---|---|---|---| | `bench_test.go` | 105 | 0 | the benchmark work | | `protocol.go` | 2 | 4 | review fixes absent from the orphan | | `server.go` | 35 | 133 | review fixes absent | | `server_test.go` | 0 | 114 | review fixes absent | | `store.go` | 58 | 341 | review fixes absent | | `store_test.go` | 1 | 492 | review fixes absent | So this branch takes **only `bench_test.go`**, on top of `main`, exactly 105 added lines. The review fix (`3064914` → `main`) never touched `bench_test.go`, so the addition applies cleanly with no conflict. The orphan commit is preserved locally at `dc1a72a` and is left untouched. ## What it measures The default is still per-publish fsync (`flushInterval` zero). linux/arm64, 500 iterations x3: ``` BenchmarkPublishDurable ~370000 ns/op per-publish fsync, current default BenchmarkPublishBatched ~6700 ns/op WithFlushInterval batches fsyncs BenchmarkPublishRoll ~375000 ns/op one segment roll ~ one fsync ``` A batched cadence is roughly **55x faster per publish**, and a roll costs about one fsync — the crash window a non-zero interval trades away. The benchmarks are left alongside the count-only ones already in `bench_test.go` (`BenchmarkServerPublish`, `BenchmarkServerPull`, `BenchmarkServerPublishDedup`, `BenchmarkBudgetSweepNonResident`, ...). ## Verification ``` gofmt -l . # clean go build ./... # ok go vet ./... # ok go test -run '^$' -bench 'Publish(Durable|Batched|Roll)' -benchtime=500x -count=3 . # ok ``` ## This does not change behavior Test-only: no production file is touched, and the fsync default is deliberately left as-is. Choosing a non-zero default from these numbers is a separate decision for you.
Phase 5 of the server-persistence plan shipped WithFlushInterval (server.go) but
not the benchmarks that were meant to decide its default cadence. The commit
carrying them, dc1a72a, branched from 3064914 before the PR #1 review fixes and
was never merged; only its bench_test.go is taken here, on top of main. Its other
file diffs were the review fixes being absent rather than new work, so reusing
the whole commit would have reverted them.

The default is unchanged (per-publish fsync). Measured on linux/arm64, 500
iterations x3, the numbers the cadence decision needs:

  BenchmarkPublishDurable  ~370000 ns/op   per-publish fsync, current default
  BenchmarkPublishBatched    ~6700 ns/op   WithFlushInterval batches fsyncs
  BenchmarkPublishRoll     ~375000 ns/op   one segment roll ~ one fsync

So a batched cadence is roughly 55x faster per publish and a roll costs about one
fsync, which is the crash window a non-zero interval trades away.
sam merged commit 6b073ef3de into main 2026-09-25 06:51:53 +00:00
sam deleted branch feature/publish-benchmarks 2026-09-25 06:51:53 +00:00
Sign in to join this conversation.
No reviewers
No labels
code-review
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
norobo/webstream!3
No description provided.