Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mmap for better file writing performance #999

Open
3 tasks done
michaeleisel opened this issue Dec 12, 2018 · 11 comments
Open
3 tasks done

Use mmap for better file writing performance #999

michaeleisel opened this issue Dec 12, 2018 · 11 comments

Comments

@michaeleisel
Copy link

michaeleisel commented Dec 12, 2018

New Issue Checklist

Issue Info

Info Value
Platform Name e.g. ios

Issue Description and Steps

I find that calls to -[NSFileHandle writeData:] are one of the biggest bottlenecks for the logger. This makes sense, as it is generally a costly function. It would be great if the logger used a memory-mapped file to do writes. It would have the same durability AFAIK and the performance would be much, much better.

@lolgear
Copy link
Contributor

lolgear commented Mar 28, 2019

@michaeleisel
Could you try latest release?

Thanks!

@michaeleisel
Copy link
Author

If you're referring to #1001, a buffer may solve it for some, but it creates a trade-off between efficiency and durability. mmap does not. Although I do see a lot of other bottlenecks as well upon further review, so perhaps there is lower hanging fruit to pick.

@michaeleisel
Copy link
Author

To be honest, I wonder if #1001 should just be reverted. It is more complicated, both for the consumers as well as library developers, and less durable, than mmap. What is the performance data backing the change? Has it been compared to mmap?

@michaeleisel
Copy link
Author

As in, #1001 reverted alongside the addition of mmap

@shayanbo
Copy link

Hi, @michaeleisel , do you have more detailed mmap solution?

@michaeleisel
Copy link
Author

The top answer of this question shows how to both and read and write using mmap (although we only need to write). Once you’ve set everything up, you can use the mmap’d pointer just like any C pointer, like how they pass it to memset to write to it. But, also be sure to verify that the file writing code (without using any intermediate memory buffers) is a bottleneck in the current implementation. There may be even larger bottlenecks that are simpler to solve, but I wanted to call attention to this one since work was being put into it anyways.

@michaeleisel
Copy link
Author

@jcbertin
Copy link
Contributor

@michaeleisel Not sure that is the right thing to do when writing in a log file:
https://stackoverflow.com/questions/35891525/mmap-for-writing-sequential-log-file-for-speed

@michaeleisel
Copy link
Author

Using a memory buffer incurs both the complexity of implementing the buffer as well as the fragility of only persisting data in memory. IMO it’s a next step after mmap

@jcbertin
Copy link
Contributor

But appending data to a mapped file will force you to unmap/resize/remap the file which incurs a performance penalty.

@michaeleisel
Copy link
Author

CocoaLumberjack uses fixed-size files, correct? So you can "pre-allocate" by making the file as large as it would potentially grow to, e.g. by seeking to the end and writing a single byte.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants