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.

  • 1
    Does "under load" mean that the receiving thread might not even get scheduled for 70ms because you have more computation heavy threads than CPU cores? Jan 6, 2017 at 22:01
  • @codes good question: the benchmark I created does no processing, it just receives and returns a big string. I'm using (about) half the cores to send and half to receive.
    – Bohemian
    Jan 6, 2017 at 22:07
  • While there are certainly faster transports than http on localhost, it still shouldn't be anywhere that slow. Jan 6, 2017 at 22:10
  • @CodesInChaos hmmm. You made me think about how many threads I had on both sides, and it had too many. My throughput with less processing threads on the listening side and less on the sending side gave results of about 10ms with 600+ TPS. Which is acceptable. I'm still going to try memory mapped file for interest sake.
    – Bohemian
    Jan 6, 2017 at 23:42

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.