-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[WIP] Remove mmap usage in SPVBlockStore #1695
Conversation
Thanks for the effort! Do you have an idea if that change might affect performance? |
Ah, and the format is stays the same, right? |
@@ -142,6 +144,33 @@ public static StoredBlock deserializeCompact(NetworkParameters params, ByteBuffe | |||
return new StoredBlock(params.getDefaultSerializer().makeBlock(header), chainWork, height); | |||
} | |||
|
|||
/** Serializes the stored block to a custom packed format. Used by {@link org.bitcoinj.store.SPVBlockStore}. */ |
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.
I think it's a bit unfortunate that these two methods duplicate the above two methods. In theory, we could implement the new methods like this:
FileChannel channel = randomAccessFile.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(CHAIN_WORK_BYTES);
deserializeCompact(params, buffer);
Of course I don't know about the performance implications and wether we run into specific problems in Windows again. Have you considered this?
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.
I added a commit with your suggestion "Avoid duplicating StoredBlock's serializeCompact() and deserializeCompact".
I will squash once we finish the discussion and testing.
I don't think this deduplication commit brings up the windows problem again, since the windows problem is just with mmaped files not with the uses of Buffers or FileChannels.
About performance, this deduplication commit does not improve/deteriorate performance. I will address your performance question in a broader PR comment.
@schildbach About performance: Since this will require lots of test and might be controversial, I think it would be better as a first step to make the change optional/just for windows. A couple of options:
|
For Android, Mike had this to say about mmap: "on Android each get() call is actually a full-blown JNI method under the hood, meaning it's unbelievably slow". So from my Android perspective, I'd probably be ok to just change the implementation to RandomAccessFile and be done with it. On Windows, RandomAccessFile seems to be the only available option anyway. So only Linux and MacOS are left to decide. Yes, testing needs to be done. But we're entering a stabilization phase anyway. |
@schildbach What would be the next step with this PR? About unit tests: they pass on my computer. Travis unit tests execution fails but I can't find out why. |
I'd prefer to keep only one implementation: either mmap or RandomAccessFile. I'm not afraid about testing, as we're about to enter the stabilization phase for 0.15. I leave it up to you wether you think we should try it for 0.15. |
A similar bugfix is being tested on the Bisq project bisq-network/bisq#2403 . Let's see what happens there before merging the PR. |
If you rebase this to current master, it should be picked up by the new performance test. |
I did some basic runtime tests with the Bisq app and it seems the performacne degradation at initial download is acceptable. I still would prefer to only apply it for Windows not for all OS. See bisq-network/bisq#2403 (comment) |
Ok, then I suggest a more straightforward name… SPVRandomAccessFileBlockStore? |
aa36656
to
6f5b897
Compare
I rebased from master. I ran SPVBlockStoreTest.performanceTest() on a mac This is around 10x performance loss on writing. I will think more about this and post another comment. |
3bdbe85
to
55bfbf1
Compare
55bfbf1
to
c1655cd
Compare
So...
On a side note... |
a697561
to
81ddd50
Compare
I close this PR and suggest to merge #1702 instead. |
There has been a "TODO" for years to remove mmap usage in SPVBlockStore.
I replaced it by direct usage of RandomAccessFile
I am motivated to implement this because I found #1477 fix does not work on windows.