docs(grpc-data): re-measure per-condition memory with GC memory info (#929)

The X0 node-only harness used a GC.GetTotalMemory(true) delta, which on .NET 10
counts committed-but-free GC regions. Switched it to the L2 Measure() method
(full blocking GC, HeapSizeBytes - FragmentedBytes, settled working set):
79,085 B heap / ~90 KB WS per OffNormal condition (GetTotalMemory still reads
158,169 B, reproducing the old 160,997). Plan 5.5, X0/A3/A4-docs evidence and the
BytesPerCondition comment corrected; the default (160,000 B from the L2
in-server worst case) is unchanged.
This commit is contained in:
Joseph Doherty
2026-11-28 09:13:48 -05:00
parent 05f431f5d8
commit cb672ea060
6 changed files with 58 additions and 23 deletions
+5 -2
View File
@@ -300,6 +300,8 @@ regions at baseline). Per the plan, `MaxImportedConditionBytes` is now set from
**205,665** (the managed-heap figure, the larger of the two) and the default `DataConnections:MaxImportedConditionBytes` =
205,665 × 2,500 = **514,162,500 B (≈ 490 MiB)** (was 400 MiB). `MaxConditions` (1,000 per mapping) needs no lowering.
Nearly all of it is the SDK condition node + children (X0's node-only figure was 160,997); the A3b EventId registry adds ~1 KB.
(Superseded: these figures and X0's were `GC.GetTotalMemory` deltas — see round 2's L2 below and #929, which re-measured the
node-only retained heap at 79,085 B.)
## Live — run `a3b-cond-3` (build `82ecc116`, clean tree) — PASS
@@ -658,7 +660,7 @@ Worst case (2 placements per condition, all 8 EventId slots filled, 3 event item
**L2: PASS** (both ≤ 200 MiB in every run). `BytesPerCondition` = the larger of the two per-condition figures, max of three runs,
rounded up: 158,629 → **160,000** (was 230,000); `MaxImportedConditionBytes` default = 160,000 × 2,500 = **400,000,000 B
(≈ 381 MiB)** (was ≈ 548 MiB). The X0 node-only figure (160,997) and A3b's 197.4 MiB were taken with `GetTotalMemory` too and are
likely inflated the same way (not re-measured here).
likely inflated the same way (not re-measured here; #929 re-measured X0: 79,085 B node-only heap, X0 evidence).
## Gates (round 2, at `b884db5f`)
@@ -693,7 +695,8 @@ Active/Acknowledged; `passed: true`. Teardown: no run-labelled containers or net
- File: the `GrpcDataConditionStreamTests.Overflow_before_the_snapshot_is_drained_resets_the_stream` load sensitivity (above).
- The plan's L2 / X0 figures (≈ 157–161 KiB per condition node, §5.5 table) came from `GC.GetTotalMemory` and are likely
inflated by the same region accounting; the plan's §5.5 table was not edited (evidence only).
inflated by the same region accounting; the plan's §5.5 table was not edited (evidence only). Done in #929: the X0 harness
now uses the L2 method (79,085 B node-only heap vs 158,169 B by `GetTotalMemory`), and §5.5 cites L2's 160,000 B.
# A3 — Verification review round 2
+1 -1
View File
@@ -32,7 +32,7 @@ The sources were the code at `91438049` and the evidence logs X0–A3. The plan
| # | Plan says | Code does (evidence) |
|---|---|---|
| D1 | §5.6 step 2(c): one per-node semaphore (default 8) bounds remote method calls. | 8 per node **and** 4 per connection inside them. A dispatch with < 250 ms of budget left is `BadTimeout`, unsent (`ImportedConditionMethods.cs:63-79`, `:247`, `:270`; A3b review S4). |
| D2 | §5.5 / §6: `MaxImportedConditionBytes` 400 MiB, ≈ 157 KiB (160,997 B) per condition. | `BytesPerCondition` = 160,000. The default is 400,000,000 B ≈ 381 MiB (`ProjectedConditionAccess.cs:58-61`, `DataConnectionOptions.cs:25`; A3 round-2 L2 measured the retained heap, not `GC.GetTotalMemory`). #929 re-measures the plan's figures. |
| D2 | §5.5 / §6: `MaxImportedConditionBytes` 400 MiB, ≈ 157 KiB (160,997 B) per condition. | `BytesPerCondition` = 160,000. The default is 400,000,000 B ≈ 381 MiB (`ProjectedConditionAccess.cs:58-61`, `DataConnectionOptions.cs:25`; A3 round-2 L2 measured the retained heap, not `GC.GetTotalMemory`). #929 re-measured the plan's figures: node-only 79,085 B heap (X0 harness, now on the L2 method); §5.5 corrected, default unchanged. |
| D3 | §6 metrics list `…conditions.refresh_required`. | Not present (`OtOpcUaTelemetry.cs:233-265` has `unsignalled`, `partition_overflows`, `items`, `resyncs`, `capacity_rejections`, `condition_methods`, `marks_discarded`). A4 diagnostics work; TODO 2. |
| D4 | §5.4/§5.5: demand per connection the caller could see. | Demand is node-wide: the first admitted event item opens every condition-bearing connection, and the per-event gate still decides visibility (A3a deviation 2). |
| D5 | §6: local visibility uses "the Subscribe grant on the `RemoteNamespaceMapping` scope". | `Subscribe` on the **placement folder's** scope, within a current mapping of the placement's realm that grants `AlarmSubscribe`, not `AlarmRead` (`ProjectedConditionAccess.cs:170-190`; A3 Runtime gate tests). Narrower than the mapping scope, and consistent with it. |
+10 -2
View File
@@ -51,8 +51,16 @@ optional children NM adds before `Create()`: `ConfirmedState`, `Confirm`, `Shelv
`Quality`, `BranchId` and `Comment` are present.
Retained size is ≈ 157 KiB per condition (160,997 B). It was measured on 2,000 `OffNormal` instances as a
`GC.GetTotalMemory(true)` delta.
Retained size is ≈ 77 KiB per condition: **79,085 B** managed heap, ≈ 90 KB settled working set (re-measured 2026-11-28 for
#929, three runs: heap 79,085 / 79,085 / 79,085 B, working set 90,284 / 90,144 / 90,038 B). It is measured on 2,000
`OffNormal` instances as the change in `HeapSizeBytes − FragmentedBytes` of the last full blocking GC (after forced
compacting collections), with the working set sampled until it settles — the same `Measure()` as the L2 harness.
- **Correction (#929).** X0 originally reported ≈ 157 KiB (160,997 B), a `GC.GetTotalMemory(true)` delta. On .NET 10 (GC
regions) that call also counts committed-but-free region space (A3 round 2 showed +92 vs +218 MiB for the same state); the
harness still logs it for comparison and it reads 158,169 B, i.e. ≈ 2× the retained heap.
- `BytesPerCondition` (160,000 B) is unaffected: it comes from the L2 in-server worst case (111,715 B heap / 158,629 B
working set, A3 round 2), which already used this method. Node-only ≈ 77 KiB of L2's ≈ 109 KiB heap is the SDK node tree.
- It excludes NM's indexes, the `c1.` identifier strings, the EventId registry and placement sets (m-T7).
- L2 (A3 exit) is the authority for `MaxImportedConditionBytes`.
@@ -18,18 +18,33 @@ static class P {
int total = Count(ctx, alarm, kinds);
Console.WriteLine($"{name}: total={total} ({string.Join(", ", kinds.Select(k => k.Key + "=" + k.Value))}); Quality={(alarm.Quality!=null)} BranchId={(alarm.BranchId!=null)} Comment={(alarm.Comment!=null)}");
}
// #929: GC.GetTotalMemory counts committed-but-free regions on .NET 10. Use the last full blocking GC's
// HeapSizeBytes - FragmentedBytes plus a settled working set: the same method as the L2 harness's Measure()
// (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests/ImportedConditionMemoryMeasurementTests.cs).
static (long Heap, long WorkingSet) Measure() {
for (int i = 0; i < 3; i++) { GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true); GC.WaitForPendingFinalizers(); }
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
var info = GC.GetGCMemoryInfo(GCKind.FullBlocking);
using var p = System.Diagnostics.Process.GetCurrentProcess(); p.Refresh(); long ws = p.WorkingSet64;
var settle = System.Diagnostics.Stopwatch.StartNew();
while (settle.Elapsed < TimeSpan.FromSeconds(10)) {
Thread.Sleep(500); p.Refresh(); long next = p.WorkingSet64; bool stable = Math.Abs(next - ws) < 1024 * 1024; ws = next; if (stable) break; }
return (info.HeapSizeBytes - info.FragmentedBytes, ws);
}
static void Main() {
var ctx = new SystemContext((ITelemetryContext)null) { NodeIdFactory = new Ids(), NamespaceUris = new NamespaceTable() };
ctx.NamespaceUris.Append("urn:a"); ctx.NamespaceUris.Append("urn:b");
Run("AlarmConditionState", p => new AlarmConditionState(p), ctx);
Run("OffNormalAlarmState", p => new OffNormalAlarmState(p), ctx);
Run("DiscreteAlarmState", p => new DiscreteAlarmState(p), ctx);
var keep = new List<object>(); long before = GC.GetTotalMemory(true);
var keep = new List<object>(); var (heap0, ws0) = Measure(); long before = GC.GetTotalMemory(true);
for (int i = 0; i < 2000; i++) { var parent = new FolderState(null); var a = new OffNormalAlarmState(parent);
a.ConfirmedState = new TwoStateVariableState(a); a.Confirm = new AddCommentMethodState(a); a.ShelvingState = new ShelvedStateMachineState(a);
a.MaxTimeShelved = new PropertyState<double>.Implementation<VariantBuilder>(a);
a.Create(ctx, new NodeId("c"+i, 2), new QualifiedName("c"+i, 2), new LocalizedText("c"+i), true); keep.Add(a); }
long after = GC.GetTotalMemory(true); Console.WriteLine($"retained bytes/condition (2000, OffNormal, no address-space indexes): {(after-before)/2000}"); GC.KeepAlive(keep);
var (heap1, ws1) = Measure(); long after = GC.GetTotalMemory(true);
Console.WriteLine($"retained bytes/condition (2000, OffNormal, no address-space indexes): heap {(heap1-heap0)/2000} (GCMemoryInfo), " +
$"working set {(ws1-ws0)/2000} (settled); GC.GetTotalMemory delta {(after-before)/2000} (not used, #929)"); GC.KeepAlive(keep);
var conds = keep.Cast<OffNormalAlarmState>().ToArray(); var recs = new object[conds.Length];
for (int w = 0; w < 3; w++) { var sw = System.Diagnostics.Stopwatch.StartNew();
for (int i = 0; i < conds.Length; i++) { var c = conds[i]; recs[i] = (c.NodeId, c.ActiveState?.Id?.Value, c.AckedState?.Id?.Value, c.ConfirmedState?.Id?.Value,