fix(grpc-data): size projected unary reservations from the node's shape (#960); per-item status for projected items refused at create (#961)
#960: a projected read reserves 16 KiB for a fixed-size scalar (16 KiB + 256 B/element for a fixed-length fixed-size array) instead of the whole MaxPendingBytes, so the default 1 MiB admits 64 concurrent scalar reads; String/Bytes/variable arrays keep the whole cap, and a waiting whole-cap read holds back smaller ones for 100 ms (anti-starvation). Writes reserve 16 KiB + identifiers + 3 x the value bound (what the origin's DataWriteExecutor admits the batch against). Monitored-item renewals reserve 256 KiB. Measured: 4 x 250 ms maxAge=0 reads 1016 ms / 1 in flight -> 285 ms / 4 in flight. #961: TryAcquireProjectedItem reports BadResourceUnavailable for a stream-capacity refusal; the node manager's CreateMonitoredItem override turns the item manager's ServiceResultException into that item's status (was a whole-request fault), and an authority race is re-classified outside Lock like the per-item probe.
This commit is contained in:
@@ -262,7 +262,7 @@ consumer scope, exports, mappings, credential provisioning and recovery.
|
||||
| `MaxMessageBytes` / `MaxConcurrentCalls` | `1048576` / `64` | Message-size and concurrent unary-call admission. |
|
||||
| `MaxStreams` / `MaxStreamsPerPrincipal` | `256` / `8` | Global and per-principal stream bounds. |
|
||||
| `MaxMonitoredItems` | `10000` | Listener monitored-item bound. |
|
||||
| `MaxTransportBytes` / `MaxPendingBytes` | `67108864` / `1048576` | Retained transport and pending-work byte bounds. |
|
||||
| `MaxTransportBytes` / `MaxPendingBytes` | `67108864` / `1048576` | Retained transport and pending-work byte bounds. `MaxPendingBytes` is also the consumer's projected unary budget: since #960 a projected Read reserves 16 KiB for a fixed-size scalar (64 fit the default), a String / Bytes / variable-array read the whole `min(4 MiB, MaxPendingBytes)` — raise it for concurrent reads of those. |
|
||||
| `MaxSessionLifetime` | `01:00:00` | Finite stream-session lifetime. |
|
||||
| `UnaryTimeout` / `StreamCommandTimeout` | `00:00:30` / `00:00:05` | Finite ingress unary and stream-command deadlines. |
|
||||
| `CredentialBundlePath` / `TrustBundlePath` | unset | Independent node-local credential and trust provisioning mounts. |
|
||||
|
||||
@@ -101,7 +101,7 @@ a write also needs this node's local write role). A caller without the grant is
|
||||
`GetMetadata` renewal as above, for the operation it is performing (its Read / HistoryRead / Write /
|
||||
Subscribe bit), one per node and operation at a time, with a 250 ms back-off after a failure. On-demand
|
||||
renewals never touch the unary budget (cold reads, writes) or the browse/subscription-renewal fetch
|
||||
slots: they queue (at most 64) for their own pool of `max(1, maxConcurrentFetches / 2)` origin calls,
|
||||
slots (an existing monitored item's renewal reserves 256 KiB of the unary budget since #960, not all of it): they queue (at most 64) for their own pool of `max(1, maxConcurrentFetches / 2)` origin calls,
|
||||
reserve 256 KiB each, and have 3 s end to end, so a batch of N lapsed nodes renews all N:
|
||||
|
||||
- **Value Read** awaits the renewal within the request (#938; the async Read, no `Lock`, at most
|
||||
@@ -116,7 +116,12 @@ reserve 256 KiB each, and have 3 s end to end, so a batch of N lapsed nodes rene
|
||||
most 4 s, async, no `Lock`) and then creates them. An item still not acquirable is answered PER
|
||||
ITEM — `BadResourceUnavailable` for a lapse the caller is granted, `BadUserAccessDenied` for a real
|
||||
refusal. (Before, a refused projected item was thrown from the item manager and faulted the whole
|
||||
CreateMonitoredItems request.)
|
||||
CreateMonitoredItems request.) **Since #961** the remainder refused at the create itself (under the SDK's
|
||||
`Lock`, after that per-item check) is per item too: the authority changing in between is re-classified
|
||||
the same way once the create returns (granted lapse, or admitted again by then ⇒ `BadResourceUnavailable`;
|
||||
real refusal ⇒ `BadUserAccessDenied`), and no origin stream able to take the item (the node's
|
||||
`MaxStreams` streams — one per connection, serving identity and publishing interval — all in use, or a
|
||||
closing one) is `BadResourceUnavailable`. The other items of the request are created normally.
|
||||
- **HistoryRead** renews within the request and is then served. The wait (one per batch, at most 4 s
|
||||
and never past `HistoryReadDeadline`, no node-manager `Lock` held, the request's cancellation
|
||||
honoured) takes one of the non-local history batch slots first. A batch that finds none free does
|
||||
|
||||
@@ -40,9 +40,19 @@ a missing sample or an unsuitable one — is served from a bounded origin read *
|
||||
request**: the node manager's async Read (`IReadAsyncNodeManager`, no node-manager `Lock` held, no
|
||||
request thread blocked) reads the origin, serves what it read and publishes it to the cache. The
|
||||
wait is at most 5 s per request (`OtOpcUaNodeManager.ProjectedOriginReadWait`), less the request
|
||||
deadline's margin; the reads are admitted against the same unary budget as before (the default
|
||||
1 MiB `MaxPendingBytes` admits one 1 MiB read at a time) and a batch is pumped through it as reads
|
||||
complete. A read that is not answered in time, or answers nothing servable (unreachable, not
|
||||
deadline's margin; the reads are admitted against the same unary budget as before and a batch is
|
||||
pumped through it as reads complete. **Since #960** each read reserves only what its node's declared
|
||||
shape can answer — 16 KiB for a fixed-size scalar, 16 KiB + 256 B per element for a fixed-length
|
||||
array of fixed-size elements — so the default 1 MiB `DataConnections:MaxPendingBytes` admits up to
|
||||
`MaxConcurrentCalls` (64) scalar reads at once (measured: four 250 ms origin reads in one `maxAge=0`
|
||||
request, 1016 ms / 1 in flight before, 285 ms / 4 in flight after). A String / Bytes value or a
|
||||
variable-length array has no declared bound and still reserves the whole per-read cap
|
||||
(`min(4 MiB, MaxPendingBytes)`), so such reads run one at a time at the default; a read of that kind
|
||||
that is waiting for capacity holds back smaller reads for 100 ms (re-armed while it waits) so a steady
|
||||
stream of scalar reads cannot starve it. The reservation is also the read's decode limit, so an
|
||||
origin answering more than the node's shape allows is refused rather than exceeding the bound. A
|
||||
projected Write likewise reserves what its value needs (16 KiB + identifiers + 3 × the value's
|
||||
size bound — the budget the origin admits a write batch against), not the whole cap. A read that is not answered in time, or answers nothing servable (unreachable, not
|
||||
ready, older than the mapping's stale timeout), returns `BadWaitingForInitialData` as before; a
|
||||
read never admitted by the deadline is scheduled as before. A lapsed lease is renewed first, in the
|
||||
same request (see [Data connections](DataConnections.md#subscription-freshness-and-exact-item-renewal)).
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
# #960 / #961 — projected unary reservation sizing, per-item create refusals
|
||||
|
||||
2026-12-01. Follow-ups of #938 and #940 (`938-939-940-948.md`). Consumer side of gRPC data connections.
|
||||
|
||||
## #960 — one projected origin read/write in flight per node
|
||||
|
||||
**Root cause.** `ProjectedDataAccess` admitted every projected read (`ScheduleRead` / `ReadNowAsync`) and write by reserving
|
||||
`min(caller cap = 4 MiB, MaxUnaryBytes)` against `MaxUnaryBytes`, which production wires to `DataConnections:MaxPendingBytes`
|
||||
(default **1 MiB**). Every operation reserved the whole budget, so one read or write excluded all others and
|
||||
`MaxConcurrentCalls` (64) never applied. A `maxAge=0` batch of N nodes was N serial origin round trips; a concurrent write was
|
||||
rejected outright (`WriteAsync` does not wait). An existing monitored item's metadata renewal (`RenewOwnedAsync`) also reserved
|
||||
the whole budget, so it needed every other projected operation idle.
|
||||
|
||||
**Fix.** Size each reservation from what the operation can carry, keeping the sum bounded by `MaxPendingBytes`:
|
||||
|
||||
- **Read** — `ReadReservationBytes(originMetadata, cap)`: 16 KiB (`ProjectedEnvelopeBytes`) for a fixed-size scalar (Boolean,
|
||||
integers, Float/Double, Timestamp, Guid, Null); 16 KiB + 256 B/element for a fixed-length array of fixed-size elements; the
|
||||
whole cap for String / Bytes / variable-length or string arrays (no declared bound — unchanged). The reservation is also the
|
||||
read's budget, i.e. the consumer's decode limit and the origin's response limit, so an origin answering more than the node's
|
||||
shape allows is refused rather than exceeding the bound. `GrpcDataProjectedReadReservationTests` pins the constants against
|
||||
the real wire codec (widest value of each bounded shape, 128-char serving identifiers, decoded at exactly the reservation).
|
||||
- **Anti-starvation.** A whole-cap read refused for bytes by a caller that waits (`ReadNowAsync`, the #938 pump) holds back
|
||||
smaller reads for 100 ms (`ReadDrainWindow`, re-armed by each refused retry, cleared when it is admitted), so scalar reads
|
||||
that now share the budget cannot starve it. Fire-and-forget `ScheduleRead` does not arm it; writes neither arm nor honour it.
|
||||
- **Write** — `16 KiB + 2 × identifier chars + 3 × WriteValueBytes(value)` (capped). The `3 ×` term is required: the reservation
|
||||
is the batch budget the ORIGIN admits the write against (`DataWriteExecutor`: `3 × EstimatedRetainedBytes + 512 + 2 ×
|
||||
identifiers`), and `WriteValueBytes` (the former `FitsWriteBudget` bound) is ≥ that estimate for every kind. A first draft
|
||||
without it would have refused strings over ~4 K chars at the origin (`A_large_string_write_reserves_what_the_origin_admits_it_against`).
|
||||
- **Monitored-item renewal** — 256 KiB (`LapseRenewalBytes`, the same metadata call the on-demand lapse renewal makes).
|
||||
|
||||
The default `MaxPendingBytes` is unchanged: 1 MiB now holds 64 scalar reads (= `MaxConcurrentCalls`). Variable-size reads still
|
||||
serialize at the default; raising `MaxPendingBytes` buys concurrency for those (docs/Configuration.md).
|
||||
|
||||
**Measurement** (`A_max_age_zero_batch_of_scalar_nodes_reads_the_origin_concurrently_within_the_default_budget`: real consumer
|
||||
SDK session, 4 projected Int32 nodes, `maxAge=0`, 1 MiB budget, origin reads delayed 250 ms):
|
||||
|
||||
| | elapsed | max origin reads in flight |
|
||||
|---|---|---|
|
||||
| pre-fix | 1016 ms | 1 |
|
||||
| fix | 285 ms | 4 (the harness's operation limit) |
|
||||
|
||||
Not measured on the rig with ScadaBridge-sized batches (no rig run in this change).
|
||||
|
||||
## #961 — a projected item refused inside the item-manager create faulted the whole request
|
||||
|
||||
**Root cause.** `OrdinaryTagItemManager.CreateMonitoredItem` threw `ServiceResultException(BadUserAccessDenied)` when
|
||||
`TryAcquireProjectedItem` failed. SDK 2.0.1 `CustomNodeManager2.CreateMonitoredItems` calls the protected `CreateMonitoredItem`
|
||||
per item under `Lock` with no catch, so the throw became a service fault for every item in the request. Since #940 this was only
|
||||
the remainder after the per-item probe: the authority changing between probe and create, and `StartSubscription` refusing
|
||||
(`MaxStreams` cohorts — one per connection × serving identity × publishing interval — all in use, or a closing cohort).
|
||||
|
||||
**Fix.**
|
||||
|
||||
- `TryAcquireProjectedItem` reports why: `BadResourceUnavailable` when the authority admitted the caller but `StartSubscription`
|
||||
refused (the demand still valid), else `BadUserAccessDenied` (provisional).
|
||||
- `OtOpcUaNodeManager` overrides the protected `CreateMonitoredItem`: a `ServiceResultException` becomes THIS item's status.
|
||||
Nothing leaks — the item manager releases what it reserved before throwing, and the base deletes an item it already created
|
||||
before rethrowing.
|
||||
- After `base.CreateMonitoredItems` (outside `Lock`) every projected item the probe admitted but the create answered
|
||||
`BadUserAccessDenied` is re-classified exactly like the probe (`ProjectedSubscribeRefusal`): granted lapse ⇒
|
||||
`BadResourceUnavailable` (its renewal starts), real refusal ⇒ `BadUserAccessDenied`, admitted again by now ⇒
|
||||
`BadResourceUnavailable` (a transient race; the retry succeeds).
|
||||
|
||||
## Red / green (Runtime.Tests)
|
||||
|
||||
| Test (`Trait Issue`) | pre-fix | fix |
|
||||
|---|---|---|
|
||||
| 960 `Scalar_reads_reserve_their_shape_bound_so_concurrent_reads_share_the_default_budget` | **FAIL** | pass |
|
||||
| 960 `A_waiting_whole_cap_read_holds_back_smaller_reads_until_it_is_admitted` | **FAIL** | pass |
|
||||
| 960 `Scalar_writes_are_dispatched_concurrently_within_the_default_budget` | **FAIL** | pass |
|
||||
| 960 `A_max_age_zero_batch_of_scalar_nodes_reads_the_origin_concurrently_within_the_default_budget` (wire) | **FAIL** (1 in flight) | pass |
|
||||
| 960 `Cold_sdk_read_budget…` / `Sdk_write_budget…` (assert the sized budget now) | **FAIL** | pass |
|
||||
| 960 `Variable_size_read_reserves_the_full_configured_budget_until_physical_completion` (control) | pass | pass |
|
||||
| 960 `A_large_string_write_reserves_what_the_origin_admits_it_against` (guards the 3 × term) | pass | pass |
|
||||
| 960 `GrpcDataProjectedReadReservationTests` (13, codec pins) | n/a (new API) | pass |
|
||||
| 961 `A_projected_item_refused_for_stream_capacity_at_create_fails_only_that_item` (wire) | **FAIL** (request fault `BadUserAccessDenied`) | pass |
|
||||
| 961 `A_projected_item_whose_lease_lapses_between_the_probe_and_the_create_is_retryable_for_that_item_only` (wire) | **FAIL** (request fault) | pass |
|
||||
|
||||
Adjusted for #960 (they encoded "one operation holds the whole budget"): `Cancelled_clamped_write_keeps_capacity…` (30 KiB budget
|
||||
= one scalar write), `Full_write_quota_rejects_large_array…` (the held write is now ~2 MiB so the second does not fit beside it),
|
||||
`A_max_age_zero_batch_larger_than_the_unary_budget_is_pumped…` (budget = one scalar reservation; asserts 1 in flight),
|
||||
`Sdk_mapped_write_uses_default_one_mib_budget_and_is_dispatched_once` (asserts the sized write budget, < 64 KiB and above the
|
||||
origin's scalar accounting, instead of the whole 1 MiB).
|
||||
|
||||
Suites: Runtime.Tests `FullyQualifiedName~DataConnections` 1005/1005 (after the last adjustment), OpcUaServer.Tests 1460 passed,
|
||||
2 skipped, 0 failed.
|
||||
|
||||
Not live-gated (no rig run in this change).
|
||||
Reference in New Issue
Block a user