I’ve been playing with Web Sockets using Google’s Chrome browser. Web Sockets, put simply, is a really nice way for a web application to talk to a remote server and allows the remote server to talk back. There are currently various ways of doing this with using Comet. But let’s be honest. Comet is a total hack. Web Sockets, on the other hand, is a very elegant solution.
I submitted a patch to the Netty project for supporting the Web Sockets protocol.
To demonstrate how to use this patch, I’ve created a little demo. This demo consists of a simple web page for sending data to the server using the Web Sockets API JavaScript API, and a simple Netty server for serving up the web page and handling the data send over the Web Socket protocol. You can download this demo from, http://people.apache.org/~mheath/websocketexample.zip. To compile it, you will need that latest version of Netty from Subversion and apply the patch I mentioned earlier.
I’ve been meaning to post these results for a while and with the Thanksgiving break here in the US, I have time to finally do it.
When I ran my my original comparison, both the tests and databases were running on the same host connecting over the loopback interface. Using the loopback interface is a good way to test but the performance characteristics of going over a real network are much different. So I ran the tests again connecting to a second host over a gigabit/second Ethernet network.
I’ve also updated my tests to use the latest versions of both MINA and Netty.
Not only did I run the tests again over a real network connection, but I also added results for using Postgresql as well as the results of using plain JDBC and using JDBC with a thread-pool. Each test executes 50 SELECT statements and each test was run 100 times. Very interesting results.
| Test | Mean |
|---|---|
| MySQL JDBC | 23.03ms |
| MySQL JDBC/Thread-pool | 69.89ms |
| MySQL ADBCJ/MINA | 7.74ms |
| MySQL ADBCJ/Netty | 4.84ms |
| Postgresql JDBC | 25.95ms |
| Postgresql JDBC/Thread-pool | 176.98ms |
| Postgresql ADBCJ/MINA | 6.9ms |
| Postgresql ADBCJ/Netty | 5.65ms |
An astute observer would question why JDBC is so much slower than both ADBCJ/MINA or ADBCJ/Netty. The answer to that question is the fact that ADBCJ supports pipelining which increases the performance of executing multiple queries significantly.
Netty continues to amaze and MINA is still really slow. It’s unfortunate to see the slow progress of MINA. While MINA 2.0 still hasn’t been released, Netty releases happen on a regular basis. It’s true that I’m on the MINA PMC and I could help get a 2.0 release out the door but I just don’t have the time. And honestly, why would I want to contribute to MINA when Netty is making faster progress and is frankly a better framework?
20 Jun
Posted by Mike Heath as Uncategorized
Why is DataInputStream.read(byte[] b, int off, int len) declared final? Stupid. Stupid. Stupid.
I am a big GWT fan and am excited about Google App Engine which is why some of my friends and I are starting the Utah Google Technology User Group. We’re just getting started and don’t yet have a place to meet but we’re working to get the word out.
If you’re interested in participating, please let us know.
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.
I recently saw this fascinating Google Tech Talk from Van Jacobsen. It’s a few years old but it’s one of those things I wish I would have scene years ago when I started grad school doing research in networking and the Internet.
This talk really puts into perspective the importance of things like distributed hash tables and other peer-to-peer technologies and shows that there’s more use for these technologies than just pirating software.
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Dec | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||