-
Notifications
You must be signed in to change notification settings - Fork 28
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(core): batch heavy write operations #1358
Conversation
c310f7f
to
67590b7
Compare
67590b7
to
4dec142
Compare
@@ -14,4 +14,6 @@ use crate::error::TrieError; | |||
pub trait TrieDB { | |||
fn get(&self, key: Vec<u8>) -> Result<Option<Vec<u8>>, TrieError>; | |||
fn put(&self, key: Vec<u8>, value: Vec<u8>) -> Result<(), TrieError>; | |||
// fn put_batch(&self, key: Vec<u8>, value: Vec<u8>) -> Result<(), TrieError>; |
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.
Nit: maybe remove this ?
crates/storage/trie/db/in_memory.rs
Outdated
@@ -25,4 +25,14 @@ impl TrieDB for InMemoryTrieDB { | |||
self.inner.lock().unwrap().insert(key, value); | |||
Ok(()) | |||
} | |||
|
|||
fn put_batch(&self, key_values: Vec<(Vec<u8>, Vec<u8>)>) -> Result<(), TrieError> { | |||
let mut db = self.inner.lock().unwrap(); |
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.
Don't unwrap here, let's return an error.
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.
Removed unwraps here 4845ce8
Motivation
This PR batches the three current heaviest db write operations on the node (
add_block
,store_receipts
, andcommit_node
) so that a single db transaction is used for them. This reduces the time spent flushing to disc withmsync
(onlibmdbx
) orfsync
(onredb
) from around ~40-50% to ~0.35%.Non-batched version:
Batched version (the
msync
on this flamegraph is one of the tiny red bars to the left):Description