This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
# Rollout Plan: Worker and Gateway Event-Path CPU Fixes (2026-11-21)
|
||||
|
||||
Tracking: #236 (deploy gate), #235 (gateway relay hops), #237 / ScadaBridge#146 (ScadaBridge spin limit).
|
||||
Analysis: the 2026-11-21 investigation notes (`perf.md`, kept outside the docs set); the key numbers are repeated here.
|
||||
|
||||
## Why
|
||||
|
||||
On wonder-app-vd03 one worker used about 44% of one core (15.7 user + 28.8 kernel), which is about 11% of the
|
||||
4-core box, while carrying ~240 data changes/s. A WPR trace attributed 72% of that to `lmxproxy.dll` resolving the
|
||||
`MXSTATUS_PROXY` record type through the registry on every event (made worse by WOW64 and CrowdStrike's registry
|
||||
callbacks) and 26% to .NET Framework thread-pool spin after each per-event work item. The gateway on the same box
|
||||
spent most of its context switches in .NET 10 thread-pool spin yields.
|
||||
|
||||
MXAccess offers no event path without the `MXSTATUS_PROXY` array: all four events on both source interfaces carry
|
||||
it. So the fix has to make the per-event lookup cheap, not avoid it.
|
||||
|
||||
## What Ships
|
||||
|
||||
The work ships in two releases, so each change's effect on vd03 can be measured separately and the riskier change
|
||||
waits until the first has soaked.
|
||||
|
||||
| Release | Content | Risk |
|
||||
|---|---|---|
|
||||
| **R1** (`feat/worker-perf-prototype`: `659bb831`, `30ac3f32`) | Record-info pin, dedicated event-drain thread with a synchronous pipe flush, gateway `UnfairSemaphoreSpinLimit=10`, pin outcome carried in `WorkerReady.record_info_pin_status` (logged by the gateway, shown on the dashboard session page), drain-thread completion tests | Low. The pin is a cache warm-up that cannot fail a session. The drain thread keeps the same loop body, ordering and fault reporting. The spin limit is a runtime tuning knob |
|
||||
| **R2** (`feat/gateway-relay-hops`, three commits stacked on R1) | #235: inline worker event hand-off (no staging hop), dashboard mirror attached only while viewed, alarm-monitor filter, 64 KiB read-ahead pipe reader. gRPC `BufferHint` was skipped: it would rarely apply at ~4 ms event spacing, and doing it safely needs manual flushes | Medium. It changes the event relay path the gateway's ordering, backpressure and fan-out guarantees run through |
|
||||
|
||||
Both releases build the Server and the Worker from one SHA (runbook trap 5). R1 adds field 5 to `WorkerReady` in
|
||||
`mxaccess_worker.proto`. The change is additive with no protocol version bump (an older gateway ignores it, and an
|
||||
older worker sends it empty), but the Server and Worker still deploy together. R2 changes no contract.
|
||||
|
||||
## Measured Expectations (windev, ~242 events/s, no EDR)
|
||||
|
||||
| | Before | After R1 |
|
||||
|---|---|---|
|
||||
| Worker CPU (% of one core) | 67.0 | 6.2 |
|
||||
| Bench gateway CPU (% of one core) | 8.1 | 6.9 (R1); 7.26 → 5.99 for R2 over R1 in a later run, dashboard off |
|
||||
|
||||
vd03 should gain more than windev did, because CrowdStrike adds cost to every lookup the pin removes and the box is
|
||||
oversubscribed (every spin yield there is a real context switch). That is an inference, and R1's vd03 measurement
|
||||
confirms or refutes it.
|
||||
|
||||
## Rings
|
||||
|
||||
Each ring uses `docs/runbooks/DeployUpgradeNssmService.md` and `scripts/deploy/Upgrade-MxGatewayService.ps1`:
|
||||
build on windev, push over SMB, `-DryRun`, real run, then section 7 verification. Before the first ring, check
|
||||
whether the repo script has picked up the `nssm start` `SERVICE_START_PENDING` patch used on 2026-11-19. If it has
|
||||
not, apply the same local patch, or fix the repo script first. One box at a time. Every ring needs the owner's
|
||||
deploy approval, because WinRM on the wonder boxes is deploy-only.
|
||||
|
||||
### Ring 0: windev (`MxAccessGw` service, dev rig)
|
||||
|
||||
1. Deploy R1 by the windev convention: a dated `Server-YYYYMMDD` dir and an NSSM repoint, with the Worker swapped in place.
|
||||
2. Check that the gateway reports the pin as `pinned {77e896ec-…} v3.2 record {a162d9e4-…}` for every new session.
|
||||
3. Run `perfload` against the service (120 items, ~242 events/s) for 30 minutes. Pass if no worker fault,
|
||||
no `EventBacklogExceeded`, no sequence gaps at the client, and worker CPU within 2 points of the bench's 6.2%.
|
||||
4. Run the client end-to-end matrix (`scripts/run-client-e2e-tests.ps1`) once.
|
||||
|
||||
### Ring 1: DEV wonder-app-vd03 (the box with the symptom)
|
||||
|
||||
1. Record the baseline the morning of the deploy: event rate on the hot session (dashboard session view) and the
|
||||
gateway's own metrics. The 2026-11-21 counter capture in `perf.md` is the CPU baseline.
|
||||
2. Deploy R1: Server and Worker (`MxGateway.Worker.exe` apphost name), `-ExpectedSha`, label `perf-r1`.
|
||||
3. Do runbook section 7, including the 7.3 API-key session read. Check the pin status for both live sessions.
|
||||
If it reports a failure (for example a registry or permissions difference on the box), R1 still runs
|
||||
correctly but does not deliver the CPU saving: keep it deployed, record the HRESULT, and investigate.
|
||||
4. **Measure.** This needs an owner-approved, one-off counter capture: the same single WinRM `typeperf` call as the
|
||||
baseline (30 × 1 s, `MxGateway.Worker` and `MxGateway.Server` process and thread counters), with no WPR.
|
||||
Without that approval, ask someone on the box to read Task Manager's CPU column for `MxGateway.Worker.exe` and
|
||||
`MxGateway.Server.exe` over a minute.
|
||||
- **Pass:** hot worker ≤ 10% of one core at a comparable event rate (baseline 44.5%); gateway CPU and context
|
||||
switches down; no session faults over 24 h; OtOpcUa and ScadaBridge consumers reconnected and receiving data.
|
||||
- **If the worker is still above 10% and `csagent` cost is suspected:** raise the CrowdStrike exclusion request
|
||||
for `MxGateway.Worker.exe` with Security (`perf.md`, Suggested Order step 5) instead of more code changes.
|
||||
5. Soak for 48 h before QA. Then deploy R2 to vd03 and repeat steps 3–4, comparing gateway CPU against R1.
|
||||
|
||||
### Ring 2: QA wonder-app-vq03 / vq04
|
||||
|
||||
After vd03 passes R1, deploy R1 to vq03, verify, then vq04. Same checks as Ring 1 steps 3 and 4, but the CPU
|
||||
reading is optional when vd03 already proved it. R2 follows after its vd03 soak.
|
||||
|
||||
### Ring 3: PROD wonder-app-vp03 / vp04
|
||||
|
||||
Deploy after QA has soaked for a week, in a change window, with the downstream owners (OtOpcUa, ScadaBridge)
|
||||
told that sessions will drop and reconnect (a gateway restart never reattaches workers). The site PAR boxes stay
|
||||
held until their platform is deployed, as before. They take whatever release is current when they are installed.
|
||||
|
||||
## Rollback
|
||||
|
||||
- **Whole release:** runbook section 8, or `Upgrade-MxGatewayService.ps1 -Rollback -BackupStamp <stamp>`. No store
|
||||
migration is involved, so `-RestoreStores` is not needed.
|
||||
- **Spin limit only:** edit `configProperties` in `MxGateway.Server.runtimeconfig.json` in the Server dir and
|
||||
restart the service. Verify on windev before relying on the `DOTNET_ThreadPool_UnfairSemaphoreSpinLimit` env var
|
||||
instead: the runtime reads the runtimeconfig value first, so the env var may not override it.
|
||||
- **Pin only:** there is no separate switch, because a pin failure already degrades to the old behavior. If the
|
||||
pin itself were suspected, roll back the Worker together with the Server (same SHA).
|
||||
|
||||
## Risks
|
||||
|
||||
| Risk | Mitigation |
|
||||
|---|---|
|
||||
| Drain-thread shutdown or fault path behaves differently from the async loop | Completion-path tests (cancel, fault) in R1; Ring 0 soak; runbook stop/STOP_PENDING handling is unchanged |
|
||||
| Pin fails on a box with a different MXAccess registration | Non-fatal by design and reported to the gateway; LmxProxy is `6000.0045.2657.1` on every wonder box checked |
|
||||
| EDR reacts to the new `LoadRegTypeLib` call at worker start | One call per process, not per event; watch the first vd03 start |
|
||||
| R2 changes event ordering or backpressure | Separate release, after R1 soaks; fake-worker ordering/replay/fan-out tests; vd03 first |
|
||||
| Downstream consumers do not reconnect after the restart | Runbook section 7 step 7 on every box |
|
||||
|
||||
## Done When
|
||||
|
||||
- R1 and R2 are on vd03, vq03/vq04 and vp03/vp04, each with a deploy note under `docs/deploy/`.
|
||||
- The vd03 before/after numbers are recorded in that deploy note, and #236 and #235 are closed.
|
||||
- ScadaBridge#146 has an owner in the ScadaBridge repo.
|
||||
Reference in New Issue
Block a user