加入收藏 | 设为首页 | 会员中心 | 我要投稿 济源站长网 (https://www.0391zz.cn/)- 数据工具、数据仓库、行业智能、CDN、运营!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Boost application performance using asynchronous I/O-ref

发布时间:2021-01-25 14:25:56 所属栏目:Linux 来源:网络整理
导读:Linux asynchronous I/O is a relatively recent addition to the Linux kernel. It's a standard feature of the 2.6 kernel,but you can find patches for 2.4. The basic idea behind AIO is to allow a process to initiate a number of I/O operations

Finally,the asynchronous non-blocking I/O model is one of overlapping processing with I/O. The read request returns immediately,indicating that the?read?was successfully initiated. The application can then perform other processing while the background read operation completes. When theread?response arrives,a signal or a thread-based callback can be generated to complete the I/O transaction.

Typical Flow of the Asynchronous Non-Blocking I/O Model (AIO)

The ability to overlap computation and I/O processing in a single process for potentially multiple I/O requests exploits the gap between processing speed and I/O speed. While one or more slow I/O requests are pending,the CPU can perform other tasks or,more commonly,operate on already completed I/Os while other I/Os are initiated.

The next section examines this model further,explores the API,and then demonstrates a number of the commands.

From the previous taxonomy of I/O models,you can see the motivation for AIO. The blocking models require the initiating application to block when the I/O has started. This means that it isn't possible to overlap processing and I/O at the same time. The synchronous non-blocking model allows overlap of processing and I/O,but it requires that the application check the status of the I/O on a recurring basis. This leaves asynchronous non-blocking I/O,which permits overlap of processing and I/O,including notification of I/O completion.

The functionality provided by the?select?function (asynchronous blocking I/O) is similar to AIO,except that it still blocks. However,it blocks on notifications instead of the I/O call.

This section explores the asynchronous I/O model for Linux to help you understand how to apply it in your applications.

In a traditional I/O model,there is an I/O channel that is identified by a unique handle. In UNIX?,these are file descriptors (which are the same for files,pipes,sockets,and so on). In blocking I/O,you initiate a transfer and the system call returns when it's complete or an error has occurred.

AIO first entered the Linux kernel in 2.5 and is now a standard feature of 2.6 production kernels.

In asynchronous non-blocking I/O,you have the ability to initiate multiple transfers at the same time. This requires a unique context for each transfer so you can identify it when it completes. In AIO,this is an?aiocb?(AIO I/O Control Block) structure. This structure contains all of the information about a transfer,including a user buffer for data. When notification for an I/O occurs (called a completion),the?aiocb?structure is provided to uniquely identify the completed I/O. The API demonstration shows how to do this.

The AIO interface API is quite simple,but it provides the necessary functions for data transfer with a couple of different notification models. Table 1 shows the AIO interface functions,which are further explained later in this section.

API function aio_readaio_erroraio_returnaio_writeaio_suspendaio_cancellio_listio (编辑:济源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

Description