perf(gateway): attach the dashboard mirror only while a viewer watches (#235)
Every session ran a dashboard-mirror distributor subscriber that woke for every event only for Publish to discard it, since normally nobody has a session-details page open. The viewer registry now raises ViewerPresenceChanged on a session's first viewer and last viewer; the production broadcaster exposes it as IDashboardViewerPresence, and a session attaches its mirror while watched and disposes the lease when not. MarkReady still starts the pump, so draining, replay retention, the alarm lease and dead-worker detection are unchanged. ACL and value redaction are untouched. Broadcasters without presence (test doubles) keep the always-on mirror. Internal distributor subscribers can now pass a filter applied before the pump's TryWrite; the alarm monitor admits only alarm transitions and provider mode changes, so data changes no longer wake it.
This commit is contained in:
+5
-3
@@ -152,16 +152,18 @@ The monitor consumes its session's events as an **internal distributor
|
||||
subscriber** (`GatewaySession.AttachInternalEventSubscriber`), not by draining
|
||||
the worker event channel directly. The single worker event channel therefore has
|
||||
exactly one reader — the per-session `SessionEventDistributor` pump — which fans
|
||||
every event to both the dashboard mirror and the alarm feed; the alarm subscriber
|
||||
events to the dashboard mirror and the alarm feed; the alarm subscriber
|
||||
is internal (`isInternal: true`), so it is not counted against
|
||||
`MaxEventSubscribersPerSession` and a slow alarm reconcile can never fault the
|
||||
session. The worker event channel is single-reader and asserts it (a second
|
||||
`WorkerClient.ReadEventsAsync` consumer throws), so a regression cannot silently
|
||||
split the event stream between two drains.
|
||||
split the event stream between two drains. The monitor's lease carries a
|
||||
distributor-side filter that admits only `OnAlarmTransition` and
|
||||
`OnAlarmProviderModeChanged`, so data changes on its session never wake it.
|
||||
|
||||
The monitor takes that internal lease **before** it sends `SubscribeAlarms`, and
|
||||
drains it after the first reconcile. The pump is already running by then (the
|
||||
dashboard mirror starts it at `MarkReady`) and the distributor fans only to
|
||||
session starts it at `MarkReady`) and the distributor fans only to
|
||||
subscribers registered at fan-out time, so attaching after the subscribe +
|
||||
reconcile round trips would drop every transition raised in that window —
|
||||
including an `Acknowledge`, which the presence-only reconcile deltas would never
|
||||
|
||||
Reference in New Issue
Block a user