加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Boost application performance using asynchronous I/O-ref

发布时间:2021-01-25 16:43:12 所属栏目:Linux 来源:网络整理
导读:副标题#e# 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

/ Link the AIO request with a thread callback /
my_aiocb.aio_sigevent.sigev_notify = SIGEV_THREAD;
my_aiocb.aio_sigevent.notify_function = aio_completion_handler;
my_aiocb.aio_sigevent.notify_attributes = NULL;
my_aiocb.aio_sigevent.sigev_value.sival_ptr = &my_aiocb;

...

ret = aio_read( &my_aiocb );

}

void aio_completion_handler( sigval_t sigval )
{
struct aiocb *req;

req = (struct aiocb *)sigval.sival_ptr;

/ Did the request complete? /
if (aio_error( req ) == 0) {

/* Request completed successfully,get the return status */
ret = <strong>aio_return</strong>( req );

}

return;
}

In Listing 6,after creating your?aiocb?request,you request a thread callback using?SIGEV_THREAD?for the notification method. You then specify the particular notification handler and load the context to be passed to the handler (in this case,a reference to the?aiocb?request itself). In the handler,you simply cast the incoming?sigval?pointer and use the AIO functions to validate the completion of the request.

The proc file system contains two virtual files that can be tuned for asynchronous I/O performance:

    The /proc/sys/fs/aio-nr file provides the current number of system-wide asynchronous I/O requests.
  • The /proc/sys/fs/aio-max-nr file is the maximum number of allowable concurrent requests. The maximum is commonly 64KB,which is adequate for most applications.

Using asynchronous I/O can help you build faster and more efficient I/O applications. If your application can overlap processing and I/O,then AIO can help you build an application that more efficiently uses the CPU resources available to you. While this I/O model differs from the traditional blocking patterns found in most Linux applications,the asynchronous notification model is conceptually simple and can simplify your design.

    The??explains the internal details of AIO from the GNU Library perspective.
  • ?explains more about AIO and a number of real-time extensions,from scheduling and POSIX I/O to POSIX threads and high resolution timers (HRT).
  • In the??for the 2.5 integration,learn about the design and implementation of AIO in Linux.
  • In the?,find more resources for Linux developers.
  • Stay current with?.

    With?,available for download directly from developerWorks,build your next development project on Linux.

    Check out??and get involved in the?.

(编辑:PHP编程网 - 黄冈站长网)

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

热点阅读