<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, &quot;akull&quot; &lt;<a href="mailto:andre.kullmann@googlemail.com">andre.kullmann@googlemail.com</a>&gt; wrote:<br type="attribution">&gt; Hi,<br>&gt; <br>&gt; I create an simple ping like server/ client application. The client sends<br>
&gt; the system nanos and the server send it back. Now I&#39;m wordering an roundtrip<br>&gt; over loopback took 0.2 millis and over lan 1 millsecond. I think this is<br>&gt; slow. For example an infinispan request/response over lan took 0.8 seconds<br>
&gt; incl. cache lookup and object serialization.<br>&gt; Is 1 one milli an good time for an netty roundtrip ? <br>&gt; <br>&gt; Regards,<br>&gt; André<br>&gt; <br>&gt; <br>&gt; My Server<br>&gt; <br>&gt; public class Netty {<br>
&gt; <br>&gt;         public static void main(String[] args) throws Exception {<br>&gt; <br>&gt;         ChannelFactory factory =<br>&gt;             new NioServerSocketChannelFactory(<br>&gt;                     Executors.newCachedThreadPool(),<br>
&gt;                     Executors.newCachedThreadPool());<br>&gt; <br>&gt;         ServerBootstrap bootstrap = new ServerBootstrap(factory);<br>&gt; <br>&gt;         bootstrap.getPipeline().addLast(&quot;handler&quot;, new<br>
&gt; SimpleChannelHandler() {<br>&gt;             @Override<br>&gt;             public void messageReceived(ChannelHandlerContext ctx,<br>&gt; MessageEvent e) throws Exception {<br>&gt;                 e.getChannel().write(e.getMessage());<br>
&gt;             }<br>&gt;         });<br>&gt; <br>&gt;         bootstrap.bind(new InetSocketAddress(5555));<br>&gt;     }<br>&gt; }<br>&gt; <br>&gt; My Client<br>&gt; <br>&gt; public class NettyClient {<br>&gt; <br>&gt;         private static double nanosToMillis( double nanos ) {<br>
&gt;                 double d = ( nanos / (double) 1000 ) / (double) 1000;<br>&gt;                 return BigDecimal.valueOf(d).setScale( 5, BigDecimal.ROUND_UP<br>&gt; ).doubleValue();<br>&gt;         }<br>&gt; <br>&gt;         public static void main(String[] args) {<br>
&gt;                 <br>&gt;                 ChannelFactory factory = new NioClientSocketChannelFactory(<br>&gt;                                 Executors.newCachedThreadPool(),<br>&gt;                                 Executors.newCachedThreadPool() );<br>&gt;         <br>&gt;         ClientBootstrap bootstrap = new ClientBootstrap(factory);<br>
&gt;         <br>&gt;         bootstrap.setPipelineFactory(new ChannelPipelineFactory() {<br>&gt;                 @Override<br>&gt;             public ChannelPipeline getPipeline() throws Exception {<br>&gt;                                 return Channels.pipeline(new SimpleChannelUpstreamHandler() {<br>
&gt;                                         @Override<br>&gt;                             public void messageReceived( ChannelHandlerContext ctx,<br>&gt; MessageEvent e) {<br>&gt; <br>&gt;                                     long now = System.nanoTime();<br>&gt;                                             ChannelBuffer buffer = (ChannelBuffer) e.getMessage();<br>
&gt;                                             long time = Bits.getLong( buffer.array(), 0 );<br>&gt;                                             System.out.println( nanosToMillis(now-time) + &quot;ms.&quot;);<br>&gt;                                 }<br>&gt;                 });<br>&gt;             }<br>
&gt;         });<br>&gt;         <br>&gt;         ChannelFuture future = bootstrap.connect( new<br>&gt; InetSocketAddress(&quot;localhost&quot;, 5555) );<br>&gt;         future.addListener( new ChannelFutureListener() {<br>
&gt;                         <br>&gt;                         @Override<br>&gt;                         public void operationComplete( final ChannelFuture future) throws<br>&gt; Exception {<br>&gt;                                 <br>&gt;                                 TimerTask task = new TimerTask() {<br>&gt;                                         @Override<br>&gt;                                         public void run() {<br>
&gt;                                                 byte[] bytes = new byte[8];<br>&gt;                                                 Bits.putLong(bytes, 0, System.nanoTime() );<br>&gt;                                                 ChannelBuffer msg = ChannelBuffers.copiedBuffer( bytes );                                                <br>&gt;                                                 future.getChannel().write(msg);<br>
&gt;                                         }<br>&gt;                                 };<br>&gt;                         <br>&gt;                                 new Timer().schedule(task, 0, 1000 );<br>&gt;                         }<br>&gt;                 });<br>&gt;         }<br>&gt; }<br>&gt; <br>&gt; <br>&gt; --<br>&gt; 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>
&gt; Sent from the Netty User Group mailing list archive at Nabble.com.<br>&gt; <br>&gt; _______________________________________________<br>&gt; netty-users mailing list<br>&gt; <a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users">https://lists.jboss.org/mailman/listinfo/netty-users</a><br></div>