One of my big complaints with Apache MINA is the high latency that’s incurred when sending data. MINA uses a set of I/O threads to handle reads and writes. This is typical of many non-blocking I/O frameworks.
Netty is much more clever than MINA. In Netty, when you make a call to send data and the send queue is empty, Netty will just send the data. We are using non-blocking I/O so the call will still be asynchronous. If the send queue is not empty, Netty will queue up the data to be sent in much the same way that MINA does sends. The Netty approach is much faster.
Using ADBCJ I conducted a simple performance test comparing MINA and Netty. The test runs 100 simple select SQL queries against MySQL that each return a single string. Each test was run 100,000 times.
| Mean | Stdev | |
|---|---|---|
| MINA | 618,912,430.60ns | 104,509,066.50ns |
| Netty | 563,756,985.70ns | 104,440,106.73ns |
As you can see, Netty is significantly faster. In all the tests I’ve run so far, Netty has been faster.
To say I’m please with Netty would be an understatement.
7 Responses
Trustin Lee
March 4th, 2009 at 9:38 am
1Hi Mike, thanks for sharing your test result! The number looks pretty nice.
To correct just one thing, any write request in Netty is supposed to be queued to its internal buffer and flushed by I/O worker threads. This is pretty same with what MINA does.
Netty worked just like you mentioned in your post before, but the behavior has been reverted back when 3.0.0.GA is released due to some contention. I’d like to figure out the root cause of the contention to reduce the latency even more soon.
I believe where the biggest difference comes now from is probably the effective usage of data structure. Especially, Netty has much more effective buffer and queue implementation.
Trustin Lee
March 4th, 2009 at 9:51 am
2I realized that they are not exactly same at handling write requests. If the write() is called from an I/O thread, Netty tries to flush the buffer as soon as possible, while MINA doesn’t flush the queue to a certain point.
If the write() is called from an other thread than an I/O thread, both behaves same. However, that’s where the better queue and thread pool implementation kicks in.
emmanuel lecharny
March 5th, 2009 at 11:57 am
3Hi Mike,
what would be interesting is to profile MINA to know exactly where the time is lost. I’m not sure that the bottleneck is where you think… Or if it’s there, then, well, you are a MINA committer, isn’t it ?
What’s obvious is that we have many things to improve in MINA. Btw, the number you gave just shiw a slight difference, around 10%, which is still significant, but not overkilling. Except if you consider that a large part of the time is consummed in MySQL.
Last, not least, the very same test without any application at the end - ie, just a plain loopback - might demonstrate a bigger difference. Could you strip your test from the MySQL part, and re-run it ?
Would it be too much to ask you to share the test environment too ?
Many thanks !
Niall
March 28th, 2009 at 6:12 pm
4From your results thats about 10% faster - I guess we have different definitions of significant
Scalable NIO Servers - Part I - Performance « Z|NET Development
April 7th, 2009 at 8:55 pm
5[...] http://swamp.homelinux.net/blog/index.php/2009/03/03/performance-comparison-of-apache-mina-and-jboss... [...]
jim
May 28th, 2009 at 7:23 pm
6my project 1xio at Google Code http://code.google.com/p/1xio takes a non-managed approach to NIO async http stream serving.
I implemented Selectors for write which is uncommon but it works out nicely in the single thread environment.
in this implementation I use NIO as an intentional java memory leak for it’s NIO objects and do what i can to avoid strings by marking up the input ByteBuffers rather than manufacture new heap objects.
I added mimetypes and the UTF8 java strings roughly equivalent to /etc/mimetype in size double the footprint.
there is a single thread, 4 enums, and no classes presently to provide a reasonably useful static http server.
i use a technique I call ‘java metaprogramming’ similar in the spirit of c++ template metaprogramming which might have some in-constructor jit benefits over other static singleton visitor pattern strategies for asynchronous services.
Performance comparison of Apache MINA and JBoss Netty Revisited by Totally Nerdy Information
November 27th, 2009 at 12:25 pm
7[...] I ran my my original comparison, both the tests and databases were running on the same host connecting over the loopback interface. [...]
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
Archives
Links
Meta
Calendar
Recent Entries
Recent Comments
Most Commented
Totally Nerdy Information is proudly powered by WordPress - BloggingPro theme by: Design Disease