private void RegisterDefaultServices() { var traceManager = new Lazy<TraceManager>(() => new TraceManager()); Register(typeof(ITraceManager), () => traceManager.Value); var serverIdManager = new ServerIdManager(); Register(typeof(IServerIdManager), () => serverIdManager); var serverMessageHandler = new Lazy<IServerCommandHandler>(() => new ServerCommandHandler(this)); Register(typeof(IServerCommandHandler), () => serverMessageHandler.Value); var newMessageBus = new Lazy<IMessageBus>(() => new MessageBus(this)); Register(typeof(IMessageBus), () => newMessageBus.Value); var stringMinifier = new Lazy<IStringMinifier>(() => new StringMinifier()); Register(typeof(IStringMinifier), () => stringMinifier.Value); var serializer = new Lazy<JsonNetSerializer>(); Register(typeof(IJsonSerializer), () => serializer.Value); var transportManager = new Lazy<TransportManager>(() => new TransportManager(this)); Register(typeof(ITransportManager), () => transportManager.Value); var configurationManager = new DefaultConfigurationManager(); Register(typeof(IConfigurationManager), () => configurationManager); var transportHeartbeat = new Lazy<TransportHeartbeat>(() => new TransportHeartbeat(this)); Register(typeof(ITransportHeartbeat), () => transportHeartbeat.Value); var connectionManager = new Lazy<ConnectionManager>(() => new ConnectionManager(this)); Register(typeof(IConnectionManager), () => connectionManager.Value); var ackHandler = new Lazy<AckHandler>(); Register(typeof(IAckHandler), () => ackHandler.Value); var perfCounterWriter = new Lazy<PerformanceCounterManager>(() => new PerformanceCounterManager(this)); Register(typeof(IPerformanceCounterManager), () => perfCounterWriter.Value); var protectedData = new DefaultProtectedData(); Register(typeof(IProtectedData), () => protectedData); }
public static void Scaleout(int nodes, int clients) { var hosts = new MemoryHost[nodes]; var random = new Random(); var eventBus = new EventBus(); var protectedData = new DefaultProtectedData(); for (var i = 0; i < nodes; ++i) { var host = new MemoryHost(); host.Configure(app => { var config = new HubConfiguration() { Resolver = new DefaultDependencyResolver() }; var delay = i % 2 == 0 ? TimeSpan.Zero : TimeSpan.FromSeconds(1); var bus = new DelayedMessageBus(host.InstanceName, eventBus, config.Resolver, delay); config.Resolver.Register(typeof(IMessageBus), () => bus); app.MapSignalR(config); config.Resolver.Register(typeof(IProtectedData), () => protectedData); }); hosts[i] = host; } var client = new LoadBalancer(hosts); var wh = new ManualResetEventSlim(); for (int i = 0; i < clients; i++) { Task.Run(() => RunLoop(client, wh)); } wh.Wait(); }
public async Task FarmDisconnectOnlyRaisesUncleanDisconnects() { EnableTracing(); // Each node shares the same bus but are indepenent servers var counters = new SignalR.Infrastructure.PerformanceCounterManager(); var configurationManager = new DefaultConfigurationManager(); var protectedData = new DefaultProtectedData(); using (var bus = new MessageBus(new StringMinifier(), new TraceManager(), counters, configurationManager, 5000)) { var nodeCount = 3; var nodes = new List<ServerNode>(); for (int i = 0; i < nodeCount; i++) { nodes.Add(new ServerNode(bus)); } var timeout = TimeSpan.FromSeconds(5); foreach (var node in nodes) { var config = node.Resolver.Resolve<IConfigurationManager>(); config.DisconnectTimeout = TimeSpan.FromSeconds(6); IDependencyResolver resolver = node.Resolver; node.Server.Configure(app => { app.MapSignalR<FarmConnection>("/echo", new ConnectionConfiguration { Resolver = resolver }); resolver.Register(typeof(IProtectedData), () => protectedData); }); } var loadBalancer = new LoadBalancer(nodes.Select(f => f.Server).ToArray()); var transport = new Client.Transports.LongPollingTransport(loadBalancer); var connection = new Client.Connection("http://goo/echo"); await connection.Start(transport); for (int i = 0; i < nodes.Count; i++) { nodes[i].Broadcast(String.Format("From Node {0}: {1}", i, i + 1)); await Task.Delay(TimeSpan.FromSeconds(1)); } ((Client.IConnection)connection).Disconnect(); await Task.Delay(TimeSpan.FromTicks(timeout.Ticks * nodes.Count)); Assert.Equal(0, FarmConnection.OldOnDisconnectedCalls); Assert.Equal(0, FarmConnection.CleanDisconnectCount); Assert.Equal(3, FarmConnection.UncleanDisconnectCount); } }
private static void UseScaleout(int nodes, out MemoryHost[] hosts, out IHttpClient client) { hosts = new MemoryHost[nodes]; var eventBus = new EventBus(); var protectedData = new DefaultProtectedData(); for (var i = 0; i < nodes; ++i) { var host = new MemoryHost(); host.Configure(app => { var config = new HubConfiguration() { Resolver = new DefaultDependencyResolver() }; var bus = new DelayedMessageBus(host.InstanceName, eventBus, config.Resolver, TimeSpan.Zero); config.Resolver.Register(typeof(IMessageBus), () => bus); app.MapSignalR(config); config.Resolver.Register(typeof(IProtectedData), () => protectedData); }); hosts[i] = host; } client = new LoadBalancer(hosts); }