How fast can an RMI be?

I saw a question: The relationship between two separate Java Java applications (answer: JGroups), and I am thinking of implementing something with JavaGroups or direct RMI, but speed is the essence. I do not send large amounts of data (the contents of MIDI messages, so 3 bytes, no more than two messages every three milliseconds), and all this will be on the same machine. Really think that RMI / JGroups on the same physical machine will be slow?

(I think I cannot afford more than 1 ms latency, as I already have some, but I'm not sure how best to talk about speed in this context.)

I assume that my real question is: Are there any options for interacting in Java that go through something more than TCP / IP? I mean things already implemented in Java, not JNI features, d need to be implemented :)

I know don’t optimize early and all that, but it's also better safe than sorry.

+4
source share
3 answers

Are there any options for messaging in Java that go through something more than TCP / IP?

Not significantly ... AFAIK.

But I think you are thinking about it wrong. Assuming you're moving small messages, the main killer will be the overhead of making the call, not the speed at which the bytes are moving. These overheads include moments such as the time spent on making system calls, switching process contexts on the client and server, processing the headers of message packets in the kernel, and routing the packets. And any synchronous RPC-like interaction entails a call to wait for a response; i.e. application time → server →.

To increase throughput, you need to focus on the following:

  • reduction in the number of RPCs required by the application; for example, by combining them into coarser and

  • considers ways to turn synchronous interactions into asynchronous interactions; for example, using message-based technologies rather than RPC.

+5
source

If speed makes sense, you should make the call in the same thread. You won’t be able to do it as fast as using the network.

However, assuming speed is not that important, you can make Java RMI calls in about 500 microseconds and use a custom RPC code that you can make loopback calls in about 24 microseconds. Even transferring data between threads in the same JVM can take 8 microseconds.

You need to decide how much time you are willing to allow to place a network call. You also need to decide whether the time to start the call is important or the time to return the result. (Often the latter has double overhead)

Note: I say microsecond here, not milliseconds. I would ignore any options that take a few milliseconds for your purposes.

+2
source

This test is about two years old, but it shows that the only popular Java remote access solution is faster than RMI, Hessian 2 (which is still in beta, I believe).

However, if your messages are only in single-digit bytes, using any remote solution seems redundant, especially if the processes are on the same machine. I would recommend combining them into one process, if possible. You might also consider using plain old Java sockets .

+1
source

All Articles