Five basic IO model

Input / Output Process IO IO ready and waiting for the event to copy data Characteristics, advantages and disadvantages
Blocking IO The kernel before the data is ready, the system call will wait. All sockets, the default is blocking the way.
Non-blocking IO If the kernel is not yet the data is ready, the system call will return an error directly. Programmers need to repeat determination IO event is ready, on the CPU consumption is relatively serious.
IO drive signal Core data are ready, use SIGIO signal notifies the application program IO operations. Operating system IO operations signaled application
Asynchronous IO The completion of the data copying in the kernel notifies the application. The data copying is done by the system, no waiting time.

1. blocking I / O model
talk of the town to the train station to buy tickets, line up three days to buy a refund.
Cost: stop eating and drinking Lazard sleep in three days, one did not do other things.

2. Non-blocking I / O model
talk of the town to the train station to buy a ticket, every 12 hours to the train station asked whether or not a refund, three days later to buy a ticket.
Cost: round-trip station six times, six hours on the road, a lot of time to do other things.

3.I / O multiplexing model
1.select/poll
talk of the town to the train station to buy a ticket, commissioned by cattle, then every 6-hour telephone inquiry cattle, cattle to buy tickets within three days, and then talk of the town to the train station to pay for tickets .
Cost: round-trip station 2, on the road two hours, cattle fee $ 100, call 17 times
2.epoll
talk of the town to the train station to buy a ticket, commissioned by cattle, cattle buy talk of the town after notification to pick up, then go talk of the town Station pay to get tickets.
Cost: round-trip station 2, on the road two hours, cattle fee $ 100, without having to call

4. The signal driven I / O model
talk of the town to the train station to buy a ticket, the conductor to leave your phone, after the vote, conductor hear his phone call, then talk of the town to the train station to pay for tickets.
Cost: round-trip station 2, on the road two hours, costs 100 yuan cattle-free, without having to call

5. asynchronous I / O model
talk of the town to the train station to buy a ticket, the conductor to leave your phone, after the vote, conductor hear his phone call and express home delivery.
Cost: 1 and from the station, on the road for one hour costs 100 yuan cattle-free, no phone calls

If an I / O stream in, we will start a process to handle the I / O stream. Now, I assume there are now one million I / O stream in, then we need to turn one million one correspondence process to deal with these I / O stream (which is in the traditional sense of the multi-process concurrent processing ). Think about one million process, your CPU usage will be high, the implementation is extremely unreasonable. Therefore, there has been proposed I / O multiplexing model, a thread, by recording the status of I / O stream to manage a plurality of I / O, can increase throughput capacity of the server.

Guess you like

Origin blog.csdn.net/Vickers_xiaowei/article/details/92828855