Hi,
On Mon, Feb 18, 2013 at 6:30 AM, <
shah...@gmail.com> wrote:
> Hi All,
> I'm attempting to do a comparison of Java's main networking APIs: old IO,
> NIO and NIO2 and some variations within those APIs.
>
> My goal is to take up Martin's suggestion of actually doing tests, rather
> than relying on folklore and specifically to see if how to optimize a FIX
> client library (
https://github.com/falconair/FIXClient).
>
> The code is here:
>
https://gist.github.com/falconair/4975243
>
> I would love to get some feedback before I clean it up further. If there are
> glaring errors or suggestions, please share them. I wrote the program so you
> can pretty much copy and paste into your editor, name the file correctly and
> run it (jdk 7).
Just to recap, your server writes 8 bytes via Socket output stream for
100_000 times, and clients read using a buffer of 80 bytes.
It's a very particular benchmark, but that's ok-ish.
Some comments:
* There is no configuration for TCP_NODELAY, which I think should be
there since you're writing small byte arrays.
Call socket.setTcpNoDelay(true) on both the client and the server
(accepted) socket.
This made a *big* difference for me.
* The selector code is wrong. The contract of selector.select() is
that it returns > 0 if *new* reads are available.
But in the code you just set read interest once, never remove it, and
just read from the channel.
In fact, you will only perform 1 read of 80 bytes and that's it, not
reading the whole content from the server.
Removing the call to selector.select() makes this loop equal to
clientNonBlockedSpinChannel(), with same performance.
I am not sure for your simple benchmark you can compare apples to
apples using the selector.
* In my setup, the JIT stops compiling after 16 or so runs, so I'd say
only after those the JVM is warmed up properly.
Just for the record, at Jetty have selectors performing similarly to
any other "mode" for slightly more complex benchmarks, but sure it's
complex code to write (well don't, use Jetty's client and server
libraries instead :)
Finally, a quick note on JDK7 7's AsynchronousChannels: we considered
using them for Jetty 9 (JDK 7 based), but after a deeper look we did
not use them.
The problem lies in the AsynchronousChannels API, that while it's tons
simpler to use than using a Selector for the casual user, it is not
right for a high performance client/server (I stop here to not hijack
this thread).
--
Simone Bordet
http://bordet.blogspot.com
---
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless. Victoria Livschitz