-
Notifications
You must be signed in to change notification settings - Fork 218
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
[kvdb-rocksdb] switch to upstream #257
Conversation
…by way of paritytech/parity-common#257 by @ordian.
let overlay = &self.overlay.read()[Self::to_overlay_column(col)]; | ||
/// Will hold a lock until the iterator is dropped | ||
/// preventing the database from being closed. | ||
pub fn iter<'a>(&'a self, col: Option<u32>) -> impl Iterator<Item = KeyValuePair> + 'a { |
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.
this is a breaking change (return type)
@@ -531,26 +513,18 @@ impl Database { | |||
/// Get value by partial key. Prefix size should match configured prefix size. Only searches flushed values. | |||
// TODO: support prefix seek for unflushed data | |||
pub fn get_by_prefix(&self, col: Option<u32>, prefix: &[u8]) -> Option<Box<[u8]>> { | |||
self.iter_from_prefix(col, prefix).and_then(|mut iter| { | |||
match iter.next() { | |||
// TODO: use prefix_same_as_start read option (not available in C API currently) |
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.
we're finally using prefix_same_as_start
kvdb-rocksdb/src/lib.rs
Outdated
block_opts.set_lru_cache(cache_size); | ||
block_opts.set_cache_index_and_filter_blocks(true); | ||
block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true); | ||
block_opts.set_bloom_filter(10, true); |
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.
this option is added based on https://github.com/paritytech/parity-substrate-rocksdb-tuning
_marker: PhantomData<&'a Database>, | ||
struct DBAndColumns { | ||
db: DB, | ||
column_names: Vec<String>, |
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.
we have to store column names instead of columns, because cf_handle
returns a reference to ColumnFamily.
@@ -189,58 +189,37 @@ impl Default for DatabaseConfig { | |||
} | |||
} | |||
|
|||
/// Database iterator (for flushed data only) | |||
// The compromise of holding only a virtual borrow vs. holding a lock on the | |||
// inner DB (to prevent closing via restoration) may be re-evaluated in the future. |
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.
we now hold a (read) lock to prevent closing via restoration during iteration
let read_lock = self.db.read(); | ||
let optional = if read_lock.is_some() { | ||
let guarded = iter::ReadGuardedIterator::new_from_prefix(read_lock, col, prefix); | ||
Some(interleave_ordered(Vec::new(), guarded)) |
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 wonder whether we should search in overlay column as we do in iter
(cc @arkpar)?
Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
Changing the block size seems to have fixed our problems in Polkadot :) |
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.
lgtm modulo lz4
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.
Mostly okay, just some nitpicks.
@@ -672,17 +643,16 @@ impl Database { | |||
self.db | |||
.read() | |||
.as_ref() | |||
.and_then(|db| if db.cfs.is_empty() { None } else { Some(db.cfs.len()) }) | |||
.and_then(|db| if db.column_names.is_empty() { None } else { Some(db.column_names.len()) }) | |||
.map(|n| n as u32) | |||
.unwrap_or(0) | |||
} | |||
|
|||
/// Drop a column family. | |||
pub fn drop_column(&self) -> io::Result<()> { |
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.
As we make a breaking release anyway, shouldn't this be called pop_column()
?
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.
Should we rename add_column
to push_column
as well?
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.
Yeah, good idea :)
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.
to my ears, add_column
sounds better and is easier to understand. Using push/pop sort of implies something temporary or something done fairly frequently (which adding/removing columns is not).
I'd keep add_column
and maaaybe rename drop_column
to remove_column
.
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 just think that drop_column
or remove_column
sounds like something that gets an index and removes the column at the given index and not removes the last column.
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.
That is a good point. How about append_column()
and remove_last_column()
?
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.
As there is no consensus on naming, let's keep it as is, we're planning to release a new breaking version with format_version
, etc after that anyway.
} | ||
} | ||
|
||
pub trait IterationHandler { |
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.
Some documentation would be nice :)
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.
This trait was originally added in #120, we can remove it and all generics here, but it's good to have if we will consider merging something similar to #120.
Another idea I had is replace RwLock<Option<DBAndColumns>>
with https://docs.rs/arc-swap/0.4.4/arc_swap/, but let's keep it as is for now.
…h/parity-common into ao-rocksdb-switch-to-upstream2 * 'ao-rocksdb-switch-to-upstream2' of github.com:paritytech/parity-common: kvdb-rocksdb: remove lz4 feature as it has no effect for now travis: try to fix wasmpack chrome test on macOS (#263) kvdb-rocksdb: please the CI kvdb-rocksdb: do not account for default column memory budget Use 2018 edition for rustfmt (#266) [fixed-hash]: re-export `alloc_` (#268) kvdb-web: async-awaitify (#259)
…h/parity-common into ao-rocksdb-switch-to-upstream2 * 'ao-rocksdb-switch-to-upstream2' of github.com:paritytech/parity-common: kvdb-rocksdb: add a workaround for the rocksdb prefix bug
* Use upstream rocksdb …by way of paritytech/parity-common#257 by @ordian. * Hint at how `parity db reset` works in the error message * migration-rocksdb: fix build * Cargo.toml: use git dependency instead of path * update to latest kvdb-rocksdb * fix tests * saner default for light client * rename open_db to open_db_light * update to latest kvdb-rocksdb * moar update to latest kvdb-rocksdb * even moar update to latest kvdb-rocksdb * use kvdb-rocksdb from crates.io * Update parity/db/rocksdb/helpers.rs * add docs to memory_budget division
We use parity as node for pool mining, so the performance is the major factor. We use 12c/96g/400g ssd machine and parity v2.5.11 to sync blocks, the distribution of cache is similar to default 7:2:1. When we trace the cache of rocksdb, we find the pr #256 and #257, and find the block_size 16KB in rocksdb-0.1.6
However in rocksdb-0.2.0, @grbIzl tried to optimize block_size to 8MB but was rollback to 16KB in this pr. We want to know if it is suitable for us(mining) to set block_size 8MB and any other advice for |
* master: Compile triehash for no_std (#280) [kvdb-rocksdb] Use "pinned" gets to avoid allocations (#274) [kvdb-rocksdb] Release 0.2 (#273) [kvdb-rocksdb] switch to upstream (#257) travis: try to fix wasmpack chrome test on macOS (#263) Use 2018 edition for rustfmt (#266) [fixed-hash]: re-export `alloc_` (#268) kvdb-web: async-awaitify (#259) kvdb-rocksdb: configurable memory budget per column (#256) Bump rlp crate version. (#270) Introduce Rlp::at_with_offset method. (#269) Make fixed-hash test structs public (#267) Migrate primitive types to 2018 edition (#262) upgrade tiny-keccak to 2.0 (#260)
@haihongS increasing block_size to 8mb introduced a performance regression, so we changed the value back. Increasing block_size increases read amplification and is recommended to be 16-64 kb. It's possible to set it to 8mb and drastically increase the cache size, but there is no perf benefit in that. |
@ordian, thanks for your patience, we have changed some codes in v2.5.11 and exposed the rocksdb statistics(ffi) in order to analyse the performance of rocksdb. I am very curious about the way of perf analyse in official parity group, can you offer any tips? |
* Use upstream rocksdb …by way of paritytech/parity-common#257 by @ordian. * Hint at how `parity db reset` works in the error message * migration-rocksdb: fix build * Cargo.toml: use git dependency instead of path * update to latest kvdb-rocksdb * fix tests * saner default for light client * rename open_db to open_db_light * update to latest kvdb-rocksdb * moar update to latest kvdb-rocksdb * even moar update to latest kvdb-rocksdb * use kvdb-rocksdb from crates.io * Update parity/db/rocksdb/helpers.rs * add docs to memory_budget division
This is a draft PR until the following PRs are merged/issues are resolved:Also (could be done in #256)
Closes #88.