Problem
No metric records how large a stored document snapshot is.
ydoc_update_bytes looks like that metric, but it is not. It observes update.byteLength inside the onChange hook (apps/hocuspocus.server/src/hocuspocus.server.ts:214), which is one incremental Y.Doc update. The histogram says so itself: help: 'Size in bytes of each applied Y.Doc update' (apps/hocuspocus.server/src/lib/metrics.ts:176-181). Its top bucket is 1048576.
The stored snapshot is the whole document state. The enqueue path writes it to Redis (apps/hocuspocus.server/src/lib/queue.ts:156), and the worker loads it back (apps/hocuspocus.server/src/lib/queue.ts:412). It is a different and much larger number.
Without a histogram on it, an operator cannot say how close the process sits to its heap ceiling. The next performance audit also has no input to measure against.
What to do
Add a histogram for stored snapshot bytes in apps/hocuspocus.server/src/lib/metrics.ts. Observe it on the enqueue path, where the full state buffer is already in hand (apps/hocuspocus.server/src/config/hocuspocus.config.ts:237).
Choose buckets that reach the largest real document, not the largest update.
Acceptance
Problem
No metric records how large a stored document snapshot is.
ydoc_update_byteslooks like that metric, but it is not. It observesupdate.byteLengthinside theonChangehook (apps/hocuspocus.server/src/hocuspocus.server.ts:214), which is one incremental Y.Doc update. The histogram says so itself:help: 'Size in bytes of each applied Y.Doc update'(apps/hocuspocus.server/src/lib/metrics.ts:176-181). Its top bucket is 1048576.The stored snapshot is the whole document state. The enqueue path writes it to Redis (
apps/hocuspocus.server/src/lib/queue.ts:156), and the worker loads it back (apps/hocuspocus.server/src/lib/queue.ts:412). It is a different and much larger number.Without a histogram on it, an operator cannot say how close the process sits to its heap ceiling. The next performance audit also has no input to measure against.
What to do
Add a histogram for stored snapshot bytes in
apps/hocuspocus.server/src/lib/metrics.ts. Observe it on the enqueue path, where the full state buffer is already in hand (apps/hocuspocus.server/src/config/hocuspocus.config.ts:237).Choose buckets that reach the largest real document, not the largest update.
Acceptance
/metricsexposes a stored-snapshot-bytes histogram with a sample after one document save.