I need to call a method from another JVM running on the same machine. This methods needs to be called very many time with Java/native-like performance. It is a small-input small-output method. The other JVM runs on the same machine.
What is the fastest way to make this call and retrieve the result from this other JVM running “nearby”?
Some options are probably RMI, pipes, sockets, JMS, an optimized same-machine inter-JVM communication support, some low-level hack in the JVM. Any idea is welcome, regardless of how specialized it is.
The fastest way to communicate between JVMs on the same machine is using shared memory e.g. via memory mapped files. This is as much as 100x faster than using a Socket over loopback. e.g. a 200 ns round trip time vs a 10-20 micro-second round trip time for Sockets.
One implementation is Java Chronicle BTW The 100 ns latency includes persistence of the messages.
Whether you need either of these solutions isn’t something you should take for granted. Often when people say they have to have the “fastest” they really mean they don’t know how fast it needs to be so if they pick the fastest it should be the right solution. This is usually not correct because taking the fastest solution often means making compromises in the design and implementation which it may turn were never needed if only you knew what the requirements really were.
In short, unless you have specific, measurable latency and/or throughput requirements you should assume that the simplest solution is what you really want. This can be replaced with something faster should it turn out it is not suitable when you have a better understanding of what is required.