1

We are using Java nio AsynchronousServerSocketChannel with completion handlers to write to a socket channel.

The sockets are used to communicate locally between two processes running in a same system.

We tend transfer quite a huge data. We use a buffer size 16384 to transfer the data in a chunked manner. Sending over UDP is not an option.

Is there anything else which can be done to improve the performance of the socket channel or reduce the payload transferred ?

Best Regards, Saurav

3
  • You could Zip it. It would reduce the size (obviously) but I'm not sure about overall performance. Mar 27, 2017 at 13:47
  • You can use some compression technique
    – opensam
    Mar 27, 2017 at 13:48
  • Use a much large buffer, and don't transfer it in a chunked manner. Let TCP stream it however it can. Use large socket send and receive buffers. Don't try to out-think TCP. You won't.
    – user207421
    Mar 27, 2017 at 15:02

1 Answer 1

0

There are a number of alternatives you may consider. I expect that you will need to implement each and test the actual performance on your hardware with your application in order to choose the right one.

  1. You can try to tweak your current approach. Some thoughts: much larger buffer, double buffer (use two sockets so the writer always has a socket available for writing and the reader can always be reading), only send differences (if you are continuously sending and updated version of the data), compression, etc.
  2. Use a completely different approach, such as shared memory or a memory-mapped file. A couple of questions with lots of good answers that may get you started: this and that.

While the details depend on your specific environment, you probably can speed up the communication by 10x (or maybe significantly more) over your current socket implementation.

1
  • thanks Rob for your reply...i liked the memory mapped file concept...but does java apis support non persisted memory mapped files..i have asked the question here stackoverflow.com/questions/43190764/…
    – saurav
    Apr 4, 2017 at 7:13

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.