Show / Hide Table of Contents

Class WaveServer

Represents "(W)eb(A)pp(V)iew(E)nhanced" web server which provides DYNAMIC web site services. This server is not meant to be exposed directly to the public Internet, rather it should be used as an application server behind the reverse proxy, such as NGINX. This server is designed to serve dynamic data-driven requests/APIs and not meant to be used for serving static content files (although it can). The implementation is based on a lightweight HttpListener that processes incoming Http requests via an injectable WorkDispatcher which governs the threading and WorkContext lifecycle. The server processing pipeline is purposely designed to be synchronous-blocking (thread per call) which does not mean that the server is inefficient, to the contrary - this server design is specifically targeting short-called methods relying on a classical thread call stack. This approach obviates the need to create surrogate message loops/synchro contexts, tasks and other objects that introduce extra GC load. The server easily support "dangling"(left open indefinitely) WorkContext instances that can stream events (i.e. SSE/Server Push) and WebSockets from specially-purposed asynchronous notification threads.

Inheritance
System.Object
DisposableObject
ApplicationComponent
Service
Service<System.Object>
ServiceWithInstrumentationBase<System.Object>
WaveServer
Implements
IApplicationComponent
System.IDisposable
IService
INamed
IConfigurable
ILocalizedTimeProvider
IInstrumentable
IExternallyParameterized
Inherited Members
ServiceWithInstrumentationBase<Object>.ExternalParameters
ServiceWithInstrumentationBase<Object>.ExternalParametersForGroups(String[])
ServiceWithInstrumentationBase<Object>.ExternalGetParameter(String, Object, String[])
ServiceWithInstrumentationBase<Object>.ExternalSetParameter(String, Object, String[])
Service<Object>.ComponentDirector
Service.CONFIG_NAME_ATTR
Service.Destructor()
Service.ApplicationDontAutoStartService
Service.Status
Service.Running
Service.Name
Service.TimeLocation
Service.LocalizedTime
Service.Configure(IConfigSectionNode)
Service.Start()
Service.SignalStop()
Service.CheckForCompleteStop()
Service.WaitForCompleteStop()
Service.AcceptManagerVisit(Object, DateTime)
Service.UniversalTimeToLocalizedTime(DateTime)
Service.LocalizedTimeToUniversalTime(DateTime)
Service.AbortStart()
Service.DoCheckForCompleteStop()
Service.CheckServiceInactive()
Service.CheckServiceActive()
Service.CheckServiceActiveOrStarting()
Service.DoAcceptManagerVisit(Object, DateTime)
Service.____ObtainPrivateServiceStatusLockObject()
ApplicationComponent.AllComponents
ApplicationComponent.GetAppComponentBySID(UInt64)
ApplicationComponent.GetAppComponentByCommonName(String)
ApplicationComponent.ComponentSID
ApplicationComponent.ComponentStartTime
DisposableObject.DisposeAndNull<T>(T)
DisposableObject.DisposeStarted
DisposableObject.Disposed
DisposableObject.EnsureObjectNotDisposed()
DisposableObject.Dispose()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: NFX.Wave
Assembly: NFX.Wave.dll
Syntax
public class WaveServer : ServiceWithInstrumentationBase<object>, IApplicationComponent, IDisposable, IService, INamed, IConfigurable, ILocalizedTimeProvider, IInstrumentable, IExternallyParameterized
Remarks

The common belief that asynchronous non-thread-based web servers always work faster (i.e. Node.js) is not true in the data-oriented systems of high scale because eventually multiple web server machines still block on common data access resources, so it is much more important to design the database backend in an asynchronous fashion, as it is the real bottle neck of the system. Even if most of the available threads are not physically paused by IO, they are paused logically as the logical units of work are waiting for IO and the fact that server can accept more socket requests does not mean that they will not timeout. The downsides of asynchronous web layers are: (a) much increased implementation/maintenance complexity (b) many additional task/thread context switches and extra objects that facilitate the event loops/messages/tasks etc...

Constructors

WaveServer()

Declaration
public WaveServer()

WaveServer(String)

Declaration
public WaveServer(string name)
Parameters
Type Name Description
System.String name

Fields

