In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The main content of this article is to explain "five kinds of I-stroke O models in PHP7 and the explanation of synchronous, asynchronous, blocking and non-blocking". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the "five Icano models in PHP7 and the instructions for synchronization, async, blocking and non-blocking".
1. Synchronization: my client (C-side caller) a function that does not end before I die waiting for the result.
two。 Async: I (the caller on the c side) invokes a function and does not know the result of the function. When the function has a result, let me know, that is, callback notification.
3. Blocking: just call me (s-side callee, function), I (s-side callee, function) will not return until I have fully accepted the data or got the result.
4. Non-blocking: just call me (s-side callee, function), I (s-side callee, function) return immediately, and notify the caller when the result is obtained.
Five Icano models
(1) blocking I-Blocking O (blocking I-I-O)
When the user process makes a system call, the kernel begins the first stage of block O, preparing the data into the buffer, and copying the data from the kernel buffer to the memory of the user process when the data is ready.
(2) non-blocking I-Non-Blocking O (non-blocking I-G O)
The user process is blocked only in the second stage, but not in the first stage, but in the first stage, the user process does not need to be blind and so on, and keeps polling the kernel to see if the data is ready, so the model consumes more CPU.
(3) I Multiplexing O multiplexing.
Both phases of the execution of Ipicuro are blocked by the user process, but the two phases are independent, and the user process initiates two system calls in a complete IWeiO operation. Unlike blocking Icano, the first paragraph can wait for multiple descriptors to be ready.
(4) signal-driven Signal Driven O (signal driven iGUP O)
The user process is blocked only in the second phase of the execution of Icano, while there is no blocking in the first phase. When the data is ready, the model actively notifies the user that the process data is ready, that is, to make a callback to the user process. The notification is divided into two types, one is horizontal trigger, that is, if the user process does not respond, it will always send notification, and the other is edge trigger, that is, notification only once.
(5) Asynchronous I-Asynchrnous O (Asynchronous I-O)
When the user process initiates the system call, it can immediately start to do something else, and then until the two phases of the execution of Imax O are completed, the kernel will send a notification to the user process that the operation has been completed.
Ipaw O multiplexing technology
Select
(1). The mechanism of select () provides a data structure of FD _ set. Each element can establish a connection with an open file handle (whether Socket handle, or other file or named pipe or device handle). The work of establishing the connection is done by the programmer. When select () is called, the kernel modifies the contents of the fd_set according to the IO state. This informs the process that executed select () which Socket or file is readable or writable. It is mainly used in Socket communication.
(2)。 After the program executes select, if there is no data input, the program will wait (when blocking) until there is data, that is, there is no loop and sleep in the program.
(3)。 Every time you call select, you need to copy the fd_set collection from the user state to the kernel state, which is very expensive in many cases of fd_set.
(4)。 At the same time, each call to select requires the kernel to traverse all the fd_set passed in, which is also very expensive in many cases of fd_set.
(5) the number of file descriptors supported by .select is too small. The default is 1024.
Poll
(1) the implementation of .poll is very similar to select, except that the fd_set collection is described in a different way. Poll uses the pollfd linked list structure instead of select's fd_set structure, and the others are similar.
(2)。 There is no upper limit on the number of monitoring descriptors
Epoll/kqueue
(1)。 There is no upper limit on the number of monitoring descriptors
(2)。 Efficiency improvement is not a way of polling and will not decrease with the increase of the number of fd. Only fd that is active will call the callback function; that is, the biggest advantage of epoll/kqueue is that it only cares about your "active" connections, not the total number of connections, so in the actual network environment, epoll/kqueue will be much more efficient than select and poll.
(3)。 Memory copy, using mmap () file mapping memory to accelerate message delivery with kernel space
At this point, I believe that you have a better understanding of the "five PHP7 I / O models and instructions for synchronization, async, blocking, and non-blocking". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.