Skip to content

Record the size of each stored document snapshot #218

Description

@HMarzban

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

  • /metrics exposes a stored-snapshot-bytes histogram with a sample after one document save.
  • Its top bucket is above the largest snapshot seen in production.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions