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
Comments
@michaeleisel Thanks! |
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. |
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? |
As in, #1001 reverted alongside the addition of mmap |
Hi, @michaeleisel , do you have more detailed mmap solution? |
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 Not sure that is the right thing to do when writing in a log file: |
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 |
But appending data to a mapped file will force you to unmap/resize/remap the file which incurs a performance penalty. |
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. |
New Issue Checklist
Issue Info
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.The text was updated successfully, but these errors were encountered: