perf(opcua): #870 ring-buffer event monitored-item queue
Since #855 condition events are queued to folder event items under the node manager Lock. At a full DiscardOldest queue the SDK's EventQueueHandler dequeues the head of EventMonitoredItemQueue, a List.RemoveAt(0) shift of the whole queue (~1 us/item at QueueSize 1000, ~10 us at 10000). OtOpcUaSdkServer.CreateMonitoredItemQueueFactory now wraps the SDK factory in RingEventQueueFactory: event queues are RingEventMonitoredItemQueue (O(1) discard), data-change queues, durable requests and disposal go to the SDK factory unchanged. A factory set through StandardServer.MonitoredItemQueueFactory is used as-is. The SDK queue is storage only (decompiled 2.0.1): DiscardOldest, overflow-event positions and discarded/overflow counters live in EventQueueHandler, which is unchanged. The ring reproduces QueueSize 0 initial + BadInternalError enqueue, drop-oldest at Count == QueueSize, FIFO dequeue, SetQueueSize keep-newest / keep-oldest, the newest-1000 duplicate window via IsEventRaisedFor, no-op Dispose. RingEventMonitoredItemQueueParityTests drive both queues, and the SDK EventQueueHandler over both factories, with the same random sequences. FolderEventDeliveryPerfTests gains Ring_vs_sdk_event_queue (A/B in one process via the internal OtOpcUaSdkServer.RingEventQueues switch). Claude-Session: https://claude.ai/code/session_01GT67AD99zQQqpLCVm3p7xk
This commit is contained in:
+34
-2
@@ -100,8 +100,40 @@ public sealed class FolderEventDeliveryPerfTests
|
||||
public Task Stalled_items_queue_size_sensitivity(uint queueSize) =>
|
||||
RunAsync(50, acl: false, stalled: true, serverObjectProbe: false, queueSize);
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #870 A/B in one process (same machine load): N stalled folder items at a full queue, with the server's
|
||||
/// ring-buffer event queues vs the SDK's own <c>EventMonitoredItemQueue</c> (<c>List.RemoveAt(0)</c> per discard).
|
||||
/// Each round runs both arms, alternating which goes first, so a load spike lands on both.
|
||||
/// <c>OTOPCUA_EVENT_PERF_ROUNDS</c> sets the rounds (default 2).
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(50, 1000u, false)]
|
||||
[InlineData(200, 1000u, false)]
|
||||
[InlineData(200, 1000u, true)]
|
||||
[InlineData(50, 10000u, false)]
|
||||
public async Task Ring_vs_sdk_event_queue(int n, uint queueSize, bool acl)
|
||||
{
|
||||
RequireOptIn();
|
||||
var rounds = int.TryParse(Environment.GetEnvironmentVariable("OTOPCUA_EVENT_PERF_ROUNDS"), out var r) && r > 0 ? r : 2;
|
||||
try
|
||||
{
|
||||
for (var round = 0; round < rounds; round++)
|
||||
{
|
||||
foreach (var ring in round % 2 == 0 ? new[] { false, true } : [true, false])
|
||||
{
|
||||
OtOpcUaSdkServer.RingEventQueues = ring;
|
||||
await RunAsync(n, acl, stalled: true, serverObjectProbe: false, queueSize, ring ? "ring" : "sdk ");
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
OtOpcUaSdkServer.RingEventQueues = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task RunAsync(
|
||||
int n, bool acl, bool stalled, bool serverObjectProbe, uint queueSize = DefaultQueueSize)
|
||||
int n, bool acl, bool stalled, bool serverObjectProbe, uint queueSize = DefaultQueueSize, string? queueKind = null)
|
||||
{
|
||||
RequireOptIn();
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
@@ -195,7 +227,7 @@ public sealed class FolderEventDeliveryPerfTests
|
||||
var deferredPeak = rig.Nm.DeferredEventReports;
|
||||
var row = new StringBuilder();
|
||||
row.Append(CultureInfo.InvariantCulture,
|
||||
$"{(serverObjectProbe ? "i=2253" : "folder"),-6} N={n,-3} acl={(acl ? "on " : "off")} {(stalled ? "stalled " : "publishing")} q={queueSize,-5} | ");
|
||||
$"{(serverObjectProbe ? "i=2253" : "folder"),-6} N={n,-3} acl={(acl ? "on " : "off")} {(stalled ? "stalled " : "publishing")} q={queueSize,-5} {(queueKind is null ? "" : queueKind + " ")}| ");
|
||||
row.Append(CultureInfo.InvariantCulture, $"lock hold us p50 {Pct(holds, 50),8:F1} p90 {Pct(holds, 90),8:F1} p99 {Pct(holds, 99),8:F1} max {holds.Max(),9:F1} mean {holds.Average(),8:F1}");
|
||||
row.Append(CultureInfo.InvariantCulture, $" | per-item mean {(n > 0 ? holds.Average() / n : 0),6:F2} us");
|
||||
if (expectFolder)
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
using Opc.Ua.Server;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #870: the running server's monitored-item queue factory is <see cref="RingEventQueueFactory"/> (every event
|
||||
/// item's queue is a <see cref="RingEventMonitoredItemQueue"/>; the SDK's <see cref="EventQueueHandler"/> always asks
|
||||
/// the server's factory), and data-change queues are still the SDK's own.
|
||||
/// </summary>
|
||||
public sealed class RingEventQueueWiringTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task The_server_creates_ring_event_queues_and_sdk_data_change_queues()
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
await using var rig = await ServerEventRig.StartAsync("RingQueue870", encrypted: false, ct);
|
||||
|
||||
var factory = rig.Server.CurrentInstance.MonitoredItemQueueFactory.ShouldBeOfType<RingEventQueueFactory>();
|
||||
factory.SupportsDurableQueues.ShouldBeFalse();
|
||||
factory.CreateEventQueue(false, 1).ShouldBeOfType<RingEventMonitoredItemQueue>();
|
||||
factory.CreateDataChangeQueue(false, 2).ShouldBeOfType<DataChangeMonitoredItemQueue>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user