Linux Asynch IO-aio.h和libaio.h之间的区别 [英] Linux Asynch IO - difference between aio.h and libaio.h

查看:329
本文介绍了Linux Asynch IO-aio.h和libaio.h之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始研究一种新的范式,在Linux中我不知道它称为异步IO.

I have started looking at a new paradigm I didn't know called asynch IO in Linux.

我的目标是使用异步IO定位套接字编写高性能,高效的服务器.原因是我的应用程序受IO限制.

My goal is to use async IO targeting sockets to write high-performance efficient servers. The reason is that my application is IO-bound.

在寻找更多信息时,我遇到了以下2个介绍.

While searching for more information I came across the following 2 introductions.

  1. Posix AIO

Linux AIO界面

在异步框架中,我要避免的情况是为需要异步处理的每个通知创建一个新线程,因为它将杀死我的应用程序.

In a asynchronous framework, the situation I would like to avoid is to create a new thread for each notification I need to process asynchronously since it will kill my application.

我的问题如下:

  1. 这两个框架的幕后是否解决了这个问题?

  1. Do the behind-the-scenes of these 2 frameworks address this problem?

如果是,您建议考虑使用套接字吗?

If yes what would you suggest having in mind socket?

致谢

AFG

推荐答案

这些都不是真正用于套接字的.

None of these are really intended for sockets.

POSIX AIO接口创建使用普通阻塞IO的线程.它们与缓冲区缓存一起使用,并且应该原则上甚至可以与套接字一起使用(尽管我公认没有尝试过).

The POSIX AIO interface creates threads that use normal blocking IO. They work with the buffer cache and should in principle even work with sockets (though I've admittedly not tried).

Linux内核AIO接口不会创建线程来处理请求.它在无缓冲"模式下排他性地工作.提防一些非显而易见的行为,例如在某些情况下提交请求时被阻止,这是您无法预见或阻止的(除了知道您的程序表现出怪异"之外,您也不知道).

The Linux kernel AIO interface does not create threads to handle requests. It works exclusively in "no buffering" mode. Beware of non-obvious behaviour such as blocking when submitting requests in some situations, which you can neither foresee nor prevent (nor know about other than your program acting "weird").

您想要的是非阻塞套接字(一个非阻塞套接字是某种异步")和epoll,以将就绪通知的开销降至最低,并且-如果您能找出几乎不存在的文档, -splicevmsplice以减少IO开销.使用splice/vmsplice,您可以直接将DMA从磁盘直接传输到内核缓冲区,然后从那里推送到网络堆栈.或者,您可以将页面从应用程序的地址空间直接移动到内核,然后推送到网络.
不利之处是文档稀疏(至少可以说),特别是对于TCP,某些问题仍然没有解决,例如什么时候可以安全地回收内存.

What you want is nonblocking sockets (a nonblocking socket is "kind of asynchronous") and epoll to reduce the overhead of readiness notification to a minimum, and -- if you can figure out the almost non-existing documentation -- splice and vmsplice to reduce the IO overhead. Using splice/vmsplice you can directly DMA from disk to a kernel buffer and push to the network stack from there. Or, you can directly move pages from your application's address space to kernel, and push to the network.
The downside is that the documentation is sparse (to say the least) and especially with TCP, some questions remain unaddressed, e.g. when it is safe to reclaim memory.

这篇关于Linux Asynch IO-aio.h和libaio.h之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