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 7180773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:25:09+00:00 2026-05-28T17:25:09+00:00

I am working on a stock trading application whose key feature is to accept

  • 0

I am working on a stock trading application whose key feature is to accept some data from another system as fast as possible ( without blocking ). My application will then process the data at a later time.

So what I though was to let the messages queue in LinkedBlockingQueue/LinkedTransferQueue and then periodically drain the queue and process the data in a background thread.

So something along the lines of:

    private final LinkedTransferQueue<Data> queue = new LinkedTransferQueue<Data>();

    public void store( int index, long time, String[] data ) throws InterruptedException{
       Data data = new Data( index, time, data );
       queue.put( data );
    }

    private class BackgroundProcessor implements Runnable{

    private List<Data> entryList = new LinkedList<Data>( );

    @Override
    public void run(){

        try {
            while ( keepProcessing ){

                int count = queue.drainTo( entryList );

                for ( Data data : entryList ){
                //process data
                }
            }
        } catch( Exception e ){
               logger.error("Exception while processing data.", e);
        } 
    }

}

I then wanted to test the performance of this approach:

    public void testStore( String[] dataArray ) throws InterruptedException{

        int size = 100 * 1000;

        long iTime = System.nanoTime();
        for ( int i=0; i < size; i++ ){
           store( i, System.nanoTime, dataArray );
        }
        long fTime = System.nanoTime();

        System.err.println("Average Time (nanos): " +   (fTime - iTime)/size;

        float avgTimeInMicros = ((float) (fTime - iTime)/(size * 1000));
        System.err.println("Average Time (micros): " + avgTimeInMicros);
    }

I see that in my testStore(), if size = 100,0000, I can create the Data object ( which is an immutable object) and enqueue in 0.8 micro-second. However, if I decrease the size to 50, it takes as much as 20 micros.

I am assuming, the jvm after a while optimizes my code.
However, in my application, getting 50 data messages in a burst is more realistic, is there a way to tune the jvm ( or my code ) to enqueue in 1-2 micros regardless of the burst size?

P.S I tried this test on jdk 1.6 with -mx == -ms 512m.

  • 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-28T17:25:10+00:00Added an answer on May 28, 2026 at 5:25 pm

    Process 10,000 and then test for bursts of 50 after the JVM has warmed up. For a trading system, you would ensure the JVM is warmed up before you start trading.

    If you want your trading system to be consistently fast, you could consider how it can be done without discarding any objects.

    You might find the Disruptor library interesting. It is designed to handle 5 M messages/second or more. http://code.google.com/p/disruptor/

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

Sidebar

Related Questions

I'm working with in memory xml of daily stock market data, and I'm getting
I'm working on an inherited system which has some design issues which OO Buzzwords
I'm working on a stock-standard, ASP.NET MVC 3 web application (hosted on IIS 7).
i am working on the following query:- SELECT group,item,buffer,stock,(stock-buffer) AS shortexcess FROM stkmain, stkbalance,
I have working (stock) script from node var cluster = require('cluster'); var http =
I'm working on a ruby script to grab historical stock prices from Yahoo, using
From here , I am trying to get data from stock quote for every
I'm working on a stock exchange information platform and we are thinking in provide
I am working on a simple protocol stack for a small embedded system (multidrop,
I'm working on a ListView. I'd like to get the selected elements and stock

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.