Skip to content

perf(api): right-size SSE per-subscriber channel buffer (currently hardcoded 64, untested) #152

Description

@EricAndrechek

Problem

internal/api/stream_sse.go:51:

ch := make(chan []byte, 64) // TODO: need to test how many are actually needed, as this is ~1.6KB per subscriber channel...

The SSE per-subscriber channel buffer is hardcoded to 64. At ~1.6KB per slot per subscriber that's ~100KB per stream connection — fine for hundreds of subscribers, painful for thousands. More importantly: 64 is a guess, not a measurement, and the comment admits as much.

If the buffer is undersized for a real workload, the Hub drops messages to slow subscribers (existing Hub behavior); if it's oversized, memory grows linearly with concurrent subscribers.

Proposed Solution

Two parts:

  1. Make it configurable via WH_SSE_CHANNEL_BUFFER / server.sse_channel_buffer (default current value of 64) so operators can tune without recompiling.
  2. Load-test to set a defensible default. Drive make dev-obs with N=10/100/1000 concurrent SSE subscribers and a realistic ingest rate, measure (a) drop rate at the Hub, (b) per-subscriber memory, (c) tail latency from publish → flush. Pick the smallest buffer that keeps drop-rate at 0 under expected alpha workloads. Document the experiment in docs/deployment.md so operators can re-run it.

Acceptance criteria

  • Config knob shipped (or a deliberate "not configurable yet" decision documented).
  • Default backed by measurement, not the original guess.
  • Comment at stream_sse.go:51 updated or removed.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/apiHTTP handlers, routing, middlewarearea/docsDocumentation, site/, READMEarea/observabilityMetrics, logs, traces, health, profilingarea/streamingSSE / live-query delivery path (/v1/stream)documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions