Disadvantages of blocking I/O vs. non-blocking busy polling I/O
Blocking I/O: A thread can only handle I/O events for one stream. If you want to process multiple streams at the same time, either multiprocessing (fork) or multithreading (pthread_create).
Non-blocking busy polling I/O: All streams are polled in a loop, the CPU is idling when there is no I/O.
The shortcomings of the above two methods are obvious. Blocking I/O for a thread (or process) to process a stream is not suitable for high concurrency and a large number of long connection scenarios. The main problem of non-blocking busy polling I/O requires actively polling the status of the stream. The CPU is idling when there is no I/O.
A new way to understand non-blocking I/O and epoll
Non-blocking I/O can be understood as the introduction of an agent (select, poll, epoll, etc.) , which is relatively powerful and can observe I/O events of many streams at the same time. When idle, the current thread will be blocked. When one or more streams have I/O events, they wake up from the blocking state, and the program polls all streams for corresponding I/O.
Two things are important:
1. The essence of non-blocking I/O is to add a stream to the kernel monitoring list. When the stream in the monitoring list has an I/O operation, it will actively push a message to the application to let the application know which stream occurs. What kind of I/O event.
2. One of the better things about epoll than select is that when an I/O event occurs, select returns all monitored streams, and the application needs O(n) to poll all streams indiscriminately. In epoll mode, the kernel will only return streams with I/O events and indicate what I/O events have occurred.
One additional point: In blocking mode, the kernel's processing of I/O events is blocking or waking up, while in non-blocking mode, I/O events are handed over (proxied to) other objects (select, epoll, etc.) for processing or even ignored directly.
Reference link
Network programming basics - learning blocking, non-blocking (select and epoll)
http://www.cnblogs.com/Simon-xm/p/4093347.html
IO - synchronous, asynchronous, blocking, non-blocking
http://blog.csdn.net/historyasamirror/article/details/5778378