Skip to content

Commit

Permalink
Update server settings (#312)
Browse files Browse the repository at this point in the history
* Improve names

* Improve settings

* Update nuget

* Update version
  • Loading branch information
luiscantero authored Nov 16, 2023
1 parent 0e6e858 commit a81bef3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
38 changes: 26 additions & 12 deletions src/OpcApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static string Hostname
public static string ServerPath { get; set; } = string.Empty;
public static int MaxSessionCount { get; set; } = 100;
public static int MaxSubscriptionCount { get; set; } = 100;
public static int MaxQueuedRequestCount { get; set; } = 2000;
public static int MaxQueuedRequestCount { get; set; } = 2_000;

/// <summary>
/// Default endpoint security of the application.
Expand All @@ -46,7 +46,7 @@ public static string Hostname
public static bool EnableUnsecureTransport { get; set; } = false;

/// <summary>
/// Sets the LDS registration interval.
/// Sets the LDS registration interval in milliseconds.
/// </summary>
public static int LdsRegistrationInterval { get; set; } = 0;

Expand Down Expand Up @@ -85,8 +85,8 @@ public async Task<ApplicationConfiguration> ConfigureAsync()
var transportQuotas = new TransportQuotas
{
MaxStringLength = OpcMaxStringLength,
MaxMessageSize = 4 * 1024 * 1024,
MaxByteStringLength = 4 * 1024 * 1024,
MaxMessageSize = 4 * 1024 * 1024, // 4 kB.
MaxByteStringLength = 4 * 1024 * 1024, // 4 kB.
};

var alternateBaseAddresses = from dnsName in DnsNames
Expand Down Expand Up @@ -130,20 +130,21 @@ public async Task<ApplicationConfiguration> ConfigureAsync()
// Support larger number of nodes.
var securityBuilder = serverBuilder
.SetMaxMessageQueueSize(MAX_MESSAGE_QUEUE_SIZE)
.SetMaxNotificationQueueSize(MAX_NOTIFICATION_QUEUE_SIZE)
.SetMaxNotificationsPerPublish(MAX_NOTIFICATIONS_PER_PUBLISH)
.SetMaxPublishRequestCount(MAX_PUBLISH_REQUEST_COUNT)
.SetMaxRequestThreadCount(MAX_REQUEST_THREAD_COUNT)
// LDS registration interval
// LDS registration interval.
.SetMaxRegistrationInterval(LdsRegistrationInterval)
// enable auditing events and diagnostics
// Enable auditing events and diagnostics.
.SetDiagnosticsEnabled(true)
.SetAuditingEnabled(true)
// set the server capabilities
// Set the server capabilities.
.SetMaxSessionCount(MaxSessionCount)
.SetMaxSubscriptionCount(MaxSubscriptionCount)
.SetMaxQueuedRequestCount(MaxQueuedRequestCount);

// security configuration
// Security configuration.
ApplicationConfiguration = await InitApplicationSecurityAsync(securityBuilder).ConfigureAwait(false);

foreach (var policy in ApplicationConfiguration.ServerConfiguration.SecurityPolicies)
Expand Down Expand Up @@ -240,10 +241,23 @@ private static void ConfigureUserTokenPolicies(IApplicationConfigurationBuilderS
}
}

private const int MAX_MESSAGE_QUEUE_SIZE = 200000;
private const int MAX_NOTIFICATIONS_PER_PUBLISH = 200000;
private const int MAX_PUBLISH_REQUEST_COUNT = 200;
private const int MAX_REQUEST_THREAD_COUNT = MAX_PUBLISH_REQUEST_COUNT;
// Number of publish responses that can be cached per subscription for republish.
// If this value is too high and if the publish responses are not acknowledged,
// the server may run out of memory for large number of subscriptions.
private const int MAX_MESSAGE_QUEUE_SIZE = 20;

// Max. queue size for monitored items.
private const int MAX_NOTIFICATION_QUEUE_SIZE = 1_000;

// Max. number of notifications per publish response. Limit on server side.
private const int MAX_NOTIFICATIONS_PER_PUBLISH = 2_000;

// Max. number of publish requests per session that can be queued for processing.
private const int MAX_PUBLISH_REQUEST_COUNT = 20;

// Max. number of threads that can be used for processing service requests.
// The value should be higher than MAX_PUBLISH_REQUEST_COUNT to avoid a deadlock.
private const int MAX_REQUEST_THREAD_COUNT = 200;

private static string _hostname = Utils.GetHostName().ToLowerInvariant();
}
12 changes: 6 additions & 6 deletions src/PlcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ protected override void OnServerStopping()
ServerInternal.Status.Variable.State.Value = ServerState.Shutdown;
ServerInternal.Status.Variable.ClearChangeMasks(ServerInternal.DefaultSystemContext, true);

for (uint timeTillShutdown = _plcShutdownWaitPeriod; timeTillShutdown > 0; timeTillShutdown--)
for (uint secondsUntilShutdown = _plcShutdownWaitSeconds; secondsUntilShutdown > 0; secondsUntilShutdown--)
{
ServerInternal.Status.Value.SecondsTillShutdown = timeTillShutdown;
ServerInternal.Status.Variable.SecondsTillShutdown.Value = timeTillShutdown;
ServerInternal.Status.Variable.ClearChangeMasks(ServerInternal.DefaultSystemContext, true);
ServerInternal.Status.Value.SecondsTillShutdown = secondsUntilShutdown;
ServerInternal.Status.Variable.SecondsTillShutdown.Value = secondsUntilShutdown;
ServerInternal.Status.Variable.ClearChangeMasks(ServerInternal.DefaultSystemContext, includeChildren: true);

Thread.Sleep(1000);
Thread.Sleep(TimeSpan.FromSeconds(1));
}
}
}
Expand All @@ -209,5 +209,5 @@ protected override void OnServerStopping()
base.OnServerStopping();
}

private const uint _plcShutdownWaitPeriod = 10;
private const uint _plcShutdownWaitSeconds = 10;
}
2 changes: 1 addition & 1 deletion src/opc-plc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.9.11",
"version": "2.9.12",
"versionHeightOffset": -1,
"publicReleaseRefSpec": [
"^refs/heads/main$",
Expand Down

0 comments on commit a81bef3

Please sign in to comment.