Computer Network | Introduction to I/O Model

Insert image description here

Welcome to follow the bloggerMindtechnist or join [Intelligent Technology Community】Learn and share together Linux, C, C++, Python, Matlab, robot motion control, multi-robot collaboration, intelligent optimization algorithms, Bayesian filtering and Kalman estimation, multi-sensor information fusion, machine learning, artificial intelligence, control theory knowledge and technology in related fields. Follow the official account "Machines and Intelligence" Reply with the keyword "python project practice" to get the video resources of Miduo Mall!


Blogger introduction:
CSDN quality creator, CSDN rising star, CSDN content partner;
Alibaba Cloud community expert blogger; a> 51CTO community bloggers, Nuggets community bloggers, Alipay community bloggers, Blog Park bloggers.
Huawei cloud community cloud sharing expert;


"Explaining data types in MATLAB through cases"


Column:"Intelligent Optimization Algorithm"


Insert image description here

blocking I/O

Insert image description here

①When the upper-layer application app1 calls therecv system call, if the peer does not send data (there is no data in the buffer), the upper-layer application app1 will block (default behavior, by the Linux kernel Blocking);
②When the peer sends data, the linux kernelrecv side buffer has data, and the kernel will send the datacopyGive user space. Then the upper-layer application app1 is unblocked and performs the next step.

Non-blocking I/O

Insert image description here

①The upper-layer application app2 sets the socket to non-blocking mode.
②The upper-layer application app2 polls and calls the recv function to receive data. If there is no data in the buffer, the upper-layer program app2 will not block, the return value is -1, and the error code is . ③The upper-layer application continuously polls whether data has arrived. This will cause the upper-layer application to be busy waiting. Consumes a lot of CPU. Rarely used directly. The application range is small and is generally used in conjunction with selectIO multiplexing. recvEWOULDBLOCK

I/O multiplexing

Insert image description here

①The upper-layer application app3 calls theselect mechanism (this mechanism is supported by the Linux kernel and avoids app3 busy waiting.) to poll the status changes of the file descriptor.
②When the file descriptor managed by select has no data (or the status has not changed), the upper-layer application app3 will also block.
③BenefitsselectThe mechanism can manage multiple file descriptors
selectCan be regarded as A manager uses select to manage multiple IOs.
Once an I/O or multiple IOs are detected, and an event of interest to us occurs, the select function will return, and the return value is the detected event. number. Then you can use select related api functions to operate specific events.
⑤The select function can set the waiting time, which avoids the long-term freeze of the upper application app3.
⑥Compared with the blocking IO model, the selectI/O multiplexing model is equivalent to blocking in advance. When data arrives, callingrecv again will not cause blocking. The entire system (the app and the Linux kernel protocol stack cooperate better) can be optimized and provided.

Signal movement I/O

Insert image description here

① The upper-layer application app4 creates a signal handlerSIGIO. When data arrives in the buffer, the kernel will send a signal to tell the upper application app4.
②After receiving the signal, the upper-layer application app4 calls the recv function. Because there is data in the buffer, the recv function generally does not block.
③ This type is rarely used in models and is a typical "pull mode". That is: the upper-layer application app4 needs to call the recv function to pull in the data.

Bicycle I/O

Insert image description here

①The upper-layer application app5 calls theaio_read function and submits an application layer buffer buf; after the call is completed, it will not block. The upper application app5 can continue other tasks.
②When there is data in the tcpip protocol buffer, Linux actively transfers the kernel data copy to user space. Then send a signal to the upper application app5; tell app5 that the data is available and process it quickly.
③Typical “push mode”.
④ The most efficient form, the upper-layer application app5 has the ability to process asynchronously (with the support of the Linux kernel, the implication is: it can also support IO communication while processing other tasks).

...

Insert image description here


❗❗❗Important❗❗❗☞Follow the official account below"Machines and Intelligence" Reply to the keyword "python project actual combat" that is Video resources from Miduo Mall are available!

Guess you like

Origin blog.csdn.net/qq_43471489/article/details/134890959