Eugie
Eugie

Reputation: 1413

Cant choose the right networking solution for my Java app

I am writing a distributed Java application that will make heavy use of networking, and that needs to be fast.

Let's pretend that I have a class called Widget. Widgets are created client-side (most likely a Swing box) but will need to be persisted server-side and shared/distributed amongst all the other connected clients. So, I need a way to serialize Widget instances, send them to the server, where the server will manage them and update all connected clients with state changes in the Widgets they are interested in. (So, once a Widget is created and sent server-side, it can theoretically be "pulled down" and modified by any other client.

Performance is a must, so this must be a binary protocol. Also would prefer non-blocking sockets, and something that is very, very scalable.

So I'm looking at RMI, NIO and Netty as feasible solutions. If I understand Java networking correctly, then everything seems to indicate the RMI is considerably slower than NIO. I've also heard RMI is lacking in the scalability department. NIO on the other hand, gives you more flexibility and thus is considerably more complicated. Netty seems to have the best documentation, but seems slower than NIO and may not be capable of what I really need it to do.

For Widget distribution, I'm simply looking for the ability to send Widgets over a network, and fast. Don't care what protocols are used.

Anyone care to share their thoughts/input?

Thanks!

Upvotes: 0

Views: 626

Answers (4)

StaxMan
StaxMan

Reputation: 116522

First of all, RMI and NIO are apples to oranges; so don't mix up things that are not alternatives. Second, make sure performance really truly matters; and what kind of performance (throughput & latency being usual first candidates; or maybe space efficiency). There is a chance you are overestimating significance of performance, as with good solutions you are more likely to be bounded by network performance, not by endpoint (CPU) performance.

And if performance matters, have a look at jvm-serializers to get one performance comparison of actual formats. Java serialization is used for RMI, for example.

Oh, btw, do not assume you must use a binary format. This is typically not a hard requirement; textual formats compress well and are easier to debug/troubleshoot, and process by other platforms, languages if need be.

Upvotes: 2

rfeak
rfeak

Reputation: 8204

You mentioned Netty. I would second that. My experience with Netty was great. It's a very efficient library with solid documentation and flexibility.

It can do anything you can imagine with binary protocols, yet it only does what you need, so it's lightweight. It also scales very well. I've successfully load tested a single server with a simple job sustaining over 10k+ request/sec for 200-300 concurrent clients. That was on a fairly standard rack server.

There is a bit of a learning curve, but the javadoc is some of the best I've seen for dealing with that hurdle. The project is in active development, and the lead on the project is extremely responsive to questions and defects.

EDIT: For fast transfer of Widgets, you could look into Protocol Buffers. They are pretty efficient for serializing/de-serializing objects over the wire.

Upvotes: 0

Jay
Jay

Reputation: 9582

Both Google's Protocol Buffers and Apache Thrift meet those criteria.

They are binary protocols for data serialization, and they have RPC APIs for passing your widgets over the network so that you do not have to reinvent the wheel.

Upvotes: 0

Brian Agnew
Brian Agnew

Reputation: 272297

Have you looked at Jini and Javaspaces ? It's RMI, so perhaps not suitable. But the space-based pattern is very powerful for distributing objects, receiving notifications, updating in a distributed fashion etc. and you can get something up and running very easily.

Upvotes: 0

Related Questions