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.