设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Boost application performance using asynchronous I/O-ref(6)

发布时间:2021-01-24 16:31 所属栏目:118 来源:网络整理
导读:/ 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_attribu

/ 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?.

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读