Skip to content

[Server] Implement smaller Performance improvements found when profiling - #3584

Merged
marcschier merged 6 commits into
masterfrom
romanett/profilingPerf
Feb 28, 2026
Merged

marcschier merged 6 commits into
masterfrom
romanett/profilingPerf

Conversation

@romanett

Copy link
Copy Markdown
Contributor

Proposed changes

-Added GetNamespaceMetadataState(ushort) to ConfigurationNodeManager and interface for efficient lookup by namespace index. Switched to ConcurrentDictionary for thread safety. Updated AsyncCustomNodeManager to use index-based lookup. Cleared index cache in Clear method.

  • Refactor Variant and ServiceResult handling for speed
  • Use WrappedValue assignment for DataValue in MonitoredNode and NodeState to align with updated Variant usage.
  • Return ServiceResult objects instead of raw StatusCodes for bad attribute IDs.
  • Update ServiceResult exception handling: include stack trace only in DEBUG, message only in release.
  • Optimize StatusCode to ServiceResult conversion by returning static Good/Bad instances.
  • Added a ReadLimited LoadTest
  • Optimize MonitoredItem property access needed for publishing
  • Added Tests for MonitoredItem.IsReadyToPublish & Subscription.PublishTimerExpired to ensure existing behaviour

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

Added GetNamespaceMetadataState(ushort) to ConfigurationNodeManager and interface for efficient lookup by namespace index. Switched to ConcurrentDictionary for thread safety. Updated AsyncCustomNodeManager to use index-based lookup. Cleared index cache in Clear method.
- Use WrappedValue assignment for DataValue in MonitoredNode and NodeState to align with updated Variant usage.
- Return ServiceResult objects instead of raw StatusCodes for bad attribute IDs.
- Update ServiceResult exception handling: include stack trace only in DEBUG, message only in release.
- Optimize StatusCode to ServiceResult conversion by returning static Good/Bad instances.
Added SubscriptionTests to verify PublishTimerExpired behavior, including timer expiry, monitored item readiness, keep-alive, and triggering scenarios. Updated Subscription.cs only process triggering if triggered items are configured, improving correctness and efficiency.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces targeted performance optimizations across the server stack (publishing/monitored items, namespace metadata lookup, and ServiceResult/Variant handling) and adds tests/load tests to validate behavior under these changes.

Changes:

  • Add namespace-index-based NamespaceMetadataState lookup and caching, and update node managers to use it.
  • Optimize publishing hot paths (MonitoredItem/Subscription), ServiceResult conversion, and Variant/DataValue handling.
  • Add new unit tests for publishing readiness/triggering and new explicit client load tests (subscribe/read).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
Tests/Opc.Ua.Server.Tests/SubscriptionTests.cs New tests covering Subscription.PublishTimerExpired behavior including triggering paths.
Tests/Opc.Ua.Server.Tests/MonitoredItemIsReadyToPublishTests.cs New tests validating MonitoredItem.IsReadyToPublish across modes and aggregation.
Tests/Opc.Ua.Client.Tests/LoadTest.cs Rename subscribe load test, adjust delay calculation, add explicit read load test.
Tests/Opc.Ua.Client.Tests/ClientTestFramework.cs Adjust server fixture configuration for higher request concurrency.
Stack/Opc.Ua.Types/Utils/ServiceResult.cs Release/Debug AdditionalInfo behavior; optimize StatusCode→ServiceResult conversion for Good/Bad.
Stack/Opc.Ua.Types/State/NodeState.cs Use WrappedValue assignment and return ServiceResult for invalid attribute IDs.
Libraries/Opc.Ua.Server/Subscription/Subscription.cs Micro-optimizations around publishing readiness and triggering checks.
Libraries/Opc.Ua.Server/Subscription/MonitoredItem/MonitoredItem.cs Reduce locking on hot properties; adjust tracing/logging overhead.
Libraries/Opc.Ua.Server/NodeManager/MonitoredItem/MonitoredNode.cs Use WrappedValue initialization on queued DataValues.
Libraries/Opc.Ua.Server/NodeManager/AsyncCustomNodeManager.cs Switch to namespace-index-based metadata lookup.
Libraries/Opc.Ua.Server/Configuration/IConfigurationNodeManager.cs Add GetNamespaceMetadataState(ushort namespaceIndex) to the interface.
Libraries/Opc.Ua.Server/Configuration/ConfigurationNodeManager.cs Implement index-based lookup; switch caches to ConcurrentDictionary and clear index cache on namespace changes.

Comment thread Tests/Opc.Ua.Server.Tests/MonitoredItemIsReadyToPublishTests.cs
Comment thread Libraries/Opc.Ua.Server/Configuration/ConfigurationNodeManager.cs
Comment thread Libraries/Opc.Ua.Server/Configuration/ConfigurationNodeManager.cs
Comment thread Tests/Opc.Ua.Client.Tests/ClientTestFramework.cs Outdated
Comment thread Libraries/Opc.Ua.Server/Subscription/MonitoredItem/MonitoredItem.cs
Comment thread Tests/Opc.Ua.Server.Tests/SubscriptionTests.cs
Comment thread Tests/Opc.Ua.Server.Tests/SubscriptionTests.cs Outdated
Comment thread Tests/Opc.Ua.Server.Tests/SubscriptionTests.cs Outdated
if (!m_readyToPublish)
{
ServerUtils.EventLog.MonitoredItemReady(Id, "FALSE");
//ServerUtils.EventLog.MonitoredItemReady(Id, "FALSE");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Id say Lets just clean this up and remove it all, including the EventLog part in ServerUtils.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants