For some time now I have been googling a lot to get to know about the various ways to acheive asynchronous programming/behavior on nix machines and ( as known earlier to me ) got confirmed on the fact that there is still no TRULY async pattern (concurrency using single thread) for Linux as available for Windows(IOCP).
Below are the few alternatives present for linux:
- select/poll/epoll :: Cannot be done using single thread as epoll is still blocking call. Also the monitored file descriptors must be opened in non-blocking mode.
- libaio:: What I have come to know about is that its implementation sucks and its still notification based instead of being completion based as with windows I/O completion ports.
- Boost ASIO :: It uses epoll under linux and thus not a true async pattern as it spawns thread which are completely abstracted from user code to acheive the proactor design pattern
- libevent :: Any reason to go for it if I prefer ASIO?
Now Here comes the questions :)
- What would be the best design pattern for writing fast scalable network server using epoll (ofcourse, will have to use threads here :( )
- I had read somewhere that "only sockets can be opened in non-blocking mode" hence epoll supports only sockets and hence cannot be used for disk I/O. How true is the above statement and why async programming cannot be done on disk I/O using epoll ?
- Boost ASIO uses one big lock around epoll call. I didnt actually understand what can be its implications and how to overcome it using asio itself. Similar question
- How can I modify ASIO pattern to work with disk files? Is there any recommended design pattern ?
Hope somebody will able to answer all the questions with nice explanations also. Any link to source where the implementation details of epoll and AIO design patterns are exaplained is also appreciated.
select
,poll
andepoll
have a timeout parameter that can be zero which makes the functions return immediately. – Apocynaceousaio_*
functions is asynchronous. You ask to be notified when an event occurs, and then go about your business doing other things while the kernel handles your I/O. – Apocynaceousselect
in a single thread. Most probably with non-zero timeouts, but using these functions in a polling way with zero timeout and in a single thread is far from uncommon. However, it's not really asynchronous, but polling. – Apocynaceous