Repository navigation
Description
Parent
#363 (Stage 0 of the N-replica save plan, research of 2026-11-06).
Benchmark
This issue builds the baseline tool. Its numbers are the before for #704 and #706.
| Field | Value |
|---|---|
| Metric | Unnamed version rows per minute per pad, with typers on k of R replicas (R = 2, 3; k = 1..R). Lock skips and job-id dedupes (count). document_store_outcome_total by outcome (count, seeded at 0). Ladder, one room, N = 40 sockets, R = 2: hot-replica CPU, nodejs_eventloop_lag_max_seconds and nodejs_eventloop_lag_p99_seconds, RSS. Production: unnamed websocket rows per co-edited pad-minute; adjacent byte-equal unnamed pairs over all adjacent pairs. The rollout PUBSUB read lives in #705 Step 0. |
| Before | Local, 2026-11-16 to 2026-11-18, n = 5 per cell (Measured): rows per minute 0.90 with 1 typer, 1.90 with 2 and 2.90 with 3, at R = 2 and R = 3, both fixtures. Lock skips and job-id dedupes 0. Only inserted moves. Ladder, R = 2, N = 40, 1 typer: hot-replica lag max 15.8 ms on 2 KB and 28.1 ms on 500 KB. Production: not measured yet: the maintainer runs the aggregate SQL over 7 days from 2026-11-11 08:34Z, and posts counts here and on #706 by 2026-11-19. The post lists every deploy inside the window. |
| After | not measured yet. The outcomes unchanged, head-moved and coalesced move only after #704 and #706, so this issue has no after of its own. |
| Condition | Named laptop, Bun 1.4.4, apps/hocuspocus.server/scripts/lib/prodModeStack.ts with the Redis extension, commit SHA recorded. Typer at 5 characters per second, 10 minutes per run. Fixtures: the 2 KB fixture and the seed 726 fixture (about 3.6 MB). The seed 726 rows are context, no claim: #706's local bar is absolute, and #704 and #726 use bench-content-write.ts. Production: deployed SHA, collab database in London on PostgreSQL 18.6. |
| How to run | apps/hocuspocus.server/scripts/redis-sync-probe.ts in N-instance mode on prodModeStack.ts. The probe builds the 2 KB fixture from a fixed seed. Pass --fixture <path> for the seed 726 fixture. Production rows: the aggregate SQL below. Rows-per-minute before: jobs_total{queue="store-documents",status="completed"} and a Documents row count. |
| Pass rule | No pass bar: this is a baseline. Done when the table and the ladder are posted at n = 5 per cell. Stop rule: none, because no behaviour changes. Gate floor, for #706: if coedited_pad_minutes is below 30, the read is a hint, and the #706 gate stays shut. |
| Guard | The panel and the seeded counter add no save-path change. No content-safety list is needed. |
| Owner | Agent in the repo: probe, local runs and the panel. Maintainer: production SQL. |
| Claim | None for marketing. It is the ledger before for #704 and #706. |
Why
Each collab replica with a local typer runs its own 10 s / 60 s save clock, so version rows grow with the number of replicas. Before any change to the save path, we need counters and a baseline. Every current capacity ceiling predates the awareness guard, the #595 patch and Prisma 7.
What to build
- Agent in the repo.
apps/hocuspocus.server/src/lib/metrics.ts: adddocument_store_outcome_total{outcome="inserted|unchanged|coalesced|head-moved"}. Seed it at 0 inseedWorkerAlertSeriesandseedWsAlertSeries. Amended 2026-11-10:document_store_lock_lost_totalmoves to Save anyway when the Redis store lock is lost #707. - ~~Agent in the repo.
apps/hocuspocus.server/src/config/hocuspocus.config.ts(~L128-144): a flag that wires extension-redis in a local harness.~~ Dropped, maintainer ruling 2026-11-11 (ruling). The N-instance probe runs onscripts/lib/prodModeStack.ts, which already starts production mode with the Redis extension. - Agent in the repo.
apps/hocuspocus.server/scripts/redis-sync-probe.ts(~L199): replace the hard-coded['A','B']with an N-instance mode. Build it onscripts/lib/prodModeStack.ts. Its default fixture is a local-only Notes file today. Build the 2 KB fixture from a fixed seed instead, and keep--fixture <path>for the seed 726 fixture. - Agent in the repo. A dashboard panel: a
document_store_outcome_totalrate by outcome inscripts/observability/grafana/provisioning/dashboards/json/app-performance.json.
Measure (local)
- Rows per minute with typers on k of R replicas, for k = 1..R and R = 2, 3. Count lock skips and job-id dedupes.
- Scripted typer at 5 characters per second, 10-minute runs, the 2 KB fixture and the seed 726 fixture (seed 726 rows: context, no claim). n = 5 runs per cell, median and range. Name the machine, Bun version and commit.
- The one-room ladder at N = 40 sockets and R = 2, on a ~2 KB and a ~500 KB doc. Record hot-replica CPU, event-loop lag max and p99 (
nodejs_eventloop_lag_max_secondsandnodejs_eventloop_lag_p99_seconds) and RSS. Amended 2026-11-10: the other rungs (N = 100 and N = 200, R = 1 and R = 3) are deferred. - The rows-per-minute before comes from
jobs_total{queue="store-documents",status="completed"}and aDocumentsrow count. Seeddocument_store_outcome_totalforinserted,unchanged,head-movedandcoalescedat 0. A #1151 repro at 3 instances, and at 4 with mixed versions (input for Stop a room on 3 replicas from saving a truncated document during a rolling deploy #705).Moved to Stop a room on 3 replicas from saving a truncated document during a rolling deploy #705 on 2026-11-10: it runs only when Stop a room on 3 replicas from saving a truncated document during a rolling deploy #705's gate opens.Classify the 5 zero-diff pairs on a local copy: do the state vector and delete set match, and is the op aDeferred on 2026-11-10: it feeds only block fingerprints, which Skip a save that adds nothing, and merge its contributors #704 keeps out of scope.toc-idorkeyIdwrite? Never run this inside a production container.
Measure (production, maintainer)
Reads only the maintainer runs on production. Window: 7 days from 2026-11-11 08:34Z. Post counts only, here and on #706, by 2026-11-19. The post lists every deploy inside the window.
-
Unnamed
websocketrows per co-edited pad-minute, and adjacent byte-equal unnamed pairs over all adjacent pairs. One aggregate-only SQL. A head can hold 12.5 MB, so the query compares lengths first.octet_lengthreads the stored length without loading the value. Only neighbours of equal length are hashed. Check the cost on a local copy first. Find the cause of the +199.1 MB collab database growth on 2026-11-07 #761 step 3 uses the same form.BEGIN READ ONLY; SET LOCAL statement_timeout = '120s'; WITH r AS ( SELECT id, "documentId", version, "createdAt", contributors, octet_length(data) AS len, lag(id) OVER w AS prev_id, lag(octet_length(data)) OVER w AS prev_len FROM "Documents" WHERE "createdAt" >= '2026-11-11 08:34:00+00' AND "createdAt" < '2026-11-18 08:34:00+00' AND trigger = 'websocket' AND COALESCE("commitMessage", '') = '' WINDOW w AS (PARTITION BY "documentId" ORDER BY version) ), m AS ( SELECT r."documentId", date_trunc('minute', r."createdAt") AS minute, count(DISTINCT r.version) AS rows, count(DISTINCT c.id) AS editors FROM r LEFT JOIN LATERAL unnest(r.contributors) AS c(id) ON true GROUP BY 1, 2 ), eq AS ( SELECT count(*) AS byte_equal_pairs FROM r JOIN "Documents" a ON a.id = r.id JOIN "Documents" b ON b.id = r.prev_id WHERE r.len = r.prev_len AND md5(a.data) = md5(b.data) ) SELECT count(*) FILTER (WHERE editors >= 2) AS coedited_pad_minutes, sum(rows) FILTER (WHERE editors >= 2) AS coedited_rows, round(avg(rows) FILTER (WHERE editors >= 2), 3) AS rows_per_coedited_pad_minute, (SELECT count(*) FROM r WHERE prev_id IS NOT NULL) AS adjacent_pairs, (SELECT byte_equal_pairs FROM eq) AS byte_equal_pairs FROM m; ROLLBACK;
A pad-minute is co-edited when its rows name 2 or more distinct contributors.
prev_idis the previous unnamedwebsocketrow of the same pad. First, the agent checks one fact on a local copy.contributorsmust hold the editors of that row, not of the whole pad. -
The 2026-11-06 plan also listed adjacent rows that share one
commitMessage. The byte-equal pairs read above replaces it. -
The
PUBSUB NUMSUBread moved to Stop a room on 3 replicas from saving a truncated document during a rolling deploy #705 Step 0. It is a point read. With 2 WebSocket replicas, a channel passes 2 subscribers only during a rollout. So a 7-day window cannot hold it.
Done when
-
document_store_outcome_totalexists, is seeded at 0, and shows on theapp-performance.jsonpanel. Amended 2026-11-10. -
The harness flag exists and is off in production config.Dropped, maintainer ruling 2026-11-11 (ruling): the N-instance probe runs onprodModeStack.ts. - The probe runs with N instances.
- A "Measured" comment here, linked from Skip a save that adds nothing, and merge its contributors #704 and Fold saves into one version per minute per document #706, holds the rows-per-minute table and the one-room ladder.
- The production SQL counts are posted here and on Fold saves into one version per minute per document #706 by 2026-11-19, with the list of deploys inside the window.
-
The 5 zero-diff pairs are classified in a comment.Deferred, maintainer ruling 2026-11-10.
Related
#704 and #706 take their before from this issue. #705 has its own gate read, and owns the rollout PUBSUB read. #726 ran its local before on prodModeStack.ts. #761 step 3 reuses the length-first SQL.
Activity
HMarzban commentedon Nov 10, 2026
Maintainer ruling, 2026-11-10
Answer: "yes". This trims the issue to what #726 and #704 need. It comes from the storage-at-scale review of 2026-11-10, which found the persist path right-sized for today. During the 2026-11-09 burst the live load was 10-14 sockets and 6-8 rooms, and host CPU stayed at 13.2 % or less.
redis-sync-probe.ts,document_store_outcome_totalseeded at 0, the rows-per-minute table, and the one-room ladder at N = 40 sockets and R = 2. A room of 46 sockets is on record (2026-09-26).document_store_lock_lost_total. Only Save anyway when the Redis store lock is lost #707's patched library can count a lost store lock.The body is amended to match, and each changed line carries this date.
HMarzban commentedon Nov 11, 2026
Maintainer ruling, 2026-11-11
The N-instance probe runs on
apps/hocuspocus.server/scripts/lib/prodModeStack.ts, which already starts production mode with the Redis extension. Drop the harness flag inhocuspocus.config.ts. This overturns "Keep: the harness flag" from the 2026-11-10 ruling. Reason: the #726 local before already ran onprodModeStack.ts, and a new flag in production config adds risk for no gain.HMarzban commentedon Nov 13, 2026
Maintainer ruling, 2026-11-13: moved to v2.3.7. It cannot finish by the 2026-11-14 cut. Its production read is due 2026-11-19, its local table needs 10 to 11 h of runs, and its consumers #704 and #706 are in v2.3.7.
SQL fixed in the body. Every autosave stores
'', notNULL(apps/hocuspocus.server/src/lib/queue.ts:472). On a local copy, 1,388 of 1,388websocketrows hold''. The filter is nowCOALESCE("commitMessage", '') = '', so the count no longer reads 0 for the wrong reason.test(hocuspocus): add saved and N-replica modes to the sync probe
feat(hocuspocus): count store outcomes per save
HMarzban commentedon Nov 16, 2026
Measured, 2026-11-16
This comment covers the agent's code steps and a short local smoke. The 10-11 h table and the ladder have not run yet. Their command is below.
What changed
apps/hocuspocus.server/src/lib/metrics.ts: newdocument_store_outcome_total{outcome}, withinserted,unchanged,coalescedandhead-moved.seedWsAlertSeriesandseedWorkerAlertSeriesboth seed all four at 0.document_store_lock_lost_totalis not here, because it moved to Save anyway when the Redis store lock is lost #707.insertedcounts once per committed row. It counts in the worker after theFOR UPDATEtransaction (src/lib/queue.ts), and in the queue-down fallback (noteFallbackHead). Neither call can throw, and no save behaviour changed. The other three labels have no code path until Skip a save that adds nothing, and merge its contributors #704 and Fold saves into one version per minute per document #706.apps/hocuspocus.server/scripts/redis-sync-probe.ts:--instances Nreplaces['A','B']. The new--mode rowsputs typers on k of R replicas and adds idle sockets with--sockets. It starts one worker throughscripts/lib/prodModeStack.ts. It reports rows per minute,jobs_totalcompleted, outcome deltas, job-id dedupes and lock skips. It also reports CPU,nodejs_eventloop_lag_max_seconds,nodejs_eventloop_lag_p99_secondsand RSS for each replica.--fixture-bytes 512000gives the ~500 KB doc, and--fixture <path>still overrides. The other modes keep their Notes default for now, because Send save confirmations and access frames to local connections only #758 measured on it today.--stagger-ms). Typers that start together share one 60 s save clock. In 2 aborted runs (aborted/before-r2k2-1.json,-2.json), the redlock then skipped about 1 save in 2. That is an artifact of the probe, not a production fact. The redlock's DB 0 use is a library fact:@sesamecare-oss/redlock1.4.0 defaultssettings.dbto 0 (build/index.js,build/scripts.js), and extension-redis passes only{ retryCount: 0 }. Not checked on production.app-performance.json: panel 81, "Document Store Outcomes per Minute". It shows60 * sum by (outcome) (rate(document_store_outcome_total{job=~"hocuspocus-server|hocuspocus-worker"}[5m])).Smoke, before and after the counter
Apple M5 Max, Bun 1.4.4, HEAD
3bd5ca1c0plus the uncommitted batch, now committed as4dae404ec(counter, panel) andbd9c845c5(probe), local Postgres and Redis DB 6. R = 2, k = 2, 2 KB fixture, 5 characters per second, 3-minute window, worker concurrency 1. Source: probe JSON per run.insertedin the windowjobs_totalcompletedOther smokes, after the change, n = 1:
inserted5. There were 0 lock skips in the window and 2 of 3 in the tail.inserted1.When typing stops on every replica at once, the final flushes collide on the redlock. So the tail shows 1 skip per extra replica.
Gates
hocuspocus.config.tsis on the ESLint ignore list.bun run typecheckinapps/hocuspocus.server: pass.bun test tests/unit/hocuspocusConfig.test.ts tests/integration/disconnectOnce.test.ts: 15 pass.promtool check rules(prom/prometheus:v3.12.0) accepts the expr.Full table and ladder (not run, about 11.5 h)
Run from
apps/hocuspocus.server. Build the seed 726 file first. Its builder (build-seed726-fixture.ts) is a local scratch script, not in the repo yet, so this command cannot run from the repo alone (Left). Then run each line 5 times:Left
contributorsholds one row's editors. Owner: maintainer or agent.REDIS_DBsays. Not checked on production. Owner: maintainer.--fixture-seed 726option onscripts/lib/benchFixture.ts. Owner: agent, before the ladder runs.start(), notprodModeStack.spawnWs, because the Send save confirmations and access frames to local connections only #758 saved mode needs a per-instance env thatspawnWscannot take yet. Move them once it can. Owner: agent.After the deploy
Deployed with
(build): front back(06f61ee44, run 43876524495, 2026-11-16 13:31Z, Build Images and Deploy Production success). Read-only, production, 2026-11-16 13:48Z:document_store_outcome_totalexists on the worker and the collaboration server. The worker readsinserted= 8;unchanged,coalescedandhead-movedread 0, as planned. The panel (AP 81) is live since the observability deploy (288d4d260).test(hocuspocus): let spawnWs take per-instance env
test(hocuspocus): build the seed 726 fixture in the sync probe
HMarzban commentedon Nov 16, 2026
Measured, 2026-11-16
Commits
a4f4562d8(spawnWs) and84993afa8(probe). The fixture isbuildFixture(mulberry32(seed), 3 MiB)frombenchFixture.ts, as the #726 runs used, not thebench-content-write.tstext, which seeds each run with seed + run.This covers the two agent items under Left in today's earlier comment: the seed 726 fixture, and the move to
spawnWs. The 10-11 h table and the ladder have not run. Their command is below.What changed
apps/hocuspocus.server/scripts/redis-sync-probe.ts: new--fixture-seed <n>. It builds the Cut MCP write time on large pads and stop its four false alerts #726 bench text in the probe:buildFixture(mulberry32(n), 3 MiB)fromscripts/lib/benchFixture.ts, thenTiptapTransformer.toYdocwithmigrationExtensions. It copies the root nodes into aY.Docwith a fixed client ID (2 ** 31 + seed). No new file. Passing it with--fixturethrows before any setup.apps/hocuspocus.server/scripts/lib/prodModeStack.ts:spawnWs(label, base, env = {}). The per-instance env is applied for each replica; the port and health keys still come fromspawnWs. On a failed start,spawnWsnow kills its own child.bench-content-write.tskeeps calling it with two arguments.spawnWs. Saved mode passes A's Redis proxy as env.--log-diraddsREDIS_LOG_LEVEL=warn. The probe's own Postgres TLS proxy is replaced bystartPgTlsProxy. Replica logs go to<log-dir>/<label>.log, or else to the scratch dir. A failed run keeps that dir and prints its path.prodModeStack's offline env: Supabase on a closed port, no email provider,SOCIAL_CARD_KINDS=document. The counts below show no change.Seed 726 fixture
The source is
bun -ewith the same calls asbuildBenchFixture, run fromapps/hocuspocus.server.Y.Doctakes a random client ID.4846310fb835ebe87c026669424f203f05cdc8271bb87781d95379dd2a34f3cd. The ProseMirror JSON equals the transformer's own doc.--fixture-seed 726, n = 1):fixtureBytes3,571,053, exit 0.Before and after the
spawnWsmoveApple M5 Max, Bun 1.4.4, HEAD
288d4d260. Other agents' changes were in the tree, none of them in these two files. Local Postgres and Redis. Before = a frozen copy of the probe at HEAD. After = the edited probe. Same commands, run one after the other. Source: probe JSON for each run.document:savedframes per client per savejobs_totalcompleted /insertedinsertedinsertedSanity checks, n = 1 each, no claim:
--log-dirwrote 24Redis reconnecting...warn lines toA.log.One after-run failed with
B never came up, and the agent reran it. The likely cause is a port clash fromfreePort(), which the oldstart()used too; nolsoforEADDRINUSEline was saved, so this is not proven.Gates
bun fmt --checkon the 2 files: pass.--max-warnings 0) on the 2 files: pass.bun run typecheckinapps/hocuspocus.server: pass, 501 files.Full table and ladder (not run, about 11.5 h)
Run from
apps/hocuspocus.server, in bash. It now runs from the repo alone:bash -c 'P="bun --env-file=../../.env.local scripts/redis-sync-probe.ts --mode rows --redis-db 6 --minutes 10"; mkdir -p out; for i in 1 2 3 4 5; do for c in "2 1" "2 2" "3 1" "3 2" "3 3"; do set -- $c; $P --instances $1 --typers $2 > out/r$1k$2-2kb-$i.json; $P --instances $1 --typers $2 --fixture-seed 726 > out/r$1k$2-726-$i.json; done; $P --instances 2 --typers 1 --sockets 40 > out/ladder-2kb-$i.json; $P --instances 2 --typers 1 --sockets 40 --fixture-bytes 512000 > out/ladder-500kb-$i.json; done'That is 60 runs of about 11-12 min each.
Left
contributorsholds one row's editors. Owner: maintainer or agent.REDIS_DBsays. Not checked on production. Owner: maintainer.freePort()(scripts/lib/e2eHarness.ts) can return a port that a127.0.0.1listener already holds on macOS. Seen once today. Owner: agent, if it shows up again.Done today: the seed 726 fixture is reproducible from the repo (
--fixture-seed 726), and the probe's WS replicas run onprodModeStack.spawnWs.docs(changelog): record the v2.3.7 work of 2026-11-16
docs(hocuspocus): name the store outcome and reconnect counters
HMarzban commentedon Nov 16, 2026
Review, 2026-11-16 (maintainer approved).
bench-content-write.ts.freePort()note, Redlock DB 0). They live in the 2026-11-16 comment, not the body, and this pass edits no comments.HMarzban commentedon Nov 18, 2026
Measured, 2026-11-18: the local baseline at n = 5 per cell
This is the local before for #704 and #706. No behaviour changed, so there is no after here.
Condition
scripts/lib/prodModeStack.ts: production mode, Redis extension on, local Postgres through the TLS proxy, worker concurrency 1.scripts/redis-sync-probe.ts --mode rows --redis-db 6 --minutes 10, sha2569d7615c63a7eda39493965b875323fcbb3d908c1829c941358a07f4a99fb3d0e, unchanged since84993afa8.dcd69569b, from 2026-11-16 18:28Z to 2026-11-17 10:36Z. 3 runs atafd06574bon 2026-11-18. Between the two, the save path did not change. The only server change is thews_disconnects_totalcounter, which runs on a close.Three runs were run again, each once, with the same command:
ladder-500kb-3andr3k1-726-4exited 1. The probe's own Postgres connection timed out ("Connection terminated due to connection timeout"). Each run around them passed.ladder-2kb-3finished, but the laptop went into idle sleep during it (pmset:Idle Sleep00:36Z, then a 901 sMaintenance Sleep). Both replicas show 899 s of event-loop lag, and the run saved 3 rows, not 9. The new run usedcaffeinate -i. Every other run has an event-loop lag max under 284 ms.The tables use the 3 new runs in place of the 3 old ones.
Rows with typers on k of R replicas
Counts are totals over the 5 runs, inside the 10-minute window. Rows per minute is the median (range) of the 5 runs.
What it shows:
insertedmoves, as expected:unchanged,coalescedandhead-movedhave no code path until Skip a save that adds nothing, and merge its contributors #704 or Fold saves into one version per minute per document #706.fallbackInserted0 in all 60).The ladder: one room, N = 40 sockets, R = 2, 1 typer
Median (range) over 5 runs. The hot replica holds the typer. Lag is
nodejs_eventloop_lag_max_secondsandnodejs_eventloop_lag_p99_seconds(median of the samples in a run).The seed 726 rows are context, with no claim, as ruled.
Left
HMarzban commentedon Nov 24, 2026
Measured, 2026-11-24: production SQL baseline and live outcome counters
Question: How many unnamed
websocketversion rows per co-edited pad-minute and adjacent byte-equal pairs happened in the London window (2026-11-11 08:34Zto2026-11-18 08:34Z)?Setup. Read-only Postgres transaction (
SET TRANSACTION READ ONLY,statement_timeout = '30s') against the London collab cluster, plus read-only Prometheusdocument_store_outcome_totaland Grafana dashboard check on2026-11-24 07:15Z.Result:
2026-11-11 08:34Z..2026-11-18 08:34Z)coedited_pad_minutes(editors >= 2)14coedited_rows39rows_per_coedited_pad_minute2.786adjacent_pairs(websocket, unnamed)414byte_equal_pairs5(1.20 %of adjacent pairs)Live
document_store_outcome_total& panel (2026-11-24one4d36ae0f):inserted = 135,unchanged = 0,coalesced = 0,head-moved = 0.docsplus-app-performancepanel"Document Store Outcomes per Minute"is live (60 * sum by (outcome) (rate(document_store_outcome_total{job=~"hocuspocus-server|hocuspocus-worker"}[5m]))).Deploys inside the
2026-11-11 08:34Z..2026-11-18 08:34Zwindow:43008200172(2026-11-11 10:59Z,0b302b222,(build): front)43224537614(2026-11-12 13:09Z,9f132692e,(build): back front)43434574052(2026-11-13 13:32Z,3d90636a9,(build): front back)43457071472(2026-11-13 15:53Z,eeb1ab727,(build): back observability)43474637920(2026-11-13 17:37Z,21bce9f71,(build): observability)43697520137(2026-11-15 09:05Z,b7888dce1,(build): front)43851402851(2026-11-16 10:43Z,a3ef6e83f,(build): front)43876524495(2026-11-16 13:31Z,06f61ee44,(build): front back)43878530215(2026-11-16 13:43Z,288d4d260,(build): observability)44025904215(2026-11-17 05:41Z,28037ba77,(build): front back)44027220672(2026-11-17 05:53Z,45393ece7,(build): observability)44041325574(2026-11-17 07:46Z,afd06574b,(build): front back)Cross-posted on #706. All acceptance boxes are now met; closing
#703.