Asynchronous I/O一段介绍异步I/O

Asynchronous I/O means non-blocking I/O. If a process attempts to read or write using the normal, synchronous read() or write() system calls, then it must wait until the hardware has completed the physical I/O, so that it can be informed of the success or failure of the operation (and to receive the results in the case of a successful read). The execution of the process is blocked while it waits for the results of the system call. This is synchronous or blocking I/O.

However, if the process instead uses the asynchronous aio_read() or aio_write() system calls (called aioread() and aiowrite() on some operating systems), then the system call will return immediately once the I/O request has been passed down to the hardware or queued in the operating system, typically before the physical I/O operation has even begun. The execution of the process is not blocked, because it does not need to wait for the results of the system call. Instead, it can continue executing and then receive the results of the I/O operation later, once they are available. This is asynchronous or non-blocking I/O.

Asynchronous I/O enables write intensive processes like Oracle's DBWn to make full use of the I/O bandwidth of the hardware by queuing I/O requests to distinct devices in quick succession so that they can be processed largely in parallel. Asynchronous I/O also allows processes performing compute intensive operations like sorts to pre-fetch data from disk before it is required so that the I/O and computation can occur in parallel.

The performance of asynchronous I/O is heavily dependent on the operating system's implementation of the aio_read() and aio_write() system calls. Kernelized asynchronous I/O is greatly preferable to threaded asynchronous I/O but it is only available for raw devices and Quick I/O files.

 

异步I/O,就是非阻塞I/O。在我们传统的调用write或者read中,我们往往等待系统调用成功后才会从该函数中返回,如果函数一时间没有返回,那么我们的线程将会阻塞在系统调用这个地方。系统调用结束后,我们通过系统调用函数的返回值来查看这次的调用是否成功还是失败。而通过异步i/o,我们的线程在将I/O请求发送到I/O设备后就会立刻返回,接着下面的执行工作。I/O设备在处理完我们的请求后,会通过其他方式告诉我们处理请求的结果。这就是异步i/o的原理。简单而言,就是让I/O操作和我们的线程执行同时执行。

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值