I've got an application, written in C++, that uses boost::asio. It listens for requests on a socket, and for each request does some CPU-bound work (e.g. no disk or network i/o), and then responds with a response.
This application will run on a multi-core system, so I plan to have (at least) 1 thread per core, to process requests in parallel.
Whats the best approach here? Things to think about:
- I'll need a fixed size thread pool (e.g. 1 thread per CPU)
- If more requests arrive than I have threads then they'll need to be queued (maybe in the o/s sockets layer?)
Currently the server is single threaded:
- It waits for a client request
- Once it receives a request, it performs the work, and writes the response back, then starts waiting for the next request
Update:
More specifically: what mechanism should I use to ensure that if the server is busy that incoming requests get queued up? What mechanism should I use to distribute incoming requests among the N threads (1 per core)?