Typical IO model under Linux + select multiplexing model (concept)

    **目录**
     1.         阻塞IO
     2.         非阻塞IO
     3.         信号驱动IO
     4.         异步IO  (同步概念)
     5.         select“多路转接”IO(篇幅所限放置下一篇博客中,持续更新哦)

Before we begin to describe, please understand this concept.
Any two behaviors that essentially occur during the IO process are "waiting" and "copying", waiting for data preparation to be completed, and copying from the kernel to user space
can be Imagine that a lot of time wasted in the IO process is waiting to be consumed, so on the contrary, in order to improve the efficiency of IO, the core idea is to find a way to minimize the "waiting time"!

Blocking IO

  • Initiate a functional operation. When data acquisition is required, if the kernel does not prepare the data, it will wait until the data is ready before continuing;
  • All sockets, the default method is blocking
    Typical IO model under Linux + select multiplexing model (concept)Typical IO model under Linux + select multiplexing model (concept)
    non-blocking IO
  • When a functional operation is initiated and data is requested, the kernel indicates that the data has not been prepared, and the executed system call interface will return immediately and report a response error (usually EWOULDBLOCK)
  • Non-blocking IO reduces the waiting time, but it does not make much sense when it returns unsuccessfully. Therefore, the general programmer will repeatedly call the non-blocking interface (the purpose is to repeatedly try to obtain the file descriptor for reading and writing). This is the "polling" method, which is a big waste of cpu utilization;

Typical IO model under Linux + select multiplexing model (concept)

Signal drive IO

  • Signal-driven IO, as the name suggests, introduces a signal processing mode in the IO processing mode
  • Initiate a functional operation, when requesting to obtain data, do not pay attention after sending the request. When the kernel is ready to prepare the data, send a SIGIO signal to notify the process to complete subsequent IO operations
  • Note that what SIGIO monitors here is "the kernel prepares the data or not", not the second behavior of "copying"
    Typical IO model under Linux + select multiplexing model (concept)
    asynchronous IO.
  • Initiate a functional operation, when you need to request data, do not pay attention after sending the request. When the kernel prepares the data + data copy is completed, then notify the process and perform subsequent IO operations
  • What needs attention is the difference between it and signal-driven IO, which is whether the copy of the data occurs before the "notification";

Typical IO model under Linux + select multiplexing model (concept)

Asynchronous/synchronous concept

  • asynchronous:
    • In order to complete a function, issue a call, and return after the call is issued. According to the status of the callee, the caller is notified, and the actual processing result of the call can be processed at this time.
      • Synchronize
      • In order to complete a function, make a call, wait for the called state to be ready, then continue, otherwise wait forever

At this point, I believe everyone is very confused, so is "asynchronous/synchronous" and "blocking/non-blocking" not the same?
Answer: Blocking and non-blocking, mainly emphasizing whether the operation returns immediately;
asynchronous and synchronous, mainly emphasizing the timing of function completion , focusing on the "message communication mechanism".
Here is a classic example to assist in understanding:
asynchronous communication mechanism:
Typical IO model under Linux + select multiplexing model (concept)
asynchronous and synchronous The standard template looks like this:

The so-called synchronization means that when a call is issued , the call does not return until the result is not obtained . But once the call returns, you get the return value. In other words, the caller actively waits for the result of this call .
The induction is the opposite, call after issuing this call directly returned, so no results are returned. In other words, when an asynchronous procedure call is issued, the caller will not get the result immediately. Instead, after the call is issued, the callee informs the caller through status and notification, or handles the call through a callback function.

Blocking and non-blocking:

                  阻塞和非阻塞关注的是程序在等待调用结果(消息,返回值)时的状态.

Typical IO model under Linux + select multiplexing model (concept)

Due to space constraints, the select multiplexed IO model, poll, epollIO model, and the corresponding TCP communication code will be linked
to the next few blogs; everyone will be clear here! Haha, thank you for watching;

Guess you like

Origin blog.51cto.com/14632688/2663786