ScadaBridge: cap .NET thread-pool spin (UnfairSemaphoreSpinLimit) #237
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?
Cross-repo item from the vd03 CPU investigation. In the WPR trace on wonder-app-vd03,
ZB.MOM.WW.ScadaBridge.Hosthad 229k context switches — almost as many asMxGateway.Server(240k), and more than the worker. In the gateway, 93% of switches were the .NET PortableThreadPoolLowLevelLifoSemaphorespin-waiting withSleep(0)yields after each per-event work item; ScadaBridge consumes the same event stream and likely has the same pattern.mxaccessgw fixed its side in
659bb831with<RuntimeHostConfigurationOption Include="System.Threading.ThreadPool.UnfairSemaphoreSpinLimit" Value="10" />in the Server csproj (env formDOTNET_ThreadPool_UnfairSemaphoreSpinLimit=10). windev bench: gateway CPU 8.1% → 6.9% of a core at ~242 ev/s.To do (in ScadaBridge):
ScadaBridge: cap .NET thread-pool spin (UnfairSemaphoreSpinLimit) — ScadaBridge#?to ScadaBridge: cap .NET thread-pool spin (UnfairSemaphoreSpinLimit)Mirrored in ScadaBridge#146.
Gateway-side numbers to compare against when ScadaBridge measures: with the spin limit, the mxgw gateway went 8.1% → 6.9% of a core on windev. Removing the relay hops (#235, branch
feat/gateway-relay-hops) took it a further −17.5%. If ScadaBridge's MxGateway adapter shows the same pattern, the same two patterns apply: synchronous continuations on the internal channel hand-off, and not waking idle consumers per event.Done on the ScadaBridge side. ScadaBridge#146 is closed. ScadaBridge
mainb47002b4addsUnfairSemaphoreSpinLimit=10to the Host csproj, with aRuntimeConfigTestsguard and a "Runtime thread-pool settings" section indocs/requirements/Component-Host.md. Host is the only ScadaBridge process that consumes the MxGateway event stream.Adapter review: no relay-hop pattern.
RealMxGatewayClientruns oneawait foreachoverStreamEventsAsyncand invokes callbacks inline. There are no internal channels and no per-eventTask.Run, only the inherent AkkaTellintoDataConnectionActor. The mxgw .NET client (clients/dotnet) has noChannel.Create/Task.Runon the stream path either.Remaining: measure the context-switch reduction on vd03 once a ScadaBridge build with
b47002b4is deployed. That belongs with the normal ScadaBridge deploy, not this issue. Closing.