在 Mac OS X 下将顺序数据写入磁盘的最快方法是什么?
我需要一种以高速率(~200-300Mbit/s)存储大数据块(~1-2MB)的方法。
经过一番研究,我发现了几个选项:
aio_write
- Direct_IO
- Carbon 文件管理器的
PBWriteForkAsync()
- 默认
fwrite()
,包装在一个块中并通过 GCD 调度 - NSOperation 中的 NSData 的
appendData
- ...
此 wiki 页面 描述Linux下aio_write
的状态。我没有找到关于 Mac OS X 的 aio_write
状态的类似页面。
NSOperation 或 Blocks+GCD 似乎是实现非阻塞 IO 的技术。它被用在几个开源IO库中(例如https://github.com/mikeash/MAAsyncIO)
有人有类似的问题找到合适的解决方案了吗?
目前我倾向于使用 PBWriteForkAsync,因为它需要一些“调整”参数。它还应该是 64 位安全的。
I need a way to store large data chunks(~1-2MB) at a high rate (~200-300Mbit/s).
After some research I found several options:
aio_write
- Direct_IO
- Carbon File Manager's
PBWriteForkAsync()
- default
fwrite()
, wrapped in a block and dispatched via GCD - NSData's
appendData
in an NSOperation - ...
This wiki page describes the state of aio_write
under Linux. What I didn't find was a similar page about the state of aio_write
for Mac OS X.
NSOperation or Blocks+GCD seems to be a technique to achieve non-blocking IO. It is used in several open source IO libraries (e.g. https://github.com/mikeash/MAAsyncIO)
Has someone with a similar problem found a suitable solution?
Currently I tend towards PBWriteForkAsync
as it takes some 'tuning'parameters. It also should be 64-bit safe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太了解 MacOS,但我也会尝试使用非阻塞选项从
unistd.h
进行open
和write
系统调用O_NONBLOCK
。 参考I don't know MacOS very well, but I'd also try
open
andwrite
syscalls fromunistd.h
with the non-blocking optionO_NONBLOCK
. reference您应该使用无缓冲 I/O 进行写入,在 Carbon 中这是
FSWriteFork()
和kFSNoCacheBit
,在 BSD 中使用fcntl()
和 <代码>F_NOCACHE。您可能需要考虑使用工作线程使用队列按顺序写入块,而不是使用系统的非阻塞 IO。这将为您提供更多控制权,并且最终可能会更简单,特别是如果您想监视队列以查看是否跟上。
请参阅此处了解更多信息。
You should use unbuffered I/O for the writes, in Carbon this is
FSWriteFork()
withkFSNoCacheBit
, in BSD usefcntl()
withF_NOCACHE
.Rather than use the system's non-blocking IO, you may want to consider a worker thread to write the blocks sequentially using a queue. This will give you more control and may end up being simpler, particularly if you want to monitor the queue to see if you are keeping up or not.
See here for more information.