Search code examples
socketsconcurrencyboost-asioboost-thread

Boost Asio, io_service handles only one socket per core


I am writing a server application using Boost Asio:

  1. Server: Running io_service.run() from pool of threads (one thread per core), accepting connections & reading data from sockets is done asynchronously.
  2. Client: Each client connects and sends a heavy file (~500MB) to the server.

Issue: All Clients are connected to the server (number of clients > number of server cores); io_service handles only one connection/socket per thread while data from other sockets are not processed until one of the processed connections completes.

I would expect that data from all connected sockets gets processed by the io_service thread pool at a same time?


Solution

  • What is the expected behavior? Your io_service can only invoke n handlers if you have n threads invoking io_service::run(). If the number of outstanding asynchronous operations is greater than n, their handlers will wait in the io_service queue until a thread is free to invoke them.