ACCEPT_THREAD_GRANULARITY_MS

Declaration
public const int ACCEPT_THREAD_GRANULARITY_MS = 250
Field Value
Type Description
System.Int32

CONFIG_DEFAULT_ERROR_HANDLER_SECTION

Declaration
public const string CONFIG_DEFAULT_ERROR_HANDLER_SECTION = "default-error-handler"
Field Value
Type Description
System.String

CONFIG_DISPATCHER_SECTION

Declaration
public const string CONFIG_DISPATCHER_SECTION = "dispatcher"
Field Value
Type Description
System.String

CONFIG_GATE_SECTION

Declaration
public const string CONFIG_GATE_SECTION = "gate"
Field Value
Type Description
System.String

CONFIG_PREFIX_SECTION

Declaration
public const string CONFIG_PREFIX_SECTION = "prefix"
Field Value
Type Description
System.String

CONFIG_SERVER_SECTION

Declaration
public const string CONFIG_SERVER_SECTION = "server"
Field Value
Type Description
System.String

DEFAULT_CLIENT_VARS_COOKIE_NAME

Declaration
public const string DEFAULT_CLIENT_VARS_COOKIE_NAME = "WV.CV"
Field Value
Type Description
System.String

DEFAULT_DRAIN_ENTITY_BODY_TIMEOUT_SEC

Declaration
public const ushort DEFAULT_DRAIN_ENTITY_BODY_TIMEOUT_SEC = 120
Field Value
Type Description
System.UInt16

DEFAULT_ENTITY_BODY_TIMEOUT_SEC

Declaration
public const ushort DEFAULT_ENTITY_BODY_TIMEOUT_SEC = 120
Field Value
Type Description
System.UInt16

DEFAULT_HEADER_WAIT_TIMEOUT_SEC

Declaration
public const ushort DEFAULT_HEADER_WAIT_TIMEOUT_SEC = 120
Field Value
Type Description
System.UInt16

DEFAULT_IDLE_CONNECTION_TIMEOUT_SEC

Declaration
public const ushort DEFAULT_IDLE_CONNECTION_TIMEOUT_SEC = 120
Field Value
Type Description
System.UInt16

DEFAULT_KERNEL_HTTP_QUEUE_LIMIT

Declaration
public const int DEFAULT_KERNEL_HTTP_QUEUE_LIMIT = 1000
Field Value
Type Description
System.Int32

DEFAULT_MIN_SEND_BYTES_PER_SECOND

Declaration
public const uint DEFAULT_MIN_SEND_BYTES_PER_SECOND = 150U
Field Value
Type Description
System.UInt32

DEFAULT_PARALLEL_ACCEPTS

Declaration
public const int DEFAULT_PARALLEL_ACCEPTS = 64
Field Value
Type Description
System.Int32

DEFAULT_PARALLEL_WORKS

Declaration
public const int DEFAULT_PARALLEL_WORKS = 256
Field Value
Type Description
System.Int32

DEFAULT_REQUEST_QUEUE_TIMEOUT_SEC

Declaration
public const ushort DEFAULT_REQUEST_QUEUE_TIMEOUT_SEC = 120
Field Value
Type Description
System.UInt16

INSTRUMENTATION_DUMP_PERIOD_MS

Declaration
public const int INSTRUMENTATION_DUMP_PERIOD_MS = 3377
Field Value
Type Description
System.Int32

MAX_KERNEL_HTTP_QUEUE_LIMIT

Declaration
public const int MAX_KERNEL_HTTP_QUEUE_LIMIT = 524288
Field Value
Type Description
System.Int32

MAX_PARALLEL_ACCEPTS

Declaration
public const int MAX_PARALLEL_ACCEPTS = 1024
Field Value
Type Description
System.Int32

MAX_PARALLEL_WORKS

Declaration
public const int MAX_PARALLEL_WORKS = 1048576
Field Value
Type Description
System.Int32

MIN_KERNEL_HTTP_QUEUE_LIMIT

Declaration
public const int MIN_KERNEL_HTTP_QUEUE_LIMIT = 16
Field Value
Type Description
System.Int32

MIN_PARALLEL_ACCEPTS

