How to read efficiently from socket using Java NIO

后端 未结 2 953
梦如初夏
梦如初夏 2021-02-11 05:34

I am working on task involving reading from the socket trading quotes and I need to achieve minimum latency and high throughput.

I started with the simpliest possible ja

2条回答
  •  深忆病人
    2021-02-11 06:07

    You can achieve higher than that with Disruptor and other methods. A lot depends on the size and complexity of message (as well as what you do with the message !!)

    If you want to serialize/deserialze with ByteBuffer, use the putXxxx and getXxxx methods. To make this process easier, I suggest putting the length of each message first so you can check you have a full message before attempting to parse it.

    You might find this presentation interesting http://vanillajava.blogspot.com/2011/11/low-latency-slides.html

提交回复
热议问题