In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
The objects and steps involved in the occurrence of IO:
Object:
For a network IO, two objects are involved, one is the process, the other is the system kernel. When a read occurs, the following steps are taken
Steps:
Data preparation (that is, waiting)
Copy data from the kernel to the application process
The differences of several Icano models are generally different in the above two stages.
Here are five different Imap O models:
Blocking IO
Non-blocking IO
Multiplexing IO
Signal driven IO
Asynchronous IO
Among the IO mentioned above, the first four are synchronous IO and the fifth is asynchronous IO.
1. Blocking IO
In linux, the default socket is blocked
The flow of a typical read operation goes something like this:
When the user process calls the recv/recvfrom system call, it checks whether the kernel receive buffer is ready for data. For network IO, many times the data does not arrive at the beginning, so the process blocks waiting until the kernel buffer data is ready (for UDP to receive a full Datagram), the kernel copies the data to the user buffer, and then the kernel returns the result.
So, the characteristic of blocking IO is that it is block at both stages of IO execution.
two。 Non-blocking IO
In linux, socket can be set to non-blocking by parameter
Similarly, the flow of a typical blocking read operation is as follows:
When calling the recv/recvfrom system call, check whether the kernel has prepared the data. If not, return an error directly, and the waiting data will not be blocked. The user can call recv/recvfrom in a loop. In this way, if the kernel has not prepared the data, the function will always return an error. Until the data is ready, the data will be copied to the user buffer and returned.
Therefore, the user process actually needs to constantly ask whether the kernel data is ready or not.
3. Multiplexing IO
The system provides select function and epoll to implement the multiplexing input / output model. Select/epoll can use a single process to deal with the IO of multiple network interfaces. Its basic principle is that these two functions will constantly poll all the socket it is responsible for, and when any socket receives data, it will return to notify the user. At this time, the user calls recv/recvfrom, and the process of copying data from the kernel to the user's memory is actually blocked all the time. But unlike blocking IO, this method is blocked by select function, while blocking IO is blocked by recv function. In addition, the advantage of select is that it can handle multiple connections at the same time.
4. Signal driven IO
When using signal-driven SIGIO O, when the network socket is readable, the kernel notifies the application process by sending a signal, so the application can start to read the data. This approach is not asynchronous Istroke O, because the actual reading of data into the application process cache is still the responsibility of the application itself.
5. Asynchronous IO
When the user process initiates a read operation, after the kernel receives the read operation, it will return immediately, so it will not block the user process. Then it will wait for the data preparation to be completed, and then copy the data to the user memory. After that, it will send a signal to the user process telling the user process that the read operation is complete.
Consider these two questions:
1. The difference between blocking IO and non-blocking IO:
When blocking IO is called, the process blocks until the data is ready and the copy is complete.
The non-blocking IO will not block the corresponding process, and will return immediately even though the data is not ready.
two。 The difference between synchronous IO and asynchronous IO:
The difference between the two is that synchronous IO will block during the IO operation. The IO operation here is the real IO operation, that is, the recv/recvfrom system call in the non-blocking IO. When the kernel prepares the data, recvfrom will copy the data from the kernel to the user. During this period of time, the process is blocked.
Asynchronous IO is different. When the process initiates the IO operation, it returns directly, leaving the rest of the work to the kernel, until the kernel sends a signal to the user process to tell it that the IO is complete, and the process is not blocked during the whole process.
Non-blocking IO and asynchronous IO:
In non-blocking IO, although the process is not blocked most of the time, it still requires the process to actively check, and when the data is ready, the process needs to actively call recvfrom again to copy the data to the user's memory. Asynchronous IO is completely different. It is like a user process handing over the entire IO operation to someone else (the kernel) to complete, and then the other person sends a signal when he or she is done. During this period, the user process does not need to check the status of the IO operation, nor does it need to actively copy data.
"finish"
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.