http://www.ioremap.net/node/202#comment-568

Mixing async models

Tagged:  

What will happen when programmer will not think twice before starting to mix thread and event-driven IO models in the same workload? I can assure you, result will look like a crap.

A simple case - storage server, which reads data requests (read or write) from the clients, performs given operation and returns a result. To optimize IO patterns we want to run as much IO requests in parallel as possible, so we can create a pool of threads which will get the work from the client and send replies back. We may dedicate a single thread to process all incoming requests from the given set of clients, and another thread to send replies back.

Described example has a very tricky to resolve bug. Since request processing is now being split - receiving/processing the request and sending its result back, we may encounter a resource limitation. For example we receive a data read request and want to use sendfile() from the different thread to sent back a reply. Since we opened file descriptor in the receiving thread, which does not really know when to stop reading pending requests from the client and wait until previously scheduled ones are ready, eventually we will hit the case when no new file descriptor may be opened.

This is a limitation of the described model only, it is possible to design it properly, but unfortunately my weekend libevent hack was created like shown above.

Back to drawing board...

hi

have you taken a look at boost::asio? it is c++, but very well gear towards async io. single or multi-threaded.

Boost is great in some places, but depending on it in the low-level system C library is not a way to go in my opinion.


Reply via email to