diff --git a/docs/requirements/Component-Host.md b/docs/requirements/Component-Host.md index 82175752..793da6a5 100644 --- a/docs/requirements/Component-Host.md +++ b/docs/requirements/Component-Host.md @@ -250,6 +250,29 @@ own (the active node always answers Healthy), so the only event this can ever su reporting that it is a standby. The verdict remains fully observable through the HTTP status of `/health/active` itself, the readiness probe's cluster view, and the health dashboard. +### Runtime thread-pool settings + +Some settings belong to the .NET runtime, not to `ScadaBridge:*` options. They ship as +`RuntimeHostConfigurationOption` items in the Host csproj, which write them into +`ZB.MOM.WW.ScadaBridge.Host.runtimeconfig.json`. Publish carries that file, so the Windows service +install and the Docker image (`docker/Dockerfile` copies the publish output) get it with no extra +environment variables. `RuntimeConfigTests` pins it. + +| Setting | Shipped value | Why | +|---|---|---| +| `System.Threading.ThreadPool.UnfairSemaphoreSpinLimit` | `10` (runtime default `70`) | A pool worker that finds no work spins before parking, and past step 10 it calls `Sleep(0)` on every other step. Akka's default dispatcher, gRPC/Kestrel and every async continuation run on the pool (`ScriptExecutionScheduler` has its own threads), so a steady trickle of small work items, such as MxGateway events, turns those spins into context switches. With `10`, idle workers spin briefly and then park. Mirror of mxaccessgw#237 (#146). | + +What has been measured: on DEV vd03 at ~240 MxGateway events/s, a WPR trace showed 229k context +switches in the Host. That trace predates this setting and was not attributed by call stack here; +the attribution comes from the same pattern in the gateway. A synthetic local trickle benchmark (about 185 +work-item chains per second, each a few pool hops, macOS, 3 interleaved runs per value) went from +17–28k to 6–13k involuntary context switches and from 430–560 ms to 200–295 ms CPU per 20 s at +`10`. The before/after WPR comparison on vd03 is still to be done at the next vd03 deploy. + +To override on one host without rebuilding, set `DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=` +in the service or container environment. It takes precedence over runtimeconfig. `70` restores +the runtime default, and `0` disables the spin entirely. + --- ## Secrets (2026-09-28) diff --git a/src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj b/src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj index 416cccab..c34e2948 100644 --- a/src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj +++ b/src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj @@ -11,6 +11,19 @@ + + + + +