2

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?

Aldin
  • 23
  • 3

1 Answers1

1

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.

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
  • I would expect that data from all connected clients is processed (at a lower rate) by the thread pool and not to simply block all other clients waiting for one thread to become free. That would mean that one connection occupies one thread exclusively during the whole data transfer even if I read data from sockets asynchronous (This is actually what I am experiencing). Did I get something wrong ? – Aldin Feb 28 '11 at 18:36
  • @Aldin how have you determined that one connection occupies a single thread invoking `io_service::run()`? – Sam Miller Feb 28 '11 at 19:02
  • I added a log message to my connection::handle_read() function (server side), which prints the port number of the connection remote endpoint, and I get only reads for the first two connections (io_service thread pool = 2) while other connections are blocked (no log messages) until one of the first two connections completes which can take some time since large files are being transferred. – Aldin Feb 28 '11 at 19:37
  • @Aldin are you using the `async_read` composed operation, or `async_read_some`? – Sam Miller Feb 28 '11 at 19:42
  • @Aldin you should probably edit your question and add some code showing how you invoke `async_read_some`, it's most likely related to the behavior you experience. – Sam Miller Feb 28 '11 at 20:21
  • It seems that the issue is related how I am sending files on the client side. I am currently using random_access_handle and the transmit_file function (from Boos::Asio examples) to transmit files. – Aldin Feb 28 '11 at 20:57
  • If I send only random data from clients then I receive data (log messages) at a "same" time for all active connections on the server side. I don't know why this happens, maybe because Server and clients are running on the same machine, but it definitely has something to do with the TransmitFile overlapped I/O API operation. – Aldin Feb 28 '11 at 21:09
  • I will try to test with clients on different hosts, and see how it works. Sam, thanks for taking the time to comment on my issue. Cheers. – Aldin Feb 28 '11 at 21:13
  • Just for record: "On Windows Vista, Windows XP, Windows 2000 Professional, and Windows NT Workstation 3.51 and later only TWO outstanding TransmitFile requests are handled simultaneously; the third request will wait until one of the previous requests is completed." – Aldin Mar 01 '11 at 13:24