Declaration
public const int MIN_PARALLEL_ACCEPTS = 1
Field Value
Type Description
System.Int32

MIN_PARALLEL_WORKS

Declaration
public const int MIN_PARALLEL_WORKS = 1
Field Value
Type Description
System.Int32

Properties

ClientVarsCookieName

Provides the name of cookie where server keeps client vars

Declaration
[Config]
[ExternalParameter(new string[]{"web"})]
public string ClientVarsCookieName { get; set; }
Property Value
Type Description
System.String

ComponentCommonName

Declaration
public override string ComponentCommonName { get; }
Property Value
Type Description
System.String
Overrides
ApplicationComponent.ComponentCommonName

Dispatcher

Gets/sets work dispatcher

Declaration
public WorkDispatcher Dispatcher { get; set; }
Property Value
Type Description
WorkDispatcher

DrainEntityBodyTimeoutSec

Declaration
[Config(Default = (ushort)120)]
[ExternalParameter(new string[]{"web"})]
public ushort DrainEntityBodyTimeoutSec { get; set; }
Property Value
Type Description
System.UInt16

EntityBodyTimeoutSec

Declaration
[Config(Default = (ushort)120)]
[ExternalParameter(new string[]{"web"})]
public ushort EntityBodyTimeoutSec { get; set; }
Property Value
Type Description
System.UInt16

EnvironmentName

Provides the name of environment, i.e. DEV,PROD, TEST i.e. some handlers may depend on environment name to serve DEV vs PROD java script files etc.

Declaration
[Config]
public string EnvironmentName { get; set; }
Property Value
Type Description
System.String

Gate

Gets/sets network gate

Declaration
public INetGate Gate { get; set; }
Property Value
Type Description
INetGate

GateCallerRealIpAddressHeader

Declaration
[Config]
public string GateCallerRealIpAddressHeader { get; set; }
Property Value
Type Description
System.String

HeaderWaitTimeoutSec

Declaration
[Config(Default = (ushort)120)]
[ExternalParameter(new string[]{"web"})]
public ushort HeaderWaitTimeoutSec { get; set; }
Property Value
Type Description
System.UInt16

IdleConnectionTimeoutSec

Declaration
[Config(Default = (ushort)120)]
[ExternalParameter(new string[]{"web"})]
public ushort IdleConnectionTimeoutSec { get; set; }
Property Value
Type Description
System.UInt16

IgnoreClientWriteErrors

When true does not throw exceptions on client channel write

Declaration
[Config(Default = true)]
public bool IgnoreClientWriteErrors { get; set; }
Property Value
Type Description
System.Boolean

InstrumentationEnabled

When true, emits instrumentation messages

Declaration
[Config]
[ExternalParameter(new string[]{"web", "instrumentation"})]
public override bool InstrumentationEnabled { get; set; }
Property Value
Type Description
System.Boolean
Overrides
NFX.ServiceModel.ServiceWithInstrumentationBase<System.Object>.InstrumentationEnabled

KernelHttpQueueLimit

Establishes HTTP.sys kernel queue limit

Declaration
[Config]
public int KernelHttpQueueLimit { get; set; }
Property Value
Type Description
System.Int32

LogHandleExceptionErrors

When true writes errors that get thrown in server cathc-all HandleException methods

Declaration
[Config]
[ExternalParameter(new string[]{"web", "instrumentation"})]
public bool LogHandleExceptionErrors { get; set; }
Property Value
Type Description
System.Boolean

LogMatches

Returns matches used by the server's default error handler to determine whether exception details should be logged

Declaration
public OrderedRegistry<WorkMatch> LogMatches { get; }
Property Value
Type Description
OrderedRegistry<WorkMatch>

MinSendBytesPerSecond

Declaration
[Config(Default = 150U)]
[ExternalParameter(new string[]{"web"})]
public uint MinSendBytesPerSecond { get; set; }
Property Value
Type Description
System.UInt32

ParallelAccepts

Specifies how many requests can get accepted from kernel queue in parallel

Declaration
[Config(Default = 64)]
public int ParallelAccepts { get; set; }
Property Value
Type Description
System.Int32

ParallelWorks

Specifies how many instances of WorkContext(or derivatives) can be processed at the same time

