Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6861529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:32:47+00:00 2026-05-27T02:32:47+00:00

I am working on task involving reading from the socket trading quotes and I

  • 0

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 java nio prototype like this

ByteBuffer buf = ByteBuffer.allocateDirect(BUFFER_SIZE);
try {
       buf.clear();
       int numBytesRead = socketChannel.read(buf);

       if (numBytesRead == -1) {  
           socketChannel.close();
       } else {
           buf.flip();
           byte[] byteArrived = new byte[buf.remaining];
           buf.get(byteArrived,0,byteArrived.length);
           // here we send byteArrived to the parser
       }
   } catch (IOException e) {    
}

I guess it is lame to create byte[] array every time, but due to the lack of knowledge I dont know how to parse ByteBuffer ( because I need to unmarshall byte protocol into messages and pass them into business logic). Can you recommend how to avoid mass garbage creation?

Also I would like to ask about best practices how to organize socket reading with low latency and high throughput? I read about LMAX and disruptor framework and they achieved 6M transactions on the single thread.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:32:48+00:00Added an answer on May 27, 2026 at 2:32 am

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a task to enable image uploading and auto-scaling(from full sized
I am working on a task that needs to checkout source from a github
I've recently started working on a new application which will utilize task parallelism. I
I'm working on a task where I need to redirect all traffic going to
Hi i've been working on a task of porting some code from some old
I'm working on a task tracking program for my job. It is modified from
I am currently working on a task where i need to fetch the locations
I'm working on a task system and I'd like to be able to submit
I've got the unpleasurable task of working on a Classic ASP site (VBSCRIPT) and
hey guys im working on a task to make my story's links like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.