netty/netty — pull request #2635 by nitsanw (2014-07-04 11:29:40+00:00)
Title: A selectNow event loop and some hacks to make it fit in.

- new sample to run it: EchoSelectNowServer.
- added interface for both new loop and old loop to implement so you can
switch between them.
This is a sucky PR, more of a proof of concept really.
I have verified the code works and compared performance on relevant hardware for the EchoServer sample. I used the https://github.com/nitsanw/java-ping spinning client to measure the performance before and after and from what I can see the results are as follows(figures in ns):
Min, 50%, 90%, 99%, 99.9%, 99.99%
NettyS 7464, 11215, 11557, 12949, 14319, 17278
NettySN 7456, 7968, 8199, 9877, 10971, 14326
JavaPS 6812, 9671, 10218, 11441, 12496, 16286
JavaPSN 6401, 6837, 6946, 8507, 10081, 12955

Where NettyS is current implementation, NettySN is using the selectNow event loop running the EchoServer. JavaPS is the java-ping project TCP select server, and JavaPSN is the selectNow server.
The difference is a consistent 3us between select/selectNow on the median and above.
This does not account for coordinated ommision and does not target an environment where selector interaction is in a different pattern. In particular the spin/backoff strategy could prove less responsive if the backoff cold state took longer than the select() blocking wakeup under similar conditions.
Also note this approach is far more CPU intensive and routine wakeups are harmful when there are more threads than core etc... YMMV ;-)