Graphic Analysis and Comparison of five Io models of UNIX

Source: Internet
Author: User
Tags epoll

 

 

Graphic Analysis and Comparison of five Io models of UNIX

(From http://blog.csdn.net/blueboy2000/archive/2009/08/26/4485874.aspx)

 

There are five I/O models in UNIX

Blocking I/O

Non-blocking I/O

I/O multiplexing (select and poll)

Signal-driven I/O (sigio)

Asynchronous I/O (posix.1 AIO _ series functions)


B. Block I/O models
An application calls an I/O function, leading to application blocking and waiting for data preparation.
If the data is not ready, keep waiting ....
The data is ready. copy the data from the kernel to the user space.
Io function return success indicator

 

C. Non-blocking I/O model
When we set a set of interfaces to non-blocking, we will tell the kernel that when the requested I/O operation cannot be completed, do not sleep the process, but return an error. In this way, our I/O operation functions will continuously test whether the data is ready. If not, continue the test until the data is ready. In this continuous testing process, it will take a lot of CPU time.

 

D. I/O Reuse Model
The I/O reuse model uses select or poll functions. These two functions can also block the process, but they are different from those that block I/O, these two functions can block Multiple I/O operations at the same time. In addition, I/O functions of multiple read operations and write operations can be detected at the same time. I/O operation functions can be called only when data is readable or writable.

Currently, JAVA supports only one level of multiplexing. In this mode, listening to connections in a thread in blocking mode does not require too many threads to wait for the connection in blocking mode.

E. Signal-driven I/O model
First, we allow the set of interfaces for signal-driven I/O, and install a signal processing function, the process continues to run without blocking. When the data is ready, the process receives a sigio signal and can call the I/O operation function in the signal processing function to process the data.

F. asynchronous I/O model
Call the aio_read function to tell the kernel description, buffer pointer, buffer size, file offset, and notification method, and then return immediately. When the kernel copies the data to the buffer, it notifies the application.

2. Comparison of several I/O models
The difference between the first four models is that the first stage is basically the same, and the second stage is basically the same. Data is copied from the kernel to the caller's buffer zone. The two phases of asynchronous I/O are different from the first four models.

3. synchronous I/O and asynchronous I/O
A. synchronous I/O operations cause request process blocking until I/O operations are completed.
Asynchronous I/O operations do not cause request process blocking.
B. Our first four models are synchronous I/O, and only the last asynchronous I/O model is asynchronous I/O.

 

Java NiO and multiplexing

Select provided by Java 1.4 NIO, which is a multiplexing I/O (multiplexed non-blocking I/O) model. The underlying layer is select or poll. I/O reuse is to block one of the select or poll system calls, rather than blocking the real I/O system calls. JDK 5.0 Update 9 and JDK 6.0 support epoll in Linux, can improve the performance of concurrent idle connection (http://blogs.sun.com/alanb/entry/epoll ).

Bio refers to the blocking Io mode, that is, the Read and Write must be in synchronous mode. Nio refers to asynchronous reading and synchronous writing, and AIO refers to asynchronous reading and asynchronous writing.
JAVA supports both TCP/IP and UDP/IP over the network protocol. Currently, Java only supports bio and NiO in network Io operations. "

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.