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

fix(store): Fix refcount logic slowness #3123

Merged
merged 17 commits into from
Aug 12, 2020
Merged

fix(store): Fix refcount logic slowness #3123

merged 17 commits into from
Aug 12, 2020

Conversation

mikhailOK
Copy link
Contributor

Use rocksdb merge operator for ColState. No longer need to atomically
read + write on update.

Fixes #3065

Test plan

sanity test
manually check performance

Use rocksdb merge operator for ColState. No longer need to atomically
read + write on update.

Fixes #3065

Test plan
---------
sanity test
manually check performance
@gitpod-io
Copy link

gitpod-io bot commented Aug 10, 2020

Copy link
Collaborator

@bowenwang1996 bowenwang1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much performance improvement do we get from this change?

core/store/src/db.rs Show resolved Hide resolved
core/store/src/db.rs Show resolved Hide resolved
core/store/src/db.rs Outdated Show resolved Hide resolved
core/store/src/db.rs Outdated Show resolved Hide resolved
cursor.into_inner()
}

fn decode_trie_node_with_rc(bytes: &[u8]) -> Result<(&[u8], u32), StorageError> {
fn decode_trie_node_with_rc(bytes: &[u8]) -> Result<(&[u8], i32), StorageError> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it i32 now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update writes encoded positive or negative refcount delta, and merge adds up updates. Records/partial sum can be negative, but the result from db.get() should always be positive (if it is <= 0, there is a bug in gc). Probably need to add a new assert, this change deleted the one from apply_deletions.

mikhailOK and others added 2 commits August 10, 2020 16:03
Co-authored-by: Bowen Wang <bowenwang1996@users.noreply.github.com>
Co-authored-by: Bowen Wang <bowenwang1996@users.noreply.github.com>
@mikhailOK
Copy link
Contributor Author

In #3065 the bottleneck was calling db.get() 2.5 million times when we apply genesis, which was slow when we did it for the second time. Now this is just a batch write which is instant. Merging happens on get() and compaction, didn't measure but should be fast.

Copy link
Collaborator

@evgenykuzyakov evgenykuzyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it improve Runtime performance, e.g. trie finalization?

@mikhailOK
Copy link
Contributor Author

Applying a block should become faster

@codecov
Copy link

codecov bot commented Aug 11, 2020

Codecov Report

Merging #3123 into master will increase coverage by 0.00%.
The diff coverage is 88.97%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3123   +/-   ##
=======================================
  Coverage   87.25%   87.26%           
=======================================
  Files         212      212           
  Lines       41424    41515   +91     
=======================================
+ Hits        36145    36226   +81     
- Misses       5279     5289   +10     
Impacted Files Coverage Δ
core/primitives/src/version.rs 100.00% <ø> (ø)
neard/src/lib.rs 65.04% <0.00%> (-2.63%) ⬇️
core/store/src/lib.rs 84.10% <66.66%> (-0.62%) ⬇️
core/store/src/db.rs 86.71% <91.56%> (+1.71%) ⬆️
core/store/src/trie/trie_storage.rs 94.69% <96.55%> (-0.51%) ⬇️
core/store/src/trie/mod.rs 87.92% <100.00%> (ø)
core/store/src/trie/shard_tries.rs 79.24% <100.00%> (-3.39%) ⬇️
chain/client/src/info.rs 68.99% <0.00%> (-3.11%) ⬇️
chain/network/src/test_utils.rs 90.32% <0.00%> (-1.62%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dcf6258...7e13356. Read the comment docs.

core/store/src/db.rs Outdated Show resolved Hide resolved
core/store/src/db.rs Outdated Show resolved Hide resolved
core/store/src/db.rs Outdated Show resolved Hide resolved
core/store/src/db.rs Outdated Show resolved Hide resolved
@@ -395,21 +396,21 @@ impl RawTrieNodeWithSize {
}
}

fn encode_trie_node_with_rc(data: &[u8], rc: u32) -> Vec<u8> {
fn encode_trie_node_with_rc(data: &[u8], rc: i32) -> Vec<u8> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the naming reflect that this is now working with delta values instead of absolute values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually both: we write deltas, but read absolute values (aggregation happens in merge operator). Makes sense to do a refactor to move refcount logic from Trie to Store, but we can do it separately

core/store/src/trie/trie_storage.rs Outdated Show resolved Hide resolved
core/store/src/trie/trie_storage.rs Outdated Show resolved Hide resolved
mikhailOK and others added 4 commits August 11, 2020 07:35
@mikhailOK
Copy link
Contributor Author

Manually tested restarting with this change on old storage

@mikhailOK mikhailOK requested a review from frol August 12, 2020 06:29
@mikhailOK mikhailOK merged commit 1bf2fb3 into master Aug 12, 2020
@mikhailOK mikhailOK deleted the merge_operator branch August 13, 2020 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening database takes a very long time
6 participants