mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-10 02:25:56 +00:00
0b57527b29
Under load, 5x concurrent /api/state degraded from 276ms (single) to ~4s each (linear), because every caller serialized on the monitor lock to rebuild and JSON-encode the full 1.6MB state. /api/diagnostics had the same dogpile shape on cache miss, even though its 45s TTL cache was working as designed. Wrap both handlers in a per-tenant singleflight.Group so concurrent callers share the work: 20x concurrent /api/state now completes in 358ms wall (~14-50x improvement). Diagnostics warm-cache responses are now sub-3ms; cold compute coalesces. Also drop websocket Upgrader buffers from 4MB read/write to 64KB. gorilla streams larger payloads across the buffer transparently, so the 4MB allocation per connection was overhead that scaled badly with concurrent clients (100 clients * 8MB = 800MB just in buffers). Contract-neutral: no endpoint, response body, header, or wire-format change.