public void TestConnect27() { var heartbeatSettings = new HeartbeatSettings { UseHeartbeatFailureDetection = false }; var latencySettings = new LatencySettings { PerformLatencyMeasurements = false }; for (int i = 0; i < 100; ++i) { using ( var client = CreateClient(name: "perf_client", latencySettings: latencySettings, heartbeatSettings: heartbeatSettings)) { using ( var server = CreateServer(name: "perf_server", latencySettings: latencySettings, heartbeatSettings: heartbeatSettings)) { Bind(server); Connect(client, server.LocalEndPoint); client.Disconnect(); } } } }
public void TestConnect26() { var settings = new LatencySettings { Interval = TimeSpan.FromTicks(10), NumSamples = 20 }; using (var client = CreateClient(latencySettings: settings)) using (var server = CreateServer(latencySettings: settings)) { client.AverageRoundTripTime.Should().NotHaveValue("because this endpoint hasn't established any connection yet"); server.AverageRoundTripTime.Should().NotHaveValue("because this endpoint hasn't established any connection yet"); Bind(server); Connect(client, server.LocalEndPoint); Thread.Sleep(TimeSpan.FromMilliseconds(100)); var clientRoundtrip = client.AverageRoundTripTime; var serverRoundtrip = server.AverageRoundTripTime; Console.WriteLine("Client: {0}μs", clientRoundtrip.Value.Ticks / 10); Console.WriteLine("Server: {0}μs", serverRoundtrip.Value.Ticks / 10); clientRoundtrip.Should().BeGreaterThan(TimeSpan.Zero); serverRoundtrip.Should().BeGreaterThan(TimeSpan.Zero); } }
public void TestCtor() { var settings = new LatencySettings(); settings.PerformLatencyMeasurements.Should().BeTrue(); settings.NumSamples.Should().Be(100); settings.Interval.Should().Be(TimeSpan.FromSeconds(1)); }
internal override IRemotingEndPoint CreateClient(string name = null, IAuthenticator clientAuthenticator = null, IAuthenticator serverAuthenticator = null, LatencySettings latencySettings = null, HeartbeatSettings heartbeatSettings = null, NetworkServiceDiscoverer networkServiceDiscoverer = null) { return(new NamedPipeRemotingEndPointClient(name, clientAuthenticator, serverAuthenticator, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings)); }
internal override IRemotingEndPoint CreateServer(string name = null, IAuthenticator clientAuthenticator = null, IAuthenticator serverAuthenticator = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, HeartbeatSettings heartbeatSettings = null, NetworkServiceDiscoverer networkServiceDiscoverer = null) { return(new SocketEndPoint(EndPointType.Server, name, clientAuthenticator, serverAuthenticator, networkServiceDiscoverer: null, latencySettings: latencySettings, endPointSettings: endPointSettings, heartbeatSettings: heartbeatSettings)); }
/// <summary> /// Initializes a new silo server. /// </summary> /// <param name="args">The command line arguments given to the Main() method</param> /// <param name="customTypeResolver">The type resolver, if any, responsible for resolving Type objects by their assembly qualified name</param> /// <param name="codeGenerator">The code generator to create proxy and servant types</param> /// <param name="heartbeatSettings">The settings for heartbeat mechanism, if none are specified, then default settings are used</param> /// <param name="latencySettings">The settings for latency measurements, if none are specified, then default settings are used</param> /// <param name="endPointSettings">The settings for the endpoint itself (max. number of concurrent calls, etc...)</param> /// <param name="endPointName">The name of this silo, used for debugging (and logging)</param> public OutOfProcessSiloServer(string[] args, ITypeResolver customTypeResolver = null, ICodeGenerator codeGenerator = null, HeartbeatSettings heartbeatSettings = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, string endPointName = null) { Log.InfoFormat("Silo Server starting, args ({0}): \"{1}\", {2} custom type resolver", args.Length, string.Join(" ", args), customTypeResolver != null ? "with" : "without" ); int pid; if (args.Length >= 1 && int.TryParse(args[0], out pid)) { _parentProcessId = pid; _parentProcess = Process.GetProcessById(pid); _parentProcess.EnableRaisingEvents = true; _parentProcess.Exited += ParentProcessOnExited; } if (Log.IsDebugEnabled) { Log.DebugFormat("Args.Length: {0}", args.Length); } _registry = new DefaultImplementationRegistry(); _waitHandle = new ManualResetEvent(false); _customTypeResolver = customTypeResolver; _endPoint = new SocketEndPoint(EndPointType.Server, endPointName, codeGenerator: codeGenerator, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings, endPointSettings: endPointSettings ); _endPoint.OnConnected += EndPointOnOnConnected; _endPoint.OnDisconnected += EndPointOnOnDisconnected; _endPoint.OnFailure += EndPointOnOnFailure; }
public void TestCtor1() { var args = new[] { Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), }; var heartbeatSettings = new HeartbeatSettings { Interval = TimeSpan.FromSeconds(1.5), ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true, SkippedHeartbeatThreshold = 11 }; var latencySettings = new LatencySettings { Interval = TimeSpan.FromSeconds(1.5), NumSamples = 8, PerformLatencyMeasurements = true }; using (var server = new OutOfProcessSiloServer(args, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings)) { var endPoint = server.EndPoint; endPoint.Should().NotBeNull(); endPoint.LatencySettings.Should().BeSameAs(latencySettings); endPoint.LatencySettings.Interval.Should().Be(TimeSpan.FromSeconds(1.5)); endPoint.LatencySettings.NumSamples.Should().Be(8); endPoint.LatencySettings.PerformLatencyMeasurements.Should().BeTrue(); endPoint.HeartbeatSettings.Should().BeSameAs(heartbeatSettings); endPoint.HeartbeatSettings.Interval.Should().Be(TimeSpan.FromSeconds(1.5)); endPoint.HeartbeatSettings.ReportSkippedHeartbeatsAsFailureWithDebuggerAttached.Should().BeTrue(); endPoint.HeartbeatSettings.SkippedHeartbeatThreshold.Should().Be(11); Task.Factory.StartNew(() => server.Run(IPAddress.Loopback, 60000, 60010)); WaitFor(() => endPoint.LocalEndPoint != null && Enumerable.Range(60000, 10).Contains(endPoint.LocalEndPoint.Port), TimeSpan.FromSeconds(10)) .Should() .BeTrue(); } }
public void TestRoundtripTime() { var settings = new LatencySettings { Interval = TimeSpan.FromMilliseconds(1), NumSamples = 100 }; SharpRemote.Hosting.OutOfProcessSilo silo; using (silo = new SharpRemote.Hosting.OutOfProcessSilo(latencySettings: settings)) { silo.RoundtripTime.Should().Be(TimeSpan.Zero, "because without being started, no latency is measured"); silo.Start(); Thread.Sleep(TimeSpan.FromMilliseconds(200)); TimeSpan rtt = silo.RoundtripTime; Console.WriteLine("RTT: {0}Ticks", rtt.Ticks); rtt.Should().BeGreaterThan(TimeSpan.Zero); rtt.Should().BeLessOrEqualTo(TimeSpan.FromMilliseconds(10)); } }
public void TestCtor7() { var args = new[] { Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), }; var heartbeatSettings = new HeartbeatSettings { Interval = TimeSpan.FromSeconds(1.5), ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true, SkippedHeartbeatThreshold = 11 }; var latencySettings = new LatencySettings { Interval = TimeSpan.FromSeconds(1.5), NumSamples = 8, PerformLatencyMeasurements = true }; using (var server = new OutOfProcessSiloServer(args, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings)) { var endPoint = server.EndPoint; endPoint.Should().NotBeNull(); endPoint.LatencySettings.Should().BeSameAs(latencySettings); endPoint.LatencySettings.Interval.Should().Be(TimeSpan.FromSeconds(1.5)); endPoint.LatencySettings.NumSamples.Should().Be(8); endPoint.LatencySettings.PerformLatencyMeasurements.Should().BeTrue(); endPoint.HeartbeatSettings.Should().BeSameAs(heartbeatSettings); endPoint.HeartbeatSettings.Interval.Should().Be(TimeSpan.FromSeconds(1.5)); endPoint.HeartbeatSettings.ReportSkippedHeartbeatsAsFailureWithDebuggerAttached.Should().BeTrue(); endPoint.HeartbeatSettings.SkippedHeartbeatThreshold.Should().Be(11); } }
internal abstract IRemotingEndPoint CreateServer(string name = null, IAuthenticator clientAuthenticator = null, IAuthenticator serverAuthenticator = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, HeartbeatSettings heartbeatSettings = null, NetworkServiceDiscoverer networkServiceDiscoverer = null);
/// <summary> /// Initializes a new silo server. /// </summary> /// <param name="args">The command line arguments given to the Main() method</param> /// <param name="customTypeResolver">The type resolver, if any, responsible for resolving Type objects by their assembly qualified name</param> /// <param name="codeGenerator">The code generator to create proxy and servant types</param> /// <param name="postMortemSettings"> /// Settings to control how and if minidumps are collected - when set to null, default values are used ( /// <see /// cref="PostMortemSettings" /> /// ) /// </param> /// <param name="heartbeatSettings">The settings for heartbeat mechanism, if none are specified, then default settings are used</param> /// <param name="latencySettings">The settings for latency measurements, if none are specified, then default settings are used</param> /// <param name="endPointSettings">The settings for the endpoint itself (max. number of concurrent calls, etc...)</param> /// <param name="endPointName">The name of this silo, used for debugging (and logging)</param> public OutOfProcessSiloServer(string[] args, ITypeResolver customTypeResolver = null, ICodeGenerator codeGenerator = null, PostMortemSettings postMortemSettings = null, HeartbeatSettings heartbeatSettings = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, string endPointName = null) { if (postMortemSettings != null && !postMortemSettings.IsValid) { throw new ArgumentException("postMortemSettings"); } Log.InfoFormat("Silo Server starting, args ({0}): \"{1}\", {2} custom type resolver", args.Length, string.Join(" ", args), customTypeResolver != null ? "with" : "without" ); int pid; if (args.Length >= 1 && int.TryParse(args[0], out pid)) { _parentProcessId = pid; _parentProcess = Process.GetProcessById(pid); _parentProcess.EnableRaisingEvents = true; _parentProcess.Exited += ParentProcessOnExited; } if (Log.IsDebugEnabled) { Log.DebugFormat("Args.Length: {0}", args.Length); } if (args.Length >= 10) { if (postMortemSettings != null) { Log.Info("Ignoring post-mortem settings specified from the command-line"); } else { var settings = new PostMortemSettings(); bool.TryParse(args[1], out settings.CollectMinidumps); bool.TryParse(args[2], out settings.SuppressErrorWindows); bool.TryParse(args[3], out settings.HandleAccessViolations); bool.TryParse(args[4], out settings.HandleCrtAsserts); bool.TryParse(args[5], out settings.HandleCrtPureVirtualFunctionCalls); int tmp; int.TryParse(args[6], out tmp); settings.RuntimeVersions = (CRuntimeVersions)tmp; int.TryParse(args[7], out settings.NumMinidumpsRetained); settings.MinidumpFolder = args[8]; settings.MinidumpName = args[9]; if (!settings.IsValid) { Log.ErrorFormat("Received invalid post-mortem debugger settings: {0}", settings); } else { postMortemSettings = settings; } } } _registry = new DefaultImplementationRegistry(); _waitHandle = new ManualResetEvent(false); _customTypeResolver = customTypeResolver; _postMortemSettings = postMortemSettings; if (_postMortemSettings != null) { Log.InfoFormat("Using post-mortem debugger: {0}", _postMortemSettings); if (!NativeMethods.LoadPostmortemDebugger()) { int err = Marshal.GetLastWin32Error(); Log.ErrorFormat("Unable to load the post-mortem debugger dll: {0}", err); } if (_postMortemSettings.CollectMinidumps) { if (NativeMethods.InitDumpCollection(_postMortemSettings.NumMinidumpsRetained, _postMortemSettings.MinidumpFolder, _postMortemSettings.MinidumpName)) { Log.InfoFormat("Installed post-mortem debugger; up to {0} mini dumps will automatically be saved to: {1}", _postMortemSettings.NumMinidumpsRetained, _postMortemSettings.MinidumpFolder ); } } NativeMethods.InstallPostmortemDebugger(_postMortemSettings.HandleAccessViolations, _postMortemSettings.SuppressErrorWindows, _postMortemSettings.HandleCrtAsserts, _postMortemSettings.HandleCrtPureVirtualFunctionCalls, _postMortemSettings.RuntimeVersions); } _endPoint = new SocketEndPoint(EndPointType.Server, endPointName, codeGenerator: codeGenerator, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings, endPointSettings: endPointSettings ); _endPoint.OnConnected += EndPointOnOnConnected; _endPoint.OnDisconnected += EndPointOnOnDisconnected; _endPoint.OnFailure += EndPointOnOnFailure; }
/// <summary> /// Initializes a new instance of this silo with the specified options. /// The given host process will only be started once <see cref="Start" /> is called. /// </summary> /// <param name="process"></param> /// <param name="options"></param> /// <param name="codeGenerator">The code generator to create proxy and servant types</param> /// <param name="latencySettings"> /// The settings for latency measurements, if none are specified, then default settings are /// used /// </param> /// <param name="endPointSettings">The settings for the endpoint itself (max. number of concurrent calls, etc...)</param> /// <param name="failureSettings"> /// The settings specifying when a failure is assumed to have occured in the host process - /// if none are specified, then defaults are used /// </param> /// <param name="failureHandler"> /// The object responsible for deciding how failures are dealt with - if none is specified /// then a new <see cref="ZeroFailureToleranceStrategy" /> is used /// </param> /// <param name="endPointName">The name of the endpoint - used in log messages to differentiate between different endpoints</param> /// <exception cref="ArgumentNullException">When <paramref name="process" /> is null</exception> /// <exception cref="ArgumentException">When <paramref name="process" /> is contains only whitespace</exception> public OutOfProcessSilo( string process = ProcessWatchdog.SharpRemoteHost, ProcessOptions options = ProcessOptions.HideConsole, ICodeGenerator codeGenerator = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, FailureSettings failureSettings = null, IFailureHandler failureHandler = null, string endPointName = null ) { if (process == null) { throw new ArgumentNullException(nameof(process)); } if (string.IsNullOrWhiteSpace(process)) { throw new ArgumentException("process"); } if (failureSettings != null) { if (failureSettings.ProcessReadyTimeout <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(failureSettings), "ProcessReadyTimeout should be greater than zero"); } if (failureSettings.EndPointConnectTimeout <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(failureSettings), "EndPointConnectTimeout should be greater than zero"); } } failureSettings = failureSettings ?? new FailureSettings(); failureHandler = failureHandler ?? new ZeroFailureToleranceStrategy(); _endPoint = new SocketEndPoint(EndPointType.Client, endPointName, codeGenerator: codeGenerator, heartbeatSettings: failureSettings.HeartbeatSettings, latencySettings: latencySettings, endPointSettings: endPointSettings, waitUponReadWriteError: true); _subjectHost = _endPoint.CreateProxy <ISubjectHost>(Constants.SubjectHostId); _syncRoot = new object(); _process = new ProcessWatchdog( process, options ); _process.OnHostOutputWritten += EmitHostOutputWritten; _queue = new OutOfProcessQueue( _process, _endPoint, failureHandler, failureSettings ); _queue.OnHostStarted += QueueOnOnHostStarted; }