You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
append(AppendCommand[]) with per-command conditions currently uses appendBatch — a multi-round-trip path:
BEGIN
Advisory lock acquisition (1 query)
getHighWaterMark (1 query)
COPY events to main table
CREATE TEMP TABLE + COPY conditions
JOIN-based condition check
currval
pg_notify
COMMIT
~10 round-trips per call. Benchmarked at 2,600 ev/s for 500 commands × 1 event each (T16).
Compare: single-command appendViaFunction does everything in 1 round-trip via stored procedure — benchmarked at 22,000 ev/s (T1) for single-event conditional appends.
Proposed solution
A stored procedure that accepts arrays of commands and does the full loop server-side:
Acquire advisory locks (already done in SP for single commands)
INSERT all events via unnest/generate_subscripts
Per-command condition check against pre-insert snapshot (highWaterMark pattern)
RAISE on first violation with command index
pg_notify + return last position
Single round-trip. Expected gain: 5-8x for batch commands with per-event conditions.
Benchmark baseline (from event-store-bench T16)
Cmds/append
Current ev/s
p50
1
811
6ms
10
1,619
45ms
50
2,000
271ms
100
2,160
524ms
500
2,600
2,148ms
Target: match or approach T1's 22K ev/s at 1 cmd, and scale with batch size.
Context
Discovered via T14/T15/T16 scenarios in packages/event-store-bench
Problem
append(AppendCommand[])with per-command conditions currently usesappendBatch— a multi-round-trip path:~10 round-trips per call. Benchmarked at 2,600 ev/s for 500 commands × 1 event each (T16).
Compare: single-command
appendViaFunctiondoes everything in 1 round-trip via stored procedure — benchmarked at 22,000 ev/s (T1) for single-event conditional appends.Proposed solution
A stored procedure that accepts arrays of commands and does the full loop server-side:
Single round-trip. Expected gain: 5-8x for batch commands with per-event conditions.
Benchmark baseline (from event-store-bench T16)
Target: match or approach T1's 22K ev/s at 1 cmd, and scale with batch size.
Context
packages/event-store-bench