public IDisposable StartServer() { var monitor = new ConnectionRateMonitor(); var binding = new NetTcpBinding { Security = { Mode = SecurityMode.None } }; var listener = binding.Start(this.ConnectArguments.CreateNetTcpAddress()); Console.WriteLine("Listening on {0} for {1}", listener.Uri, typeof(SimpleObject).Name); listener.GetChannels() .SubscribeOn(System.Reactive.Concurrency.ThreadPoolScheduler.Instance) .Subscribe(c => { monitor.OnConnect(); c.GetMessages() .Subscribe( m => { monitor.OnMessage(); var obj = m.GetBody<SimpleObject>(); }, ex => monitor.OnDisconnect(), monitor.OnDisconnect); }); monitor.Start(); return Disposable.Create(listener.Abort); }
private IDisposable FixedLenghtWithAck() { var sockets = SocketEvents.GetTcpStreamSockets(_port); var monitor = new ConnectionRateMonitor(); sockets.GetConnections() .Subscribe(connection => { monitor.OnConnect(); connection .ToLengthPrefixed() .Subscribe(context => { var response = HandleMessage(context.Message); monitor.OnMessage(); context.Publish(response); }, ex => monitor.OnDisconnect(), monitor.OnDisconnect); }); monitor.Start(); return sockets; }
private IDisposable FixedLenghtWithAck() { var sockets = SocketEvents.GetTcpStreamSockets(_port); var monitor = new ConnectionRateMonitor(); sockets.GetConnections() .Subscribe(connection => { monitor.OnConnect(); connection .ToLengthPrefixed() .Subscribe(context => { var response = HandleMessage(context.Message); monitor.OnMessage(); context.Publish(response); }, ex => monitor.OnDisconnect(), monitor.OnDisconnect); }); monitor.Start(); return(sockets); }
public IDisposable StartServer() { var monitor = new ConnectionRateMonitor(); var binding = new NetTcpBinding { Security = { Mode = SecurityMode.None } }; var listener = binding.Start(_address); Console.WriteLine("Listening on " + listener.Uri); listener.GetChannels() .SubscribeOn(System.Reactive.Concurrency.ThreadPoolScheduler.Instance) .Subscribe(c => { monitor.OnConnect(); c.GetMessages() .Subscribe( m => monitor.OnMessage(), ex => monitor.OnDisconnect(), monitor.OnDisconnect); }); monitor.Start(); return(Disposable.Create(listener.Abort)); }
public IDisposable StartServer() { var monitor = new ConnectionRateMonitor(); var binding = new NetTcpBinding { Security = { Mode = SecurityMode.None } }; var listener = binding.Start(this.ConnectArguments.CreateNetTcpAddress()); Console.WriteLine("Listening on {0} for {1}", listener.Uri, typeof(SimpleObject).Name); listener.GetChannels() .SubscribeOn(System.Reactive.Concurrency.ThreadPoolScheduler.Instance) .Subscribe(c => { monitor.OnConnect(); c.GetMessages() .Subscribe( m => { monitor.OnMessage(); var obj = m.GetBody<SimpleObject>(); }, ex => monitor.OnDisconnect(), monitor.OnDisconnect); }); monitor.Start(); return Disposable.Create(listener.Abort); }
public SocketClientWithAck(ConnectArgs args, SocketCommandArgs socketArgs) { _args = args; _clients = new List <IConnection <Context <byte[]>, byte[]> >(); _connectionEnumerator = this.GetNext().GetEnumerator(); _payload = GetChars(socketArgs.Size); _monitor = new ConnectionRateMonitor(); }
public SocketClientWithAck(ConnectArgs args, SocketCommandArgs socketArgs) { _args = args; _socketArgs = socketArgs; _endpoint = SocketUtility.GetFirstIpEndPoint(_args.Server, _args.Port); _clients = new List<IConnection<Context<byte[]>, byte[]>>(); _connections = GetNext().GetEnumerator(); _payload = GetChars(_socketArgs.Size); _monitor = new ConnectionRateMonitor(); }
private IDisposable SimpleReceiver() { var sockets = SocketEvents.GetTcpStreamSockets(_port); var monitor = new ConnectionRateMonitor(); sockets.Subscribe(s => { monitor.OnConnect(); var receiver = s.CreateReceiver(); receiver.Subscribe( d => monitor.OnMessage(), ex => monitor.OnDisconnect(), monitor.OnDisconnect); }); monitor.Start(); return sockets; }
private IDisposable SimpleReceiver() { var sockets = SocketEvents.GetTcpStreamSockets(_port); var monitor = new ConnectionRateMonitor(); sockets.Subscribe(s => { monitor.OnConnect(); var receiver = s.CreateReceiver(); receiver.Subscribe( d => monitor.OnMessage(), ex => monitor.OnDisconnect(), monitor.OnDisconnect); }); monitor.Start(); return(sockets); }
public IDisposable StartServer() { var monitor = new ConnectionRateMonitor(); var binding = new NetTcpBinding { Security = { Mode = SecurityMode.None } }; var listener = binding.Start(_address); Console.WriteLine("Listening on " + listener.Uri); listener.GetChannels() .SubscribeOn(System.Reactive.Concurrency.ThreadPoolScheduler.Instance) .Subscribe(c => { monitor.OnConnect(); c.GetMessages() .Subscribe( m => monitor.OnMessage(), ex => monitor.OnDisconnect(), monitor.OnDisconnect); }); monitor.Start(); return Disposable.Create(listener.Abort); }
public IDisposable Start() { ConnectionRateMonitor monitor = new ConnectionRateMonitor(); var connections = new Task[_connections]; for (int i = 0; i < _connections; i++) { var channel = _factory.CreateChannel(_address); var openTask = Task.Factory.FromAsync(channel.BeginOpen, channel.EndOpen, null); openTask.ContinueWith(_ => monitor.OnConnect()); _channels.Enqueue(channel); connections[i] = openTask; } Task.WaitAll(connections); double backlog = 0; double currentRate = 0; AsyncCallback cb = (iar) => { IDuplexSessionChannel channel = (IDuplexSessionChannel)iar.AsyncState; backlog = monitor.OnMessageEnd(); monitor.OnMessage(); channel.EndSend(iar); }; var load = Observable.Interval(TimeSpan.FromMilliseconds(1000)) .TakeWhile(_ => !_isDisposed) .Where(_ => backlog <= _rate) .Subscribe(async _ => { int pending = _rate; Action action = () => { //Console.WriteLine("Thread ID" + System.Threading.Thread.CurrentThread.ManagedThreadId); while (Interlocked.Decrement(ref pending) >= 0) { var channel = GetNextChannel(); monitor.OnMessageStart(); var iar = channel.BeginSend(_messageBuffer.CreateMessage(), cb, channel); } }; Parallel.Invoke( new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount * 4, }, action, action, action, action, action, action, action, action ); }, ex => Console.WriteLine(ex.Message + " \n" + ex.StackTrace)); var ratemonitor = monitor.Start(); return Disposable.Create(() => { // Terminate the timer as well. _isDisposed = true; load.Dispose(); ratemonitor.Dispose(); lock (ThisLock) { while (_channels.Count > 0) { var c = _channels.Dequeue(); c.Abort(); } _factory.Abort(); } }); }
public IDisposable Start() { ConnectionRateMonitor monitor = new ConnectionRateMonitor(); var connections = new Task[_connections]; for (int i = 0; i < _connections; i++) { var channel = _factory.CreateChannel(_address); var openTask = Task.Factory.FromAsync(channel.BeginOpen, channel.EndOpen, null); openTask.ContinueWith(_ => monitor.OnConnect()); _channels.Enqueue(channel); connections[i] = openTask; } Task.WaitAll(connections); double backlog = 0; double currentRate = 0; AsyncCallback cb = (iar) => { IDuplexSessionChannel channel = (IDuplexSessionChannel)iar.AsyncState; backlog = monitor.OnMessageEnd(); monitor.OnMessage(); channel.EndSend(iar); }; var load = Observable.Interval(TimeSpan.FromMilliseconds(1000)) .TakeWhile(_ => !_isDisposed) .Where(_ => backlog <= _rate) .Subscribe(async _ => { int pending = _rate; Action action = () => { //Console.WriteLine("Thread ID" + System.Threading.Thread.CurrentThread.ManagedThreadId); while (Interlocked.Decrement(ref pending) >= 0) { var channel = GetNextChannel(); monitor.OnMessageStart(); var iar = channel.BeginSend(_messageBuffer.CreateMessage(), cb, channel); } }; Parallel.Invoke( new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount * 4, }, action, action, action, action, action, action, action, action ); }, ex => Console.WriteLine(ex.Message + " \n" + ex.StackTrace)); var ratemonitor = monitor.Start(); return(Disposable.Create(() => { // Terminate the timer as well. _isDisposed = true; load.Dispose(); ratemonitor.Dispose(); lock (ThisLock) { while (_channels.Count > 0) { var c = _channels.Dequeue(); c.Abort(); } _factory.Abort(); } })); }