public void SetUp(BenchmarkContext context) { TaskScheduler.UnobservedTaskException += (sender, args) => Console.WriteLine(args.Exception); this.ClientGroup = new MultithreadEventLoopGroup(1); this.ServerGroup = new MultithreadEventLoopGroup(1); this.WorkerGroup = new MultithreadEventLoopGroup(); this.message = Encoding.UTF8.GetBytes("ABC"); this.inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); this.outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(this.inboundThroughputCounter); this.signal = new ManualResetEventSlimReadFinishedSignal(this.ResetEvent); // reserve up to 10mb of 16kb buffers on both client and server; we're only sending about 700k worth of messages this.serverBufferAllocator = new PooledByteBufferAllocator(); this.clientBufferAllocator = new PooledByteBufferAllocator(); Assembly assembly = typeof(TcpChannelPerfSpecs).Assembly; var tlsCertificate = TestResourceHelper.GetTestCertificate(); string targetHost = tlsCertificate.GetNameInfo(X509NameType.DnsName, false); ServerBootstrap sb = new ServerBootstrap() .Group(this.ServerGroup, this.WorkerGroup) .Channel <TcpServerSocketChannel>() .ChildOption(ChannelOption.Allocator, this.serverBufferAllocator) .ChildHandler(new ActionChannelInitializer <TcpSocketChannel>(channel => { channel.Pipeline //.AddLast(TlsHandler.Server(tlsCertificate)) .AddLast(this.GetEncoder()) .AddLast(this.GetDecoder()) .AddLast(counterHandler) .AddLast(new ReadFinishedHandler(this.signal, WriteCount)); })); Bootstrap cb = new Bootstrap() .Group(this.ClientGroup) .Channel <TcpSocketChannel>() .Option(ChannelOption.Allocator, this.clientBufferAllocator) .Handler(new ActionChannelInitializer <TcpSocketChannel>( channel => { channel.Pipeline //.AddLast(TlsHandler.Client(targetHost, null, (sender, certificate, chain, errors) => true)) .AddLast(this.GetEncoder()) .AddLast(this.GetDecoder()) .AddLast(new CounterHandlerOutbound(this.outboundThroughputCounter)); })); // start server this.serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server this.clientChannel = cb.ConnectAsync(this.serverChannel.LocalAddress).Result; }
public void SetUp(BenchmarkContext context) { TaskScheduler.UnobservedTaskException += (sender, args) => Console.WriteLine(args.Exception); var dispatcher = new DispatcherEventLoop(); this.serverGroup = new MultithreadEventLoopGroup(_ => dispatcher, 1); this.workerGroup = new WorkerEventLoopGroup(dispatcher); this.clientGroup = new MultithreadEventLoopGroup(_ => new EventLoop(), 1); this.message = Encoding.UTF8.GetBytes("ABC"); this.inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); this.outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(this.inboundThroughputCounter); this.signal = new ManualResetEventSlimReadFinishedSignal(this.resetEvent); // reserve up to 10mb of 16kb buffers on both client and server; we're only sending about 700k worth of messages this.serverBufferAllocator = new PooledByteBufferAllocator(); this.clientBufferAllocator = new PooledByteBufferAllocator(); ServerBootstrap sb = new ServerBootstrap() .Group(this.serverGroup, this.workerGroup) .Channel <TcpServerChannel>() .ChildOption(ChannelOption.Allocator, this.serverBufferAllocator) .ChildHandler(new ActionChannelInitializer <TcpChannel>(channel => { channel.Pipeline .AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(counterHandler) .AddLast(new ReadFinishedHandler(this.signal, WriteCount)); })); Bootstrap cb = new Bootstrap() .Group(this.clientGroup) .Channel <TcpChannel>() .Option(ChannelOption.Allocator, this.clientBufferAllocator) .Handler(new ActionChannelInitializer <TcpChannel>( channel => { channel.Pipeline .AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(new CounterHandlerOutbound(this.outboundThroughputCounter)); })); // start server this.serverChannel = sb.BindAsync(TestAddress).Result; // connect to server this.clientChannel = cb.ConnectAsync(this.serverChannel.LocalAddress).Result; }
public void SetUp(BenchmarkContext context) { ClientGroup = new MultithreadEventLoopGroup(1); ServerGroup = new MultithreadEventLoopGroup(1); WorkerGroup = new MultithreadEventLoopGroup(); var iso = Encoding.GetEncoding("ISO-8859-1"); message = iso.GetBytes("ABC"); // pre-allocate all messages foreach (var m in Enumerable.Range(0, WriteCount)) { messages[m] = Unpooled.WrappedBuffer(message); } _inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); _outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(_inboundThroughputCounter); _signal = new ManualResetEventSlimReadFinishedSignal(ResetEvent); var sb = new ServerBootstrap().Group(ServerGroup, WorkerGroup).Channel <TcpServerSocketChannel>() .ChildOption(ChannelOption.TcpNodelay, true) .ChildHandler( new ActionChannelInitializer <TcpSocketChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ReadFinishedHandler(_signal, WriteCount)); })); var cb = new ClientBootstrap().Group(ClientGroup) .Option(ChannelOption.TcpNodelay, true) .Channel <TcpSocketChannel>().Handler(new ActionChannelInitializer <TcpSocketChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()).AddLast(GetDecoder()).AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)); })); // start server _serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server _clientChannel = cb.ConnectAsync(_serverChannel.LocalAddress).Result; //_clientChannel.Configuration.AutoRead = false; }
public void SetUp(BenchmarkContext context) { this.ServerGroup = new MultithreadEventLoopGroup(1); this.WorkerGroup = new MultithreadEventLoopGroup(); Encoding iso = Encoding.GetEncoding("ISO-8859-1"); IByteBuffer buf = Unpooled.Buffer().WriteInt(3).WriteBytes(iso.GetBytes("ABC")); this.message = new byte[buf.ReadableBytes]; buf.GetBytes(buf.ReaderIndex, this.message); this.inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(this.inboundThroughputCounter); this.signal = new ManualResetEventSlimReadFinishedSignal(this.ResetEvent); // using default settings this.serverBufferAllocator = new PooledByteBufferAllocator(); ServerBootstrap sb = new ServerBootstrap() .Group(this.ServerGroup, this.WorkerGroup) .Channel <TcpServerSocketChannel>() .ChildOption(ChannelOption.Allocator, this.serverBufferAllocator) .ChildHandler(new ActionChannelInitializer <TcpSocketChannel>(channel => { channel.Pipeline .AddLast(this.GetEncoder()) .AddLast(this.GetDecoder()) .AddLast(counterHandler) .AddLast(new ReadFinishedHandler(this.signal, WriteCount)); })); // start server this.serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server var address = (IPEndPoint)this.serverChannel.LocalAddress; this.ClientSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); this.ClientSocket.Connect(address.Address, address.Port); this.Stream = new NetworkStream(this.ClientSocket, true); }
public void SetUp(BenchmarkContext context) { ClientGroup = new MultithreadEventLoopGroup(1); ServerGroup = new MultithreadEventLoopGroup(2); var iso = Encoding.GetEncoding("ISO-8859-1"); message = iso.GetBytes("ABC"); _inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); _outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(_inboundThroughputCounter); _signal = new SimpleReadFinishedSignal(); var sb = new ServerBootstrap().Group(ServerGroup).Channel <LocalServerChannel>() .ChildHandler( new ActionChannelInitializer <LocalChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ReadFinishedHandler(_signal, WriteCount)); })); var cb = new ClientBootstrap().Group(ClientGroup) .Channel <LocalChannel>() .Handler(new ActionChannelInitializer <LocalChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()).AddLast(GetDecoder()).AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)); })); // start server _serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server _clientChannel = cb.ConnectAsync(_serverChannel.LocalAddress).Result; }
public void SetUp(BenchmarkContext context) { ServerGroup = new MultithreadEventLoopGroup(1); WorkerGroup = new MultithreadEventLoopGroup(); var iso = Encoding.GetEncoding("ISO-8859-1"); message = Unpooled.Buffer().WriteInt(3).WriteBytes(iso.GetBytes("ABC")).ToArray(); _inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); _outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(_inboundThroughputCounter); _signal = new ManualResetEventSlimReadFinishedSignal(ResetEvent); var sb = new ServerBootstrap().Group(ServerGroup, WorkerGroup).Channel <TcpServerSocketChannel>() .ChildOption(ChannelOption.TcpNodelay, true) .ChildHandler( new ActionChannelInitializer <TcpSocketChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ReadFinishedHandler(_signal, WriteCount)); })); // start server _serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server var address = (IPEndPoint)_serverChannel.LocalAddress; ClientSocket = new System.Net.Sockets.Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); ClientSocket.Connect(address.Address, address.Port); Stream = new NetworkStream(ClientSocket, true); }
public void SetUp(BenchmarkContext context) { ServerGroup = new MultithreadEventLoopGroup(1); WorkerGroup = new MultithreadEventLoopGroup(); var iso = Encoding.GetEncoding("ISO-8859-1"); message = Unpooled.Buffer().WriteInt(3).WriteBytes(iso.GetBytes("ABC")).ToArray(); _inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); _outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(_inboundThroughputCounter); _signal = new ManualResetEventSlimReadFinishedSignal(ResetEvent); var sb = new ServerBootstrap().Group(ServerGroup, WorkerGroup).Channel<TcpServerSocketChannel>() .ChildOption(ChannelOption.TcpNodelay, true) .ChildHandler( new ActionChannelInitializer<TcpSocketChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ReadFinishedHandler(_signal, WriteCount)); })); // start server _serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server var address = (IPEndPoint) _serverChannel.LocalAddress; ClientSocket = new System.Net.Sockets.Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); ClientSocket.Connect(address.Address, address.Port); Stream = new NetworkStream(ClientSocket, true); }
public void SetUp(BenchmarkContext context) { this.ServerGroup = new MultithreadEventLoopGroup(1); this.WorkerGroup = new MultithreadEventLoopGroup(); Encoding iso = Encoding.GetEncoding("ISO-8859-1"); this.message = Unpooled.Buffer().WriteInt(3).WriteBytes(iso.GetBytes("ABC")).ToArray(); this.inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(this.inboundThroughputCounter); this.signal = new ManualResetEventSlimReadFinishedSignal(this.ResetEvent); // using default settings this.serverBufferAllocator = new PooledByteBufferAllocator(); ServerBootstrap sb = new ServerBootstrap() .Group(this.ServerGroup, this.WorkerGroup) .Channel<TcpServerSocketChannel>() .ChildOption(ChannelOption.Allocator, this.serverBufferAllocator) .ChildHandler(new ActionChannelInitializer<TcpSocketChannel>(channel => { channel.Pipeline .AddLast(this.GetEncoder()) .AddLast(this.GetDecoder()) .AddLast(counterHandler) .AddLast(new ReadFinishedHandler(this.signal, WriteCount)); })); // start server this.serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server var address = (IPEndPoint)this.serverChannel.LocalAddress; this.ClientSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); this.ClientSocket.Connect(address.Address, address.Port); this.Stream = new NetworkStream(this.ClientSocket, true); }
public ReadFinishedHandler(IReadFinishedSignal signal, int expectedReads) { this.signal = signal; this.expectedReads = expectedReads; }
public void SetUp(BenchmarkContext context) { ClientGroup = new MultithreadEventLoopGroup(Environment.ProcessorCount/2); ServerGroup = new MultithreadEventLoopGroup(1); WorkerGroup = new MultithreadEventLoopGroup(Environment.ProcessorCount/2); _shutdownBenchmark = new CancellationTokenSource(); _clientChannels = new ConcurrentBag<IChannel>(); _inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); _outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); _clientConnectedCounter = context.GetCounter(ClientConnectCounterName); _errorCounter = context.GetCounter(ErrorCounterName); _signal = new ManualResetEventSlimReadFinishedSignal(ResetEvent); var sb = new ServerBootstrap().Group(ServerGroup, WorkerGroup).Channel<TcpServerSocketChannel>() .ChildOption(ChannelOption.TcpNodelay, true) .ChildHandler(new ActionChannelInitializer<TcpSocketChannel>(channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(new IntCodec(true)) .AddLast(new CounterHandlerInbound(_inboundThroughputCounter)) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ErrorCounterHandler(_errorCounter)); })); ClientBootstrap = new ClientBootstrap().Group(ClientGroup) .Option(ChannelOption.TcpNodelay, true) .Channel<TcpSocketChannel>().Handler(new ActionChannelInitializer<TcpSocketChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(new IntCodec(true)) .AddLast(new CounterHandlerInbound(_inboundThroughputCounter)) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ErrorCounterHandler(_errorCounter)); })); var token = _shutdownBenchmark.Token; _eventLoop = () => { while (!token.IsCancellationRequested) { foreach (var channel in _clientChannels) { // unrolling a loop channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.Flush(); } // sleep for a tiny bit, then get going again Thread.Sleep(40); } }; // start server _serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server with 1 client initially _clientChannels.Add(ClientBootstrap.ConnectAsync(_serverChannel.LocalAddress).Result); }
public void SetUp(BenchmarkContext context) { TaskScheduler.UnobservedTaskException += (sender, args) => Console.WriteLine(args.Exception); this.ClientGroup = new MultithreadEventLoopGroup(1); this.ServerGroup = new MultithreadEventLoopGroup(1); this.WorkerGroup = new MultithreadEventLoopGroup(); Encoding iso = Encoding.GetEncoding("ISO-8859-1"); this.message = iso.GetBytes("ABC"); this.inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); this.outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(this.inboundThroughputCounter); this.signal = new ManualResetEventSlimReadFinishedSignal(this.ResetEvent); // reserve up to 10mb of 16kb buffers on both client and server; we're only sending about 700k worth of messages this.serverBufferAllocator = new PooledByteBufferAllocator(); this.clientBufferAllocator = new PooledByteBufferAllocator(); Assembly assembly = typeof(TcpChannelPerfSpecs).Assembly; byte[] certificateData; using (Stream sourceStream = assembly.GetManifestResourceStream(assembly.GetManifestResourceNames()[0])) using (var tempStream = new MemoryStream()) { sourceStream.CopyTo(tempStream); certificateData = tempStream.ToArray(); } var tlsCertificate = new X509Certificate2(certificateData, "password"); string targetHost = tlsCertificate.GetNameInfo(X509NameType.DnsName, false); ServerBootstrap sb = new ServerBootstrap() .Group(this.ServerGroup, this.WorkerGroup) .Channel<TcpServerSocketChannel>() .ChildOption(ChannelOption.Allocator, this.serverBufferAllocator) .ChildHandler(new ActionChannelInitializer<TcpSocketChannel>(channel => { channel.Pipeline //.AddLast(TlsHandler.Server(tlsCertificate)) .AddLast(this.GetEncoder()) .AddLast(this.GetDecoder()) .AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(this.outboundThroughputCounter)) .AddLast(new ReadFinishedHandler(this.signal, WriteCount)); })); Bootstrap cb = new Bootstrap() .Group(this.ClientGroup) .Channel<TcpSocketChannel>() .Option(ChannelOption.Allocator, this.clientBufferAllocator) .Handler(new ActionChannelInitializer<TcpSocketChannel>( channel => { channel.Pipeline //.AddLast(TlsHandler.Client(targetHost, null, (sender, certificate, chain, errors) => true)) .AddLast(this.GetEncoder()) .AddLast(this.GetDecoder()) .AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(this.outboundThroughputCounter)); })); // start server this.serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server this.clientChannel = cb.ConnectAsync(this.serverChannel.LocalAddress).Result; }
public void SetUp(BenchmarkContext context) { ClientGroup = new MultithreadEventLoopGroup(1); ServerGroup = new MultithreadEventLoopGroup(2); var iso = Encoding.GetEncoding("ISO-8859-1"); message = iso.GetBytes("ABC"); _inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); _outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(_inboundThroughputCounter); _signal = new SimpleReadFinishedSignal(); var sb = new ServerBootstrap().Group(ServerGroup).Channel<LocalServerChannel>() .ChildHandler( new ActionChannelInitializer<LocalChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ReadFinishedHandler(_signal, WriteCount)); })); var cb = new ClientBootstrap().Group(ClientGroup) .Channel<LocalChannel>() .Handler(new ActionChannelInitializer<LocalChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()).AddLast(GetDecoder()).AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)); })); // start server _serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server _clientChannel = cb.ConnectAsync(_serverChannel.LocalAddress).Result; }
public void SetUp(BenchmarkContext context) { ClientGroup = new MultithreadEventLoopGroup(Environment.ProcessorCount / 2); ServerGroup = new MultithreadEventLoopGroup(1); WorkerGroup = new MultithreadEventLoopGroup(Environment.ProcessorCount / 2); _shutdownBenchmark = new CancellationTokenSource(); _clientChannels = new ConcurrentBag <IChannel>(); _inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); _outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); _clientConnectedCounter = context.GetCounter(ClientConnectCounterName); _errorCounter = context.GetCounter(ErrorCounterName); _signal = new ManualResetEventSlimReadFinishedSignal(ResetEvent); var sb = new ServerBootstrap().Group(ServerGroup, WorkerGroup).Channel <TcpServerSocketChannel>() .ChildOption(ChannelOption.TcpNodelay, true) .ChildHandler(new ActionChannelInitializer <TcpSocketChannel>(channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(new IntCodec(true)) .AddLast(new CounterHandlerInbound(_inboundThroughputCounter)) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ErrorCounterHandler(_errorCounter)); })); ClientBootstrap = new ClientBootstrap().Group(ClientGroup) .Option(ChannelOption.TcpNodelay, true) .Channel <TcpSocketChannel>().Handler(new ActionChannelInitializer <TcpSocketChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(new IntCodec(true)) .AddLast(new CounterHandlerInbound(_inboundThroughputCounter)) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ErrorCounterHandler(_errorCounter)); })); var token = _shutdownBenchmark.Token; _eventLoop = () => { while (!token.IsCancellationRequested) { foreach (var channel in _clientChannels) { // unrolling a loop channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.WriteAsync(ThreadLocalRandom.Current.Next()); channel.Flush(); } // sleep for a tiny bit, then get going again Thread.Sleep(40); } }; // start server _serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server with 1 client initially _clientChannels.Add(ClientBootstrap.ConnectAsync(_serverChannel.LocalAddress).Result); }
public void SetUp(BenchmarkContext context) { ClientGroup = new MultithreadEventLoopGroup(1); ServerGroup = new MultithreadEventLoopGroup(1); WorkerGroup = new MultithreadEventLoopGroup(); var iso = Encoding.GetEncoding("ISO-8859-1"); message = iso.GetBytes("ABC"); // pre-allocate all messages foreach (var m in Enumerable.Range(0, WriteCount)) { messages[m] = Unpooled.WrappedBuffer(message); } _inboundThroughputCounter = context.GetCounter(InboundThroughputCounterName); _outboundThroughputCounter = context.GetCounter(OutboundThroughputCounterName); var counterHandler = new CounterHandlerInbound(_inboundThroughputCounter); _signal = new ManualResetEventSlimReadFinishedSignal(ResetEvent); var sb = new ServerBootstrap().Group(ServerGroup, WorkerGroup).Channel<TcpServerSocketChannel>() .ChildOption(ChannelOption.TcpNodelay, true) .ChildHandler( new ActionChannelInitializer<TcpSocketChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()) .AddLast(GetDecoder()) .AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)) .AddLast(new ReadFinishedHandler(_signal, WriteCount)); })); var cb = new ClientBootstrap().Group(ClientGroup) .Option(ChannelOption.TcpNodelay, true) .Channel<TcpSocketChannel>().Handler(new ActionChannelInitializer<TcpSocketChannel>( channel => { channel.Pipeline.AddLast(GetEncoder()).AddLast(GetDecoder()).AddLast(counterHandler) .AddLast(new CounterHandlerOutbound(_outboundThroughputCounter)); })); // start server _serverChannel = sb.BindAsync(TEST_ADDRESS).Result; // connect to server _clientChannel = cb.ConnectAsync(_serverChannel.LocalAddress).Result; //_clientChannel.Configuration.AutoRead = false; }
public ReadFinishedHandler(IReadFinishedSignal signal, int expectedReads) { _signal = signal; _expectedReads = expectedReads; }