Performance & Concurrency Baseline (Cloudflare Worker)
Quick summary
First measured baseline for the be-cloudflare stack (S2-08): reconciliation scan throughput, settlement claim throughput, audit v2 verify/checkpoint cost, and concurrency behavior — all on wrangler dev --local + local D1.
Scope warning: every number below was measured on local miniflare sqlite with a single workerd process, CLI-side wall clock. Do not extrapolate to remote Worker CPU time, D1 latency, or production cost/SLA. Remote re-measurement is a separate (S3) scope item.
Source artifact: be-cloudflare/tests/perf-baseline-out/perf-results.json (schema devpay-perf-baseline/v1, bound to the commit that produced it). Runner: bash be-cloudflare/tests/run-perf-baseline.sh (build → .dev.vars → fresh local D1 → wrangler dev → measurement suite). Suite is standalone and exits nonzero on FAIL legs.
Environment
| Item | Value |
|---|---|
| CPU | AMD Ryzen 7 9700X (8 cores / 16 threads) |
| RAM | 15.5 GB |
| OS | Linux 6.6 (WSL2) x64 |
| Runtime | node v22.23.4, wrangler 4.156.0, miniflare local D1 |
Reconciliation scan
POST /api/v1/admin/reconciliation/run (budget 50 000 rows/invocation, page 1000) over a clean consistent dataset (orders+payments+ledger; seller-scoped rows, 0 findings).
| Dataset (orders) | Wall time | Invocations | Rows scanned | Throughput |
|---|---|---|---|---|
| 100 | ~0.33 s | 1 | ~800 | ~2.4k rows/s |
| 1 000 | ~0.59 s | 1 | ~8 000 | ~13.7k rows/s |
| 10 000 | ~24.6 s | 2 (budget pause→resume) | ~80 000 | ~3.3k rows/s |
- Per-check
scanned/total/remainingare recorded per check in the artifact; per-check wall time is not isolated (engine evaluates checks sequentially inside one invocation — only invocation-level wall is honest). - Estimated D1 ops are derived per check as
seg counts + page fetches + viol queriesand stored asest_d1_ops(estimate, not a driver counter). - Scan completeness held at every tier (
remaining=0, runcompleted).
Settlement commit
POST /api/v1/settlements claiming N settleable orders for one seller (claim UPDATE chunks of 90 → validate → one atomic record batch: retag + settlement + ledger + audit + outbox + COMMITTED).
| Orders | Wall time | Claims/s | Extra rows written |
|---|---|---|---|
| 100 | ~0.13 s | ~750 | ledger 1 · audit v1 1 · audit v2 1 · evidence 1 · outbox 1 |
| 1 000 | ~0.37 s | ~2.7k | same |
| 10 000 | ~1.53 s | ~6.6k | same |
Per-commit write shape is flat in N (claims are ceil(N/90) batch calls of ~90 UPDATEs + ~12 statements in the atomic record batch + ~4 ops for the audit emit).
Recon pause/resume at finding scale
1 200 seeded orphan settlement claims → INVOCATION_FINDINGS_CAP=500 paused the run as expected and resume completed it:
- 5 invocations, all 1 200 findings recorded, 300 auto-fixes applied, 0 residual claims.
- Anomaly: one finding-flood invocation took ~89 s on local miniflare — a single persist batch of ~500 finding INSERTs + auto-fix UPDATEs + exception sync + causal lookups. This is the dominant cost of a flooding check; consider smaller
INVOCATION_FINDINGS_CAPor split persistence if recon runs under a request-duration budget.
Audit v2 chain
Synthetic but valid-HMAC chain rows (key from local .dev.vars; the verifier recomputes every row — no fake data):
| Operation | Rows | Wall time |
|---|---|---|
POST /admin/audit/checkpoints (fold) | 1 000 | ~25 ms |
POST /admin/audit/checkpoints (fold) | 4 000 | ~441 ms |
GET /admin/audit/v2/verify | ~1 000 checked | ~468 ms |
GET /admin/audit/v2/verify | 5 000 checked | ~170 ms |
GET /admin/audit/v2/verify (>5 000 rows) | 5 000 checked, truncated:true | ~554 ms |
VERIFY_LIMIT=5000truncation surfaces correctly (truncated:true,okapplies to the checked prefix only).- Audit append cost is measured indirectly: settlement/commit deltas show the emit adds ~4 sequential D1 ops (sequence CAS → prev read → chain insert → evidence insert) post-commit; there is no with/without-audit toggle — a direct A/B measurement needs a code seam, recorded as a follow-up.
Concurrency
| Probe | Result |
|---|---|
8× concurrent POST /settlements (same seller) | exactly 1 commit (200); losers converged to 409 NOTHING_TO_SETTLE — winner completed before losers' snapshot read, so no IN_PROGRESS wait was observed; wall ~0.76 s; distinct_settlements=1, 200/200 orders claimed once |
8× concurrent POST /orders/:id/refund (same order) | refunded exactly once (5000 KRW, 1 succeeded attempt, 1 ledger debit); losers → 409 NOT_PAID/REFUND_IN_PROGRESS; wall ~0.58 s |
2× wrangler dev instances, same local D1, concurrent POST /settlements | exactly 1 settlement committed (A=200); loser surfaced 500 DB not clean 409 — F-04 residual reproduced |
Two-instance mechanism: both workerd processes share the same miniflare sqlite file; the settlement lease CAS relies on D1 UPDATE … WHERE lease_owner=? atomicity. The loser's claim/CAS fails and converges to SETTLEMENT_RACE/SETTLEMENT_RUN_FAILED — surfaced as 409 or 500. Retry duty is on the client.
Volume estimate (labeled ESTIMATE)
Measured row sizes × assumed op volume — linear extrapolation, not a traffic forecast:
- Per settlement commit: ~7 durable rows (settlement, run, ledger, audit v1, v2 chain, evidence, outbox) + N order UPDATEs.
- Per payment capture: ~7 rows (order, payment, ledger, audit v1, v2, evidence, outbox).
- Avg payload sizes observed:
audit_evidence.payload_json~208 B,audit_events_v2.payload_json~47 B (synthetic rows — real evidence payloads are larger). - At 10 000 financial ops/day: ~70 000 appended rows/day across ledger+audit+evidence+outbox (estimate; retention/pruning policy out of scope).
NOT_VERIFIED / deferred
- Remote Worker CPU/D1 latency & cost — S3 scope; local numbers do not transfer.
- Per-check wall attribution inside a recon invocation (engine has no per-check timer).
- With/without-audit A/B latency (no toggle seam).
- D1 op counts are estimates, not driver-observed counters.