osio上的aio:它是在内核中实现还是在用户线程中实现?其他选择? [英] aio on osx: Is it implemented in the kernel or with user threads? Other Options?

查看:233
本文介绍了osio上的aio:它是在内核中实现还是在用户线程中实现?其他选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究我的小型c ++框架,并且有一个文件类,它也应该支持异步读写。除了在我发现的一些工作线程中使用同步文件i / o之外,唯一的解决方案是aio。无论如何我在四处寻找并在某处阅读,在Linux中,aio甚至没有在内核中实现,而是在用户线程中实现。 OSX也是如此吗?另一个问题是aio的回调函数,它必须为每个回调生成一个额外的线程,因为你不能指定某个线程或线程池来处理它(信号不是我的选项)。以下是由此产生的问题:

I am working on my small c++ framework and have a file class which should also support async reading and writing. The only solution other than using synchronous file i/o inside some worker threads I found is aio. Anyways I was looking around and read somewhere, that in Linux, aio is not even implemented in the kernel but rather with user threads. Is the same true for OSX? Another concern is aio's functionality of callbacks which has to spawn an extra thread for each callback since you can't assign a certain thread or threadpool to take care of that (signals are not an option for me). So here are the questions resulting from that:


  • 是否在osx的内核中实现了aio,因此很可能比我的更好自己的线程实现?

  • Is aio implemented in the Kernel of osx and thus is most likely better than my own threaded implementation?

回调系统 - 为每个回调设置一个线程 - 是否会成为实践中的瓶颈?

Can the callback system -spawning a thread for each callback- become a bottleneck in practice?

如果aio不值得在osx上使用,unix上还有其他选择吗?在可可?在碳?

If aio is not worth using on osx, are there any other alternatives on unix? in cocoa? in carbon?

或者我应该使用自己的线程池模拟异步i / o?

Or should I simply emulate async i/o with my own threadpool?

您对此主题的体验是什么?

What is your experience on the subject?

推荐答案

您可以看到具体方法AIO是在OSX上实现的 here

You can see exactly how AIO is implemented on OSX right here.

实现使用内核线程,每个线程弹出一个作业队列,并根据每个请求的优先级以优先级队列的阻塞方式执行(at至少这是乍一看的样子。)

The implementation uses kernel threads, one queue of jobs which each thread pops and execute in a blocking fashion in a priority queue based on each request's priority (at least that's what it looks like at a first glance).

您可以使用 sysctl 配置线程数和队列大小

You can configure the number of threads and the size of the queue with sysctl. To see these options and the default values, run sysctl -a | grep aio

kern.aiomax = 90
kern.aioprocmax = 16
kern.aiothreads = 4

根据我的经验,为了让它有意义使用AIO ,这些限制需要更高。

In my experience, in order for it to make any sense to use AIO, these limits need to be a lot higher.

至于线程中的回调,我不相信Mac OS X支持这一点。它只通过信号完成通知(参见来源)。

As for the callbacks in threads, I don't believe Mac OS X supports that. It only does completion notifications through signals (see source).

你可以在你自己的线程池中做好工作。你可以做的比目前的darwin实现更好的一件事是按照磁盘上的物理位置对你的读取作业进行排序(参见 fcntl F_LOG2PHYS )甚至可能给你带来优势。

You could probably do as good of a job in your own thread pool. One thing you could do better than the current darwin implementation is to sort your read jobs by physical location on the disk (see fcntl and F_LOG2PHYS) which might even give you an edge.

这篇关于osio上的aio:它是在内核中实现还是在用户线程中实现?其他选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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