3

Is RMI the king (speed-wise) of the binary networking protocols, or are there others out there with higher benchmarked speeds?

Is it possible to use something like Netty to build my own binary (TCP) protocol that would be faster? I'm new to networking and trying to wrap my head around the various libraries and frameworks that are available. Thansk in advance!

3 Answers3

2

RMI's speed is governed by two things:

  1. Default Java serialization
  2. Distributed garbage collection

Default Java serialization can be surprisingly bloated. You can make your object serialization more lightweight by implementing Externalizale and doing your own bare-bones serialization. This already start to look like doing a custom protocol.

Distributed Garbage Collection can become a factor if your system grows large and contains many JVMs. DGC involves JVMs exchanging messages alerting each other about objects which are subject to garbage collection. It can potentially create a lot of network traffic.

That said, RMI "out of the box" can be faster than other "out of the box" alternatives. For example, SOAP can be much less efficient on the wire and involves a much deeper and heavier network stack than RMI.

You can build a faster custom RPC than RMI, but if you rely on Java serialization, it probably won't be much faster because of point #1 above.

Finally, why do you want a faster protocol? Are you having problems with the speed of RMI? Are you looking to pick the fastest "out of the box" solution upfront? Keep in mind The rules of Optimize Club.

Charles Forsythe
  • 1,831
  • 11
  • 12
  • Thanks @Charles Forsythe (+1) - I found [this](http://stackoverflow.com/questions/817853/what-is-the-difference-between-serializable-and-externalizable-in-java) after googling "serializable vs externalizable" and according to the leading answer, JBoss has their own serialization mechanism that is a "drop-in" replacement for the one that ships with the JDK. Do you know anything about this? What does it mean to be a "drop-in" replacement. I might be just as well using RMI with this (optimized) JBoss serializer... and thanks again! –  Mar 30 '13 at 20:21
  • Also, it looks like there are serializers that are much faster than JBoss (take look [here](https://github.com/eishay/jvm-serializers/wiki)). According to this, [kryp](http://code.google.com/p/kryo/) is the king of the serializers. So the same question as above, can kryo be "dropped in" to replace JRE serialization, but still use RMI as the protocol? If so, how? Thanks again! –  Mar 30 '13 at 20:35
  • No it isn't. RMI uses Object Serialization and nothing else. – user207421 Mar 30 '13 at 23:17
  • 1
    RMI's speed is also governed by DNS, and by network bandwidth of course. I don't see that DGC has much to do with it, it happens out-of-band. – user207421 Apr 05 '13 at 01:42
1

RMI needs to process metadata and it uses reflection. If you implement a custom protocol based on TCP and DataOutputStream / DataInputStream it may be faster than RMI.

Assuming we have an RMI Service

 Service srv = (Service) Naming.lookup(lookupString);
 srv.sayHi("Jack");
 srv.sayBye("Back");

We can do the same sending a command and param directly thru TCP connection

 ObjectOutputStream out = ...
 out.write(0);  // 0 - Hi command 
 out.writeUTF("Jack");
 out.write(1);  // 1 - Bye command
 out.writeUTF("Jack");
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • Thanks @Evgeniy Dorofeev (+1) - please look at my question underneath Charles Forsythe's answer - I have the same question for you! –  Mar 30 '13 at 20:35
  • It would be more accurate to say that Object Serialization uses reflection, and that RMI uses Object Serialization. It would also be better to remove the word 'generic', which has a specific and different meaning in Java, it doesn't add anything here. – user207421 Mar 30 '13 at 23:17
1

Protocal Buffers are one the the most compact ways of serializing java objects.

Depending on your needs you can combine that with your own transport protocol (raw tcp sockets, udp, http..)

Andreas Petersson
  • 16,248
  • 11
  • 59
  • 91
  • Thanks @Andreas Petersson (+1) - please look at my question underneath Charles Forsythe's answer - I have the same question for you! –  Mar 30 '13 at 20:36