Declaration
[Config(Default = 256)]
public int ParallelWorks { get; set; }
Property Value
Type Description
System.Int32

Prefixes

Returns HttpListener prefixes such as "http://+:8080/"

Declaration
public IList<string> Prefixes { get; }
Property Value
Type Description
System.Collections.Generic.IList<System.String>

RequestQueueTimeoutSec

Declaration
[Config(Default = (ushort)120)]
[ExternalParameter(new string[]{"web"})]
public ushort RequestQueueTimeoutSec { get; set; }
Property Value
Type Description
System.UInt16

Servers

Returns the global registry of all server instances that are active in this process

Declaration
public static IRegistry<WaveServer> Servers { get; }
Property Value
Type Description
IRegistry<WaveServer>

ShowDumpMatches

Returns matches used by the server's default error handler to determine whether exception details should be shown

Declaration
public OrderedRegistry<WorkMatch> ShowDumpMatches { get; }
Property Value
Type Description
OrderedRegistry<WorkMatch>

Methods

AfterListenerStart(HttpListener)

Override to set listener options such as TimeoutManager.MinSendBytesPerSecond after listener.Start()

Declaration
protected virtual void AfterListenerStart(HttpListener listener)
Parameters
Type Name Description
System.Net.HttpListener listener

BeforeListenerStart(HttpListener)

Override to set listener options such as TimeoutManager.MinSendBytesPerSecond before listener.Start()

Declaration
protected virtual void BeforeListenerStart(HttpListener listener)
Parameters
Type Name Description
System.Net.HttpListener listener

DoConfigure(IConfigSectionNode)

Declaration
protected override void DoConfigure(IConfigSectionNode node)
Parameters
Type Name Description
IConfigSectionNode node
Overrides
Service.DoConfigure(IConfigSectionNode)

DoSignalStop()

Declaration
protected override void DoSignalStop()
Overrides
Service.DoSignalStop()

DoStart()

Declaration
protected override void DoStart()
Overrides
Service.DoStart()

DoWaitForCompleteStop()

Declaration
protected override void DoWaitForCompleteStop()
Overrides
Service.DoWaitForCompleteStop()

HandleException(WorkContext, WorkFilter, WorkHandler, Exception)

Handles processing exception by calling ErrorFilter.HandleException(work, error). All parameters except ERROR can be null - which indicates error that happened during WorkContext dispose

Declaration
public virtual void HandleException(WorkContext work, WorkFilter filter, WorkHandler handler, Exception error)
Parameters
Type Name Description
WorkContext work
WorkFilter filter
WorkHandler handler
System.Exception error

Log(MessageType, String, String, Exception, String, Nullable<Guid>)

Facilitates server logging

Declaration
public void Log(MessageType type, string text, string from = null, Exception error = null, string pars = null, Guid? related = default (Guid? ))
Parameters
Type Name Description
MessageType type
System.String text
System.String from
System.Exception error
System.String pars
System.Nullable<System.Guid> related

MakeContext(HttpListenerContext)

Factory method that makes new WorkContext instances. Override to make a WorkContext-derivative

Declaration
protected virtual WorkContext MakeContext(HttpListenerContext listenerContext)
Parameters
Type Name Description
System.Net.HttpListenerContext listenerContext
Returns
Type Description
WorkContext

Implements

IApplicationComponent
System.IDisposable
IService
INamed
IConfigurable
ILocalizedTimeProvider
IInstrumentable
IExternallyParameterized

Extension Methods

MiscUtils.NonNull<T>(T, Func<Exception>, String)
ObjectValueConversion.AsString(Object, String, ConvertErrorHandling)
ObjectValueConversion.AsNonNullOrEmptyString(Object)
ObjectValueConversion.AsLaconicConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsJSONConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsXMLConfig(Object, ConfigSectionNode, ConvertErrorHandling)
ObjectValueConversion.AsChar(Object, Char, ConvertErrorHandling)
ObjectValueConversion.AsNullableChar(Object, Nullable<Char>, ConvertErrorHandling)
ObjectValueConversion.AsByte(Object, Byte, ConvertErrorHandling)
ObjectValueConversion.AsNullableByte(Object, Nullable<Byte>, ConvertErrorHandling)
ObjectValueConversion.AsSByte(Object, SByte, ConvertErrorHandling)
ObjectValueConversion.AsNullableSByte(Object, Nullable<SByte>, ConvertErrorHandling)
ObjectValueConversion.AsShort(Object, Int16, ConvertErrorHandling)
ObjectValueConversion.AsNullableShort(Object, Nullable<Int16>, ConvertErrorHandling)
ObjectValueConversion.AsUShort(Object, UInt16, ConvertErrorHandling)
ObjectValueConversion.AsNullableUShort(Object, Nullable<UInt16>, ConvertErrorHandling)
ObjectValueConversion.AsInt(Object, Int32, ConvertErrorHandling)
ObjectValueConversion.AsNullableInt(Object, Nullable<Int32>, ConvertErrorHandling)
ObjectValueConversion.AsUInt(Object, UInt32, ConvertErrorHandling)
ObjectValueConversion.AsNullableUInt(Object, Nullable<UInt32>, ConvertErrorHandling)
ObjectValueConversion.AsLong(Object, Int64, ConvertErrorHandling)
ObjectValueConversion.AsNullableLong(Object, Nullable<Int64>, ConvertErrorHandling)
ObjectValueConversion.AsULong(Object, UInt64, ConvertErrorHandling)
ObjectValueConversion.AsNullableULong(Object, Nullable<UInt64>, ConvertErrorHandling)
ObjectValueConversion.AsDouble(Object, Double, ConvertErrorHandling)
ObjectValueConversion.AsNullableDouble(Object, Nullable<Double>, ConvertErrorHandling)
ObjectValueConversion.AsFloat(Object, Single, ConvertErrorHandling)
ObjectValueConversion.AsNullableFloat(Object, Nullable<Single>, ConvertErrorHandling)
ObjectValueConversion.AsDecimal(Object, Decimal, ConvertErrorHandling)
ObjectValueConversion.AsNullableDecimal(Object, Nullable<Decimal>, ConvertErrorHandling)
ObjectValueConversion.AsBool(Object, Boolean, ConvertErrorHandling)
ObjectValueConversion.AsNullableBool(Object, Nullable<Boolean>, ConvertErrorHandling)
ObjectValueConversion.AsGUID(Object, Guid, ConvertErrorHandling)
ObjectValueConversion.AsNullableGUID(Object, Nullable<Guid>, ConvertErrorHandling)
ObjectValueConversion.AsDateTime(Object)
ObjectValueConversion.AsDateTime(Object, DateTime, ConvertErrorHandling)
ObjectValueConversion.AsNullableDateTime(Object, Nullable<DateTime>, ConvertErrorHandling)
ObjectValueConversion.AsGDID(Object)
ObjectValueConversion.AsGDID(Object, GDID, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDID(Object, Nullable<GDID>, ConvertErrorHandling)
ObjectValueConversion.AsGDIDSymbol(Object)
ObjectValueConversion.AsGDIDSymbol(Object, GDIDSymbol, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDIDSymbol(Object, Nullable<GDIDSymbol>, ConvertErrorHandling)
ObjectValueConversion.AsTimeSpan(Object)
ObjectValueConversion.AsTimeSpan(Object, TimeSpan, ConvertErrorHandling)
ObjectValueConversion.AsNullableTimeSpan(Object, Nullable<TimeSpan>, ConvertErrorHandling)
ObjectValueConversion.AsEnum<TEnum>(Object, TEnum, ConvertErrorHandling)
ObjectValueConversion.AsNullableEnum<TEnum>(Object, Nullable<TEnum>, ConvertErrorHandling)
ObjectValueConversion.AsUri(Object, Uri, ConvertErrorHandling)
JSONExtensions.ToJSON(Object, JSONWritingOptions)
JSONExtensions.ToJSON(Object, TextWriter, JSONWritingOptions)
JSONExtensions.ToJSON(Object, Stream, JSONWritingOptions, Encoding)
ErlObject.ToErlObject(Object)
ErlObject.ToErlObject(Object, ErlTypeOrder, Boolean)
Back to top Copyright © 2006-2018 Agnicore Inc
Generated by DocFX