Skip to content

feat: add a CAS read-modify-write workload to ocachecli bench and the benchmark CI - #260

Merged
ovaistariq merged 3 commits into
mainfrom
feat/cas-bench
Sep 7, 2026
Merged

ovaistariq merged 3 commits into
mainfrom
feat/cas-bench

Conversation

@ovaistariq

@ovaistariq ovaistariq commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes out PR5 of the #254 plan: CAS benchmarks, as a workload op in ocachecli bench that slots into the existing single-node and 3-node cluster benchmark workflows.

The workload

cas=N in a custom mix (e.g. cas=100, read=70,cas=30). Each op is one guarded read-modify-write — GetWithVersion, then PutIfVersion against the version just read — the write-coordination pattern CAS exists for.

  • A lost race is a mismatch, not an error. Under contention that's the expected outcome and the thing worth measuring, so results report Attempts / Wins / Mismatches / Mismatch Rate in a new "CAS Outcomes" section, and Errors stays real errors only.
  • Disjoint key namespace. CAS keys are preloaded with put-if-absent and never shared with plain update keys, keeping the benchmark inside supported semantics (mixing plain writes and CAS on one key is unsupported). Plain keys are preloaded only if the mix uses them.
  • Streaming variants apply on the same threshold as the plain ops; reads always stream. Works unchanged in --mode simple and --mode cluster.

CI

Both remaining benchmark workflows gain three steps:

  • Uncontended CAS baseline, 100 B: the plain 100 B benchmarks' exact defaults (8 workers, 1000 keys), so the only variable is the op itself — this isolates what one guarded read-modify-write costs over its two constituent RPCs.
  • Contended CAS, 100 B: 16 workers over 200 keys, cas=100 — the mismatch rate is the contention signal. In cluster mode this also exercises CAS forwarding and the no-retry rule for conditional writes.
  • Mixed read=70,cas=30, 100 KB: raw-file tier, so each CAS win spills a file and reclaims the one it replaced while the compactor migrates underneath.

Verification

  • Two new tests against an in-process gRPC server pin the accounting invariants: every attempt is a win or a mismatch; a lost race is never an error; the server applied exactly one version bump per reported win; a single worker never mismatches.
  • Live smoke on a real server (8 workers, 50 keys): 4000 contended attempts, 3708 wins, 292 mismatches (7.3%), 0 errors. Mixed 100 KB: 575 CAS attempts, 26 mismatches, 0 errors, reads unaffected.
  • make vet, test-client, and both builds clean; workflow YAML parses.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YCoN4Him5ZY4hZovVp37ra


Note

Low Risk
Changes are limited to the benchmark CLI, CI workflow steps, and docs—no server or production client behavior changes.

Overview
Adds cas=N to ocachecli bench custom workloads so benchmarks can run guarded read-modify-writes (GetWithVersion → PutIfVersion). Lost races are tracked as mismatches (with win/attempt counts and mismatch rate in output), not in Errors, via ClassifyCASResult and a dedicated cas- key namespace preloaded with put-if-absent so CAS keys never share plain read/update keys.

Single-node and 3-node cluster GitHub benchmark workflows each gain three steps: uncontended 100 B CAS baseline, contended 100 B CAS (narrow keyspace), and mixed read=70,cas=30 at 100 KB (raw-file tier). Docs and the --workload flag help text describe the new mix; tests assert CAS accounting on an in-process gRPC mock.

Reviewed by Cursor Bugbot for commit 67ec315. Bugbot is set up for automated code reviews on this repo. Configure here.

… benchmark CI

Adds an OpCAS workload op ("cas=N" in a custom mix): one guarded
read-modify-write per op — GetWithVersion, then PutIfVersion against the
version just read — which is the write-coordination pattern conditional
operations exist for (issue #254). Losing the race (a VersionMismatchError) is
the expected outcome under contention, so it is counted as a mismatch and
reported as its own rate, never folded into Errors. Results gain
CASAttempts/CASWins/CASMismatches and a "CAS Outcomes" section.

CAS keys live in their own namespace, preloaded with put-if-absent, so a key is
never both plain-written and CAS-guarded (an unsupported mix); plain keys are
only preloaded when the mix uses read/update. Streaming variants apply on the
same threshold as the plain ops. Works unchanged in simple and cluster mode.

Two tests pin the accounting invariants against an in-process gRPC server:
every attempt is a win or a mismatch, a lost race is never an error, and the
server applied exactly one version bump per reported win; a single worker
never mismatches.

The single-node and 3-node cluster benchmarks each gain a contended CAS step
(16 workers over 200 keys, 100 B) and a mixed read=70,cas=30 step at 100 KB
(raw-file tier, so CAS wins spill and reclaim under compaction). Live smoke on
a real server: 4000 contended attempts, 7.3% mismatch rate, 0 errors.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YCoN4Him5ZY4hZovVp37ra
Signed-off-by: Ovais Tariq <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Greptile Summary

The latest changes address both previous review findings:

  • Preload summaries and failure thresholds now use the number of attempted namespace puts.
  • CAS win, mismatch, and error classification is centralized in metrics.go.
  • Both previous threads are resolved, and the current code implements the claimed fixes.

Confidence Score: 5/5

The PR appears safe to merge; both previous findings are resolved and no new actionable issue was introduced by the follow-up changes.

Preload accounting now consistently uses the actual number of attempted puts, and CAS result classification is centralized in the metrics layer as required. The previous threads were manually resolved after the corresponding fixes, and no blocking failure remains.

Important Files Changed

Filename Overview
client/cmd/ycsb/metrics.go Adds centralized CAS result classification, correctly recognizing wrapped version-mismatch errors and excluding expected mismatches from benchmark errors.
client/cmd/ycsb/ycsb.go Uses enabled namespaces to size preload accounting and delegates conditional-write result classification to the metrics layer.
client/cmd/ycsb/ycsb_test.go Exercises CAS win and mismatch accounting against an in-process version-aware server.
client/cmd/ycsb/progress_pterm.go Reports CAS attempts, wins, mismatches, and mismatch rate separately from errors.
.github/workflows/benchmark-single.yml Adds uncontended, contended, and mixed large-value CAS benchmarks for single-node CI.
.github/workflows/benchmark-cluster-3n.yml Adds equivalent CAS benchmark coverage for the three-node cluster workflow.

Reviews (3): Last reviewed commit: "fix(bench): size preload accounting by p..." | Re-trigger Greptile

Comment thread client/cmd/ycsb/ycsb.go Resolved
efirs
efirs previously approved these changes Sep 7, 2026
The contended CAS step deliberately runs 16 workers over 200 keys to produce a
measurable mismatch rate, but that conflates CAS cost with 2x the concurrency
and a 5x narrower keyspace than the plain 100-byte baselines use. Add a step at
the plain defaults (8 workers, 1000 keys, 100 B) so the only variable is the op
itself, isolating what one guarded read-modify-write costs over its two
constituent RPCs — and letting the contended run be read purely as the
contention signal. Placed before the contended step in both workflows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YCoN4Him5ZY4hZovVp37ra
Signed-off-by: Ovais Tariq <[email protected]>
@ovaistariq

Copy link
Copy Markdown
Contributor Author

@greptile

Comment thread client/cmd/ycsb/ycsb.go Resolved
…fication

In a mixed plain/CAS workload each key index does one preload put per enabled
namespace, but the preload summary and the 10% failure threshold divided by
cfg.NumKeys, so a run with errors could report "Preloaded 1999/1000 keys" and
errors across both namespaces could abort a run that was within tolerance per
namespace. Size both by the number of puts actually attempted.

Move the win/mismatch/error classification of a conditional-write result into
the metrics layer (ClassifyCASResult, with a CASOutcome type); the worker and
the preload now only count what it returns, and the lost-race rule — a
VersionMismatchError is a mismatch with no error — is stated in one place.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YCoN4Him5ZY4hZovVp37ra
Signed-off-by: Ovais Tariq <[email protected]>
@ovaistariq

Copy link
Copy Markdown
Contributor Author

Addressed both findings in 67ec315: preload accounting is now sized by puts attempted (NumKeys per enabled namespace) for both the summary and the failure threshold, and CAS win/mismatch/error classification is centralized in the metrics layer (ClassifyCASResult) with the worker and preload only counting outcomes. @greptile please re-review.

@ovaistariq
ovaistariq merged commit e88de8d into main Sep 7, 2026
8 checks passed
@ovaistariq
ovaistariq deleted the feat/cas-bench branch September 7, 2026 05:27
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

ovaistariq pushed a commit that referenced this pull request Sep 9, 2026
Preload writes went one at a time: preloadKeys waited for each Put or
PutStream before issuing the next, so the configured concurrency never
applied to the load phase. One deterministic producer now generates
keys and values in the original order (the RNG state after preload is
unchanged), a worker pool sized by the configured concurrency performs
the puts, and one collector owns the accounting, the 10% failure
threshold, and the spinner. The job queue is bounded so values are
released as their put completes.

Rebased onto main after #260: the pool carries both the plain and the
CAS preload namespaces and keeps the puts-based accounting; the tests
were ported onto the CAS-aware test server. The PR's commits were
squashed by the rebase.

Signed-off-by: Perfloop Agent <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YCoN4Him5ZY4hZovVp37ra
ovaistariq pushed a commit that referenced this pull request Sep 9, 2026
Preload writes went one at a time: preloadKeys waited for each Put or
PutStream before issuing the next, so the configured concurrency never
applied to the load phase. One deterministic producer now generates
keys and values in the original order (the RNG state after preload is
unchanged), a worker pool sized by the configured concurrency performs
the puts, and one collector owns the accounting, the 10% failure
threshold, and the spinner. The job queue is bounded so values are
released as their put completes.

Rebased onto main after #260: the pool carries both the plain and the
CAS preload namespaces and keeps the puts-based accounting; the tests
were ported onto the CAS-aware test server. The PR's commits were
squashed by the rebase.

Signed-off-by: Perfloop Agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants