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

  • Home
  • SEARCH
  • 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 6738055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:19:18+00:00 2026-05-26T11:19:18+00:00

I am creating a trading platform for a hedge fund and I need to

  • 0

I am creating a trading platform for a hedge fund and I need to be able to process market data on a separate thread(s) and I am trying to figure out which method I should be using.

The end goal is to be able to process up to 1000 messages per second as quickly as possible.

Here is what I am thinking so far:

Method I: Thread with ConcurrentQueue

This method creates a Thread and basically has the thread continuously take messages off of a queue (the Thread will stay alive).

public class MessageQueue
{
    private ConcurrentQueue<Message>    MessageQueue;
    private Thread                      QueueThread;

    public MessageQueue()
    {
        MessageQueue = new ConcurrentQueue<Message>();
        QueueThread = new Thread(ProcessQueue);
        QueueThread.Start();
    }

    public void ProcessQueue()
    {
        Message OrderMessage;

        while (IsRunning)
        {
            if (MessageQueue.TryDequeue(out OrderMessage)
            {
                ProcessMessage(OrderMessage);
            }
        }
    }

    public static void OnInboundMessage(Message MarketMessage)
    {
        MessageQueue.Enqueue(DataMessage);
    }

    public static void ProcessMessage(Message MarketMessage)
    {
        // Process Message Here
    }
}

Question: Why do people use the ‘ThreadStart’ method when creating a new Thread? It seems to work just as well if you don’t use it – what is it for?

Question: What is the benefit of using ConcurrentQueue? When will a regular Queue have a concurrency issue? It would seem that as long as you check to see that there is already something in the Queue before dequeing, there should not be any concurrency issues but I may not be understanding something.

Question: Should I be setting any properties of the Thread like ‘ApartmentState’ or ‘IsBackground’?

Method II: ThreadPool

This method simply invokes the ThreadPool with every new Message.

public class MessagePool
{
    public static void OnInboundMessage(Message MarketMessage)
    {
        ThreadPool.QueueUserWorkItem(obj => ProcessMessage(MarketMessage);
    }

    public static void ProcessMessage(Message MarketMessage)
    {
        // Process Message here
    }
}

Question: Are there any settings of the ThreadPool that might make it a more appropriate solution?

Question: I also don’t quite ‘get’ Lambda expressions but they seem to work – is there perhaps a better way of invoking ThreadPools? Is there any downside (performance, etc.) of using a Lambda?

Method III: MessageTasks

This method uses a Task in a similar fashion as the ThreadPool.

public class MessageTasks
{
    public static void OnInboundMessage(Message MarketMessage)
    {
        Task.Factory.StartNew(() => ProcessMessage(MarketMessage));
    }

    public static void ProcessMessage(Message MarketMessage)
    {
        // Process Message here
    }
}

Question: Would creating my own TaskFactory and TaskScheduler improve it’s performance?

My Performance Testing

It would seem that Method I is by far the fastest method of processing messages. It would seem like the ThreadPool takes about 9 Microseconds to add a new Workitem and the Task.Factory Method takes about 12 Microseconds. Has anyone had similar results?

Thanks in advance for your help – and if you think that I am going about this problem in entirely the wrong manner, don’t hesitate to let me know!

William

  • 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-26T11:19:18+00:00Added an answer on May 26, 2026 at 11:19 am

    A public trading platform with several 1000s of requests per second has written http://code.google.com/p/disruptor/ to support that use-case. It’s written in Java and a work-alike sister project has built http://code.google.com/p/disruptor-net/ for the .NET platform.

    There is a nice presentation by them at http://www.infoq.com/presentations/LMAX which explains the benefits in performance (10-100x faster than a ConcurrentQueue) and reliability and discusses necessary changes to the rest of the program architecture.

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

Sidebar

Related Questions

Creating a relatively simple data entry form, and just want to separate certain sections
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a server-side socket will fail if I'm trying to use the same port
I'm experimenting with grails in order to interface with an online trading platform. specifically
Here is the situation: I have a huge data set that I need quick
Creating Facebook event for specific page with FB Graph API There is a thread
Creating My Windows Form Application and using ADO.Net as Data Access layer and SQL
We are creating a trading application, where the backend is totally in C++ (using
Creating Your Own Abstract Processor is a quick paper on what I am trying
Creating a simple RPG game, first time using XNA. Trying to get my character

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.