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) { 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); }