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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:51:05+00:00 2026-05-23T21:51:05+00:00

I’m writing a performance-critical bidirectional streaming server using boost.asio. The server works this way

  • 0

I’m writing a performance-critical bidirectional streaming server using boost.asio.
The server works this way :

  • Thread A treats and pushes objects to be sent in the OUTPUT queue
  • Thread B waits for objects in the INPUT queue to treat them
  • Thread C is an acceptor thread that accepts incoming clients and creates a CLIENT class for each one

Multiple clients run at the same time, each one has his own connected socket and each one must do two things at the same time :

  • wait (condition variable) for at least one object to be present in the OUTPUT queue (this may take long) and send it as fast as possible
  • get any incoming object from the socket, and put it in the INPUT queue

Moreover, performance and multicore scalability are critical in this application.

The standard async approach fails here (the send callbacks may block other callbacks while waiting for a new object to send) and the blocking approach (using 1 thread for each direction) is complicated and I can’t figure out what to do in case of an error on one of the threads.

Should I use 2 sockets for each client (one for output and one for input) ? Or maybe somehow use two io_services per socket, on two different threads for concurrent callback support ?

Please explain me how you would deal with such a situation.
Thank you.

  • 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-23T21:51:06+00:00Added an answer on May 23, 2026 at 9:51 pm

    The standard async approach fails here (the send callbacks may block
    other callbacks while waiting for a new object to send)

    The async model should work fine, and if used properly is definitely going to scale better—it only falls apart when you introduce blocking. Instead of ditching async, here’s what I would suggest:

    Remove the condition variable. You need two queues: OUTPUT and WAITING.

    Then when processing a client:

    1. If there’s data in the OUTPUT queue, send it.
    2. If not, push it on the WAITING queue.

    There is no requirement to perform the next I/O from within the handler of a previous one. Here instead of blocking on a condition variable, we just offhand it onto the WAITING queue for later processing.

    And in the OUTPUT-pushing code:

    1. If there are clients in the WAITING queue, send the data directly.
    2. If not, push onto the OUTPUT queue.

    Here’s some pseudo-code:

    queue<packet> output;
    queue<client> waiting;
    
    void try_send(client c)
    {
        if(!output.empty())
        {
            // there is output waiting to be sent, send it.
            packet p = output.pop();
            c.async_send(p, on_send_finished);
        }
        else
        {
            // nothing available, go back to waiting.
            waiting.push(c);
        }
    }
    
    void on_send_finished(client c)
    {
        // send finished, try again if any more output has accumulated:
        try_send(c);
    }
    
    void push_output(packet p)
    {
        output.push(p);
    
        if(!waiting.empty())
        {
            // there is a client waiting to send, give it a try.
            client c = waiting.pop();
            try_send(c);
        }
    }
    

    This can all be done in a scalable way using a single thread, but multiple threads are pretty easy with asio. If you’re going to use multiple threads, you’ll want to introduce a lock in the logic that checks the queues.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.