What is the fastest way to write serial data to disk in Mac OS X?

I need a way to store large blocks of data (~ 1-2 MB) with high speed (~ 200-300 Mbit / s).
After some research, I found several options:

  • aio_write
  • DIRECT_IO
  • Carbon File Manager PBWriteForkAsync()
  • default fwrite() wrapped in a block and sent via GCD
  • NSData appendData in NSOperation
  • ...

This wiki page describes the state of aio_write under Linux. What I did not find was a similar aio_write status aio_write for Mac OS X.

NSOperation or Blocks + GCD seems to be a method of achieving 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?
I am currently leaning towards PBWriteForkAsync , as it requires some tuning parameters. It must also be 64-bit.

+6
source share
2 answers

I don’t know MacOS very well, but I also tried open and write syscalls from unistd.h with the non-blocking option O_NONBLOCK . reference

+2
source

You must use unbuffered I / O for writing, in Carbon it is FSWriteFork() with kFSNoCacheBit , in BSD use fcntl() with F_NOCACHE .

Instead of using a system non-blocking IO, you might need to consider a workflow to write blocks sequentially using a queue. This will give you more control and may be easier, especially if you want to keep track of the queue to make sure that you support it or not.

See here for more details.

+1
source

Source: https://habr.com/ru/post/890702/


All Articles