Cap .NET thread-pool spin (UnfairSemaphoreSpinLimit) on the ScadaBridge host #146

Closed
opened 2026-11-21 08:01:18 -05:00 by dohertj2 · 1 comment
Owner

Mirror of mxaccessgw#237; details there. On wonder-app-vd03, ZB.MOM.WW.ScadaBridge.Host showed 229k context switches in a WPR trace at ~240 MxGateway events/s. In the gateway, the same pattern was PortableThreadPool spin-waiting (Sleep(0)), which mxaccessgw capped with System.Threading.ThreadPool.UnfairSemaphoreSpinLimit=10 (mxaccessgw 659bb831). Confirm the cause here, apply the setting, measure, and document it.

Mirror of mxaccessgw#237; details there. On wonder-app-vd03, `ZB.MOM.WW.ScadaBridge.Host` showed 229k context switches in a WPR trace at ~240 MxGateway events/s. In the gateway, the same pattern was PortableThreadPool spin-waiting (`Sleep(0)`), which mxaccessgw capped with `System.Threading.ThreadPool.UnfairSemaphoreSpinLimit=10` (mxaccessgw 659bb831). Confirm the cause here, apply the setting, measure, and document it.
dohertj2 added the type:followuppriority:p2cross-repo labels 2026-11-21 08:01:18 -05:00
Author
Owner

Applied in b47002b4 (main @ d4d5be3b). The Host csproj now ships System.Threading.ThreadPool.UnfairSemaphoreSpinLimit=10 as a RuntimeHostConfigurationOption, the same setting as mxaccessgw 659bb831. It is present in the published runtimeconfig.json, which the Docker image copies. A Host test pins the value. To override or revert on one host without rebuilding, set DOTNET_ThreadPool_UnfairSemaphoreSpinLimit (70 is the runtime default, 0 turns the spin off). This is documented in Component-Host.md under Runtime thread-pool settings. A synthetic local benchmark (macOS, about 185 events/s) showed roughly half the involuntary context switches and CPU at 10 compared with 70. That is directional only. The vd03 WPR before/after measurement, which would confirm the cause here, is still to be done at the next vd03 deploy.

Applied in b47002b4 (main @ d4d5be3b). The Host csproj now ships `System.Threading.ThreadPool.UnfairSemaphoreSpinLimit=10` as a RuntimeHostConfigurationOption, the same setting as mxaccessgw 659bb831. It is present in the published runtimeconfig.json, which the Docker image copies. A Host test pins the value. To override or revert on one host without rebuilding, set `DOTNET_ThreadPool_UnfairSemaphoreSpinLimit` (70 is the runtime default, 0 turns the spin off). This is documented in Component-Host.md under *Runtime thread-pool settings*. A synthetic local benchmark (macOS, about 185 events/s) showed roughly half the involuntary context switches and CPU at 10 compared with 70. That is directional only. The vd03 WPR before/after measurement, which would confirm the cause here, is still to be done at the next vd03 deploy.
Sign in to join this conversation.