-
Notifications
You must be signed in to change notification settings - Fork 106
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
feat(filestore): add mmap reader option #665
Conversation
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## main #665 +/- ##
=======================================
Coverage 60.41% 60.42%
=======================================
Files 244 245 +1
Lines 31027 31056 +29
=======================================
+ Hits 18746 18765 +19
- Misses 10615 10620 +5
- Partials 1666 1671 +5
|
791dc5f
to
6e22b09
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Dreamacro!
Triage notes:
- this seems to solve Windows-specific perf. problem, and should not be applied to all platforms.
- please refactor to leverage build flags, see prior art in https://github.com/ipfs/boxo/blob/main/files/filewriter_windows.go
@lidel Yes, mmap was introduced to solve the Windows-specific problem, but |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triage notes:
- overall sounds good, as long it remains opt-in
- we will dogfood this in Kubo, will circle back to this as part of 0.31 activities Release 0.31 kubo#10499
- because mmap impl. is in
golang.org/x/exp
plan is to have it as opt-in flag for now, similar toIPFS_FD_MAX
- small ask to rename func inline
done |
4fc228c
to
44fa940
Compare
@lidel Hi, should I do anything else? |
44fa940
to
06b91df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eyeballed this and it looks good to me. I defer to @lidel for merging.
9038775
to
33fd0c4
Compare
@lidel Hi, Is there anything else I need to do? I have to handle conflicts due to frequent commits from upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for landing this and being patient with us @Dreamacro, lgtm 👍
I've run smoke-test in ipfs/kubo#10613 just to be sure we don't have any regressions in Kubo (it uses filestore and has some tests there).
Motivation
I have a custom IPFS implementation based on boxo, which uses
FileManager
on Windows because I need to store files directly rather than file blocks. The pull logic is roughly as follows:ProtoNode
tree.RawNode
file blocks and write them to the system. Meanwhile, this Windows node also communicates and synchronizes with other nodes.When hundreds of Windows nodes are working simultaneously, I noticed that the system's memory consumption becomes very high, and the memory is immediately released once the file download is complete. Interestingly, the memory consumption is not by the program itself but by the operating system. After some investigation, I found the root cause: Windows caches the read file blocks (even if the *os.File is already closed).
This can be reproduced with the following code:
Solution
Using mmap can solve this problem (implemented with
CreateFileMapping
on Windows). To maintain backward compatibility, aWithMMapReader
option has been added toFileManager
. Enabling this option on Windows can prevent excessive memory consumption.The downside is that it relies on the exp package, but it only changes from an indirect dependency to a direct dependency. Alternatively, the code from this package can be copied directly into the project.