Skip to content

Commit

Permalink
Port thread scheduler and servicehost from UA .NET legacy. (#1389)
Browse files Browse the repository at this point in the history
* Add minThreadCount and maxThreadCount setting for ThreadPool
* Port thread based scheduler back from UA.NET legacy. 
* The UA Expert perf test shows better response times than Task.Run implementation. 
* Old implementation to compare against is ifdefed,
* Port servicehost from UA.NET legacy
* a few minor backports in serverbase e.g. alias names for hostname
* fix editorconfig, as it caused false positives in ref server

Co-Authored-By: macheronte <79026457+macheronte@users.noreply.github.com>
  • Loading branch information
Nyphus and macheronte committed May 4, 2021
1 parent 323c8c9 commit 244b26e
Show file tree
Hide file tree
Showing 13 changed files with 490 additions and 132 deletions.
22 changes: 19 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ dotnet_style_prefer_conditional_expression_over_assignment =
dotnet_style_prefer_conditional_expression_over_return = true : suggestion

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:silent
csharp_using_directive_placement = outside_namespace : silent

# Naming rules

Expand Down Expand Up @@ -259,8 +259,24 @@ dotnet_naming_symbols.all_members.applicable_kinds =

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Diagnostic settings (windows only)
dotnet_analyzer_diagnostic.category-reliability.severity = suggestion
dotnet_analyzer_diagnostic.category-performance.severity = warning
dotnet_analyzer_diagnostic.category-security.severity = warning

# Suggest only non breaking warnings

# CA1805: Do not initialize unnecessarily.
dotnet_diagnostic.CA1805.severity = suggestion
dotnet_code_quality.CA1805.api_surface = private, internal

# CA1822: Mark members as static.
dotnet_diagnostic.CA1822.severity = suggestion
dotnet_code_quality.CA1822.api_surface = private, internal

# CA3075: Insecure DTD processing in XML
dotnet_diagnostic.CA3075.severity = warning
dotnet_diagnostic.CA3075.severity = warning

# RCS1090: Add call to 'ConfigureAwait' (or vice versa)
dotnet_diagnostic.RCS1090.severity = warning
dotnet_diagnostic.RCS1090.severity = silent

10 changes: 10 additions & 0 deletions Libraries/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Editorconfig for applications

root = false

# Diagnostic settings specific to libraries
[*.cs]

# RCS1090: Add call to 'ConfigureAwait' (or vice versa)
dotnet_diagnostic.RCS1090.severity = warning

18 changes: 14 additions & 4 deletions Libraries/Opc.Ua.Server/Server/StandardServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2665,20 +2665,22 @@ protected override void OnServerStarting(ApplicationConfiguration configuration)
/// Creates the endpoints and creates the hosts.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="bindingFactory">The transport listener binding factory.</param>
/// <param name="serverDescription">The server description.</param>
/// <param name="endpoints">The endpoints.</param>
/// <returns>
/// Returns IList of a host for a UA service.
/// </returns>
protected override IList<Task> InitializeServiceHosts(
protected override IList<ServiceHost> InitializeServiceHosts(
ApplicationConfiguration configuration,
TransportListenerBindings bindingFactory,
out ApplicationDescription serverDescription,
out EndpointDescriptionCollection endpoints)
{
serverDescription = null;
endpoints = null;

Dictionary<string, Task> hosts = new Dictionary<string, Task>();
var hosts = new Dictionary<string, ServiceHost>();

// ensure at least one security policy exists.
if (configuration.ServerConfiguration.SecurityPolicies.Count == 0)
Expand Down Expand Up @@ -2711,7 +2713,7 @@ protected override void OnServerStarting(ApplicationConfiguration configuration)

foreach (var scheme in Utils.DefaultUriSchemes)
{
var binding = TransportBindings.Listeners.GetBinding(scheme);
var binding = bindingFactory.GetBinding(scheme);
if (binding != null)
{
endpointsForHost = binding.CreateServiceHost(
Expand All @@ -2728,7 +2730,15 @@ protected override void OnServerStarting(ApplicationConfiguration configuration)
}
}

return new List<Task>(hosts.Values);
return new List<ServiceHost>(hosts.Values);
}

/// <summary>
/// Creates an instance of the service host.
/// </summary>
public override ServiceHost CreateServiceHost(ServerBase server, params Uri[] addresses)
{
return new ServiceHost(this, typeof(SessionEndpoint), addresses);
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions Stack/Opc.Ua.Bindings.Https/Stack/Https/HttpsServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract class HttpsServiceHost : ITransportListenerFactory
/// </summary>
public List<EndpointDescription> CreateServiceHost(
ServerBase serverBase,
IDictionary<string, Task> hosts,
IDictionary<string, ServiceHost> hosts,
ApplicationConfiguration configuration,
IList<string> baseAddresses,
ApplicationDescription serverDescription,
Expand All @@ -62,12 +62,7 @@ X509Certificate2Collection instanceCertificateChain
)
{
// generate a unique host name.
string hostName = String.Empty;

if (hosts.ContainsKey(hostName))
{
hostName = "/Https";
}
string hostName = hostName = "/Https";

if (hosts.ContainsKey(hostName))
{
Expand Down Expand Up @@ -167,6 +162,11 @@ X509Certificate2Collection instanceCertificateChain
Utils.Trace(Utils.TraceMasks.Error, "Failed to create endpoint {0} because the transport profile is unsupported.", uri);
}
}

// create the host.
ServiceHost serviceHost = serverBase.CreateServiceHost(serverBase, uris.ToArray());

hosts[hostName] = serviceHost;
}

return endpoints;
Expand Down
2 changes: 1 addition & 1 deletion Stack/Opc.Ua.Core/Stack/Bindings/ITransportBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public interface ITransportListenerFactory :
/// <param name="instanceCertificateChain">The cert cahin of the server certificate.</param>
List<EndpointDescription> CreateServiceHost(
ServerBase serverBase,
IDictionary<string, Task> hosts,
IDictionary<string, ServiceHost> hosts,
ApplicationConfiguration configuration,
IList<string> baseAddresses,
ApplicationDescription serverDescription,
Expand Down
78 changes: 39 additions & 39 deletions Stack/Opc.Ua.Core/Stack/Bindings/TransportBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Opc.Ua.Bindings
{
/// <summary>
/// The transpaort bindings available for teh stack.
/// The transport bindings available for the UA applications.
/// </summary>
public static class TransportBindings
{
Expand All @@ -34,55 +34,55 @@ static TransportBindings()
/// The bindings for transport listeners (server).
/// </summary>
public static TransportListenerBindings Listeners { get; private set; }
}

/// <summary>
/// The bindings for the transport channels.
/// </summary>
public class TransportChannelBindings :
TransportBindingsBase<ITransportChannelFactory>
{
/// <summary>
/// The bindings for the transport channels.
/// Initialize the transport listener.
/// </summary>
public class TransportChannelBindings :
TransportBindingsBase<ITransportChannelFactory>
/// <param name="defaultBindings">List of known default bindings.</param>
public TransportChannelBindings(Type[] defaultBindings) : base(defaultBindings)
{
/// <summary>
/// Initialize the transport listener.
/// </summary>
/// <param name="defaultBindings">List of known default bindings.</param>
public TransportChannelBindings(Type[] defaultBindings) : base(defaultBindings)
{
}
}

/// <summary>
/// Get a transport channel for the specified uri scheme.
/// </summary>
/// <param name="uriScheme">The uri scheme of the transport.</param>
public ITransportChannel GetChannel(string uriScheme)
{
var binding = GetBinding(uriScheme);
return binding?.Create();
}
/// <summary>
/// Get a transport channel for the specified uri scheme.
/// </summary>
/// <param name="uriScheme">The uri scheme of the transport.</param>
public ITransportChannel GetChannel(string uriScheme)
{
var binding = GetBinding(uriScheme);
return binding?.Create();
}
}

/// <summary>
/// The bindings for the transport listeners.
/// </summary>
public class TransportListenerBindings :
TransportBindingsBase<ITransportListenerFactory>
{
/// <summary>
/// The bindings for the transport listeners.
/// Initialize the transport listener.
/// </summary>
public class TransportListenerBindings :
TransportBindingsBase<ITransportListenerFactory>
/// <param name="defaultBindings">List of known default bindings.</param>
public TransportListenerBindings(Type[] defaultBindings) : base(defaultBindings)
{
/// <summary>
/// Initialize the transport listener.
/// </summary>
/// <param name="defaultBindings">List of known default bindings.</param>
public TransportListenerBindings(Type[] defaultBindings) : base(defaultBindings)
{
}
}

/// <summary>
/// Get a transport listener for the specified uri scheme.
/// </summary>
/// <param name="uriScheme">The uri scheme of the transport.</param>
public ITransportListener GetListener(string uriScheme)
{
var binding = GetBinding(uriScheme);
return binding?.Create();
}
/// <summary>
/// Get a transport listener for the specified uri scheme.
/// </summary>
/// <param name="uriScheme">The uri scheme of the transport.</param>
public ITransportListener GetListener(string uriScheme)
{
var binding = GetBinding(uriScheme);
return binding?.Create();
}
}
}

0 comments on commit 244b26e

Please sign in to comment.