<p>AFAIK nanotime is not very reliable and the javadoc warn of that.<br>
Also, this is not a good test for Netty, as its power really lies in being able to scale smoothly. For raw performance, you need to remove as many layers of indirection as possible …</p>
<p>--<br>
Marc-André Laverdiere<br>
Sent from a mobile device. Please excuse the brevity </p>
<div class="gmail_quote">On 16-Jul-2011 2:44 AM, "akull" <<a href="mailto:andre.kullmann@googlemail.com">andre.kullmann@googlemail.com</a>> wrote:<br type="attribution">> Hi,<br>> <br>> I create an simple ping like server/ client application. The client sends<br>
> the system nanos and the server send it back. Now I'm wordering an roundtrip<br>> over loopback took 0.2 millis and over lan 1 millsecond. I think this is<br>> slow. For example an infinispan request/response over lan took 0.8 seconds<br>
> incl. cache lookup and object serialization.<br>> Is 1 one milli an good time for an netty roundtrip ? <br>> <br>> Regards,<br>> André<br>> <br>> <br>> My Server<br>> <br>> public class Netty {<br>
> <br>>         public static void main(String[] args) throws Exception {<br>> <br>> ChannelFactory factory =<br>> new NioServerSocketChannelFactory(<br>> Executors.newCachedThreadPool(),<br>
> Executors.newCachedThreadPool());<br>> <br>> ServerBootstrap bootstrap = new ServerBootstrap(factory);<br>> <br>> bootstrap.getPipeline().addLast("handler", new<br>
> SimpleChannelHandler() {<br>> @Override<br>> public void messageReceived(ChannelHandlerContext ctx,<br>> MessageEvent e) throws Exception {<br>> e.getChannel().write(e.getMessage());<br>
> }<br>> });<br>> <br>> bootstrap.bind(new InetSocketAddress(5555));<br>> }<br>> }<br>> <br>> My Client<br>> <br>> public class NettyClient {<br>> <br>>         private static double nanosToMillis( double nanos ) {<br>
>                 double d = ( nanos / (double) 1000 ) / (double) 1000;<br>>                 return BigDecimal.valueOf(d).setScale( 5, BigDecimal.ROUND_UP<br>> ).doubleValue();<br>>         }<br>> <br>>         public static void main(String[] args) {<br>
>                 <br>>                 ChannelFactory factory = new NioClientSocketChannelFactory(<br>>                                 Executors.newCachedThreadPool(),<br>>                                 Executors.newCachedThreadPool() );<br>> <br>> ClientBootstrap bootstrap = new ClientBootstrap(factory);<br>
> <br>> bootstrap.setPipelineFactory(new ChannelPipelineFactory() {<br>>         @Override<br>> public ChannelPipeline getPipeline() throws Exception {<br>>                                 return Channels.pipeline(new SimpleChannelUpstreamHandler() {<br>
>                                         @Override<br>>                  public void messageReceived( ChannelHandlerContext ctx,<br>> MessageEvent e) {<br>> <br>>                          long now = System.nanoTime();<br>>                                   ChannelBuffer buffer = (ChannelBuffer) e.getMessage();<br>
>                                   long time = Bits.getLong( buffer.array(), 0 );<br>>                                   System.out.println( nanosToMillis(now-time) + "ms.");<br>>                          }<br>> });<br>> }<br>
> });<br>> <br>> ChannelFuture future = bootstrap.connect( new<br>> InetSocketAddress("localhost", 5555) );<br>> future.addListener( new ChannelFutureListener() {<br>
>                         <br>>                         @Override<br>>                         public void operationComplete( final ChannelFuture future) throws<br>> Exception {<br>>                                 <br>>                                 TimerTask task = new TimerTask() {<br>>                                         @Override<br>>                                         public void run() {<br>
>                                                 byte[] bytes = new byte[8];<br>>                                                 Bits.putLong(bytes, 0, System.nanoTime() );<br>>                                                 ChannelBuffer msg = ChannelBuffers.copiedBuffer( bytes );                                                <br>>                                                 future.getChannel().write(msg);<br>
>                                         }<br>>                                 };<br>>                         <br>>                                 new Timer().schedule(task, 0, 1000 );<br>>                         }<br>>                 });<br>>         }<br>> }<br>> <br>> <br>> --<br>> View this message in context: <a href="http://netty-forums-and-mailing-lists.685743.n2.nabble.com/netty-performance-tp6588064p6588064.html">http://netty-forums-and-mailing-lists.685743.n2.nabble.com/netty-performance-tp6588064p6588064.html</a><br>
> Sent from the Netty User Group mailing list archive at Nabble.com.<br>> <br>> _______________________________________________<br>> netty-users mailing list<br>> <a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/netty-users">https://lists.jboss.org/mailman/listinfo/netty-users</a><br></div>