netty performance

akull andre.kullmann at googlemail.com
Fri Jul 15 17:14:11 EDT 2011


Hi,

I create an simple ping like server/ client application. The client sends
the system nanos and the server send it back. Now I'm wordering an roundtrip
over loopback took 0.2 millis and over lan 1 millsecond. I think this is
slow. For example an infinispan request/response over lan took 0.8 seconds
incl. cache lookup and object serialization.
Is 1 one milli an good time for an netty roundtrip ? 

Regards,
André


My Server

public class Netty {

	public static void main(String[] args) throws Exception {

        ChannelFactory factory =
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool());

        ServerBootstrap bootstrap = new ServerBootstrap(factory);

        bootstrap.getPipeline().addLast("handler", new
SimpleChannelHandler() {
            @Override
            public void messageReceived(ChannelHandlerContext ctx,
MessageEvent e) throws Exception {
                e.getChannel().write(e.getMessage());
            }
        });

        bootstrap.bind(new InetSocketAddress(5555));
    }
}

My Client

public class NettyClient {

	private static double nanosToMillis( double nanos ) {
		double d = ( nanos / (double) 1000 ) / (double) 1000;
		return BigDecimal.valueOf(d).setScale( 5, BigDecimal.ROUND_UP
).doubleValue();
	}

	public static void main(String[] args) {
		
		ChannelFactory factory = new NioClientSocketChannelFactory(
				Executors.newCachedThreadPool(),
				Executors.newCachedThreadPool() );
        
        ClientBootstrap bootstrap = new ClientBootstrap(factory);
        
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        	@Override
            public ChannelPipeline getPipeline() throws Exception {
				return Channels.pipeline(new SimpleChannelUpstreamHandler() {
					@Override
    		        public void messageReceived( ChannelHandlerContext ctx,
MessageEvent e) {

    		        	long now = System.nanoTime();
   		        	 	ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
   		        	 	long time = Bits.getLong( buffer.array(), 0 );
   		        	 	System.out.println( nanosToMillis(now-time) + "ms.");
		        	}
                });
            }
        });
        
        ChannelFuture future = bootstrap.connect( new
InetSocketAddress("localhost", 5555) );
        future.addListener( new ChannelFutureListener() {
			
			@Override
			public void operationComplete( final ChannelFuture future) throws
Exception {
				
				TimerTask task = new TimerTask() {
					@Override
					public void run() {
						byte[] bytes = new byte[8];
						Bits.putLong(bytes, 0, System.nanoTime() );
						ChannelBuffer msg = ChannelBuffers.copiedBuffer( bytes );						
						future.getChannel().write(msg);
					}
				};
			
				new Timer().schedule(task, 0, 1000 );
			}
		});
	}
}


--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/netty-performance-tp6588064p6588064.html
Sent from the Netty User Group mailing list archive at Nabble.com.



More information about the netty-users mailing list