Java – What the fastest way to pass large data between JVMs

datajavajvmspring

I have 2 JVMs on the same machine that I want to pass about 1Mb of (serializable) data between ideally in under 5 ms.

Under load, using HTTP to localhost takes about 70ms average.

I tried hazelcast, passing the data via a distributed queue – about 50ms average.

Is there a faster way?


I'm using spring boot.

Best Answer

Why don't you use pure sockets?

A socket on the same machine will send data over pretty quickly. Assuming you can send 100 MB\s over, you should be able to send 1 MB in roughly 10 ms. Getting higher speeds than this will be a bit tricky. If you had a good card you could get it to under 5 ms.

If you can serialize the data, you can send it over quite easily. See this for sending objects over sockets.

Using files would give you an average of about 80-160 MB/s or 12 ms - 6.25 ms to send 1 MB, but you'd have to read it again which will take more time.

You could use a Memory-mapped file to only have to read the file once and have it stored in memory so any virtual machine could read it from memory. Keeping a file in memory with a MappedByteBuffer will provide efficient access but you'd have to read the file first. This is also a bit more complicated than sending over sockets or writing to/reading from a file.

Related Topic