Skip to main content

Module ws_timing

Module ws_timing 

Source
Expand description

Lightweight WS message-throughput instrumentation.

Counts inbound (client → server) and outbound (server → client) WS messages per kind into atomic counters, and a single dedicated thread emits a summary log line every WINDOW_MS. No per-message log I/O, no allocations on the hot path, no work when no messages flowed.

Used to diagnose “server CPU is idle but loads are slow” — comparing the inbound and outbound rates against the client-side equivalents tells us whether time is in server-reply latency, client-send pacing, or round-trip.

Functions§

message_kind
Stable 'static kind tag for a message. Must match what the TS client emits for symmetric cross-side correlation.
message_tag
The specific command/query/report/view id carried by a message, when the wire type carries one directly. *Request and *Error variants carry their id inline; *Response/*Cancel/*Window variants only carry tx (the id lives in a tx→id side table the caller already tracks per subscription) — those return None here rather than duplicating that lookup.
record_inbound
Record an inbound WS message (already parsed). kind should be the 'static discriminant string from message_kind.
record_inbound_for_client
Same as record_inbound, plus an OTLP counter tagged by client_id and tag (the specific command/query/report/view id, from message_tag, when the message carries one) — the aggregate DashMap counters above are cheap enough for an unbounded number of message kinds, but tagging those by client_id/tag too would put an OTel series per (kind × client × tag) into the periodic in-process log line, which is the wrong place for this breakdown. This is that breakdown, exported as a proper metric instead (cardinality bounded by concurrent connections × distinct command/query/report/view ids, which is the norm for these tags).
record_outbound
Record an outbound WS message about to be serialized to the wire.
record_outbound_for_client
Same as record_outbound, plus a per-client/per-tag OTLP counter — see record_inbound_for_client.
start_periodic_logger
Spawn the dedicated summary thread. Idempotent — safe to call from any number of CellServerCtx::new invocations.