Gateway: cut per-event relay hops (staging channel, dashboard mirror, pipe reader, gRPC BufferHint) #235
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up from the worker CPU investigation (240 ev/s on wonder-app-vd03; branch
feat/worker-perf-prototype, commit659bb831). The gateway's .NET 10 PortableThreadPool spin-waits after each per-event work item; each event currently costs ~6 of our pool work items plus 2–3 of Kestrel's (~2.1 spin spells per frame). The spin limit (UnfairSemaphoreSpinLimit=10, in659bb831) trims the cost; these remove the hops themselves.Ranked:
AllowSynchronousContinuations=trueon_eventStagingand_events, or run mapping + fan-out inline on the read loop (WorkerClient.cs:723,753-768,791). Saves ~2 pool items/event.GatewaySession.cs:656,851,942-960) only while a viewer exists; consider a per-subscriber predicate at the distributor so the alarm monitor (GatewayAlarmMonitor.cs:285-305) stops waking on every data change. Saves ~1/event.WorkerFrameReader.cs:46,72) with aPipeReaderor a 64 KiB pooled buffer — currently two read completions per frame.WriteOptions(WriteFlags.BufferHint)whileEventStreamService.cs:224has more buffered, flush on the last. Verify grpc-dotnetBufferHintsemantics first.Measure with the windev bench (
C:\build\perfbench\bench-run.ps1, ~242 ev/s): gateway CPU baseline 8.1% of a core, 6.9% with the spin limit. Lower priority: per-event metrics dictionary lookups (GatewayMetrics.cs:253-260), send-latency histogram sampling (MxAccessGatewayService.cs:187-206), and aWorkerEventBatchcontract change only if per-frame cost still shows.Implemented, not merged or deployed. Branch
feat/gateway-relay-hops, three commits stacked on R1 (feat/worker-perf-prototype):ReadEventsAsyncreader must never block synchronously") is documented inIWorkerClientand indocs/GatewayProcessDesign.md("Event path threading").IDashboardViewerPresence). Internal subscribers can pass a filter, so the alarm monitor no longer wakes on data changes. ACL and redaction are unchanged.EndOfStream.BufferHint: skipped. The semantics work in grpc-dotnet, but at ~4 ms event spacing the next event is almost never waiting, and doing it safely needs manual flushes (for example on resume-filtered events).Tests: full gateway suite on macOS 1478 passed / 0 failed / 6 skipped; affected tests re-run on the combined R1+R2 stack 616/616.
windev bench (~242 ev/s, dashboard off, spin limit on in both): gateway 7.26% → 5.99% of a core (−17.5%), context switches about −⅓. Item 2's saving isn't in that number.
Possible pre-existing flake:
EventStreamServiceTests.StreamEventsAsync_WhenWorkerFaultsUnderTwoSubscribers_CountsTheFaultOncefailed once in a large filtered run (the pump's readiness check lost a race with the fault) and passed on six reruns.Rollout: this is R2 in
docs/plans/2026-11-21-worker-perf-rollout.md. It deploys to vd03 after R1 has soaked; see #236.The 2026-12-02 bug + perf review (MXA-002 / WIP-002) confirmed that none of the event-path CPU fixes are on
mainat54367e74. They live only onfeat/worker-perf-prototype→feat/gateway-relay-hops→fix/readbulk-subscription-teardown, each 2 commits behind main. Landing them is Phase 1 of the fix plan: #252.Merged to
mainat68043411(pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA.The relay-hop commits landed with Phase 1 (#252). Deployment state is tracked on #236.