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

[kvdb-rocksdb] switch to upstream #257

Merged
merged 43 commits into from
Nov 28, 2019
Merged

Conversation

ordian
Copy link
Member

@ordian ordian commented Nov 10, 2019

dvdplm added a commit to openethereum/parity-ethereum that referenced this pull request Nov 11, 2019
@ordian ordian marked this pull request as ready for review November 14, 2019 15:55
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 {
Copy link
Member Author

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)
Copy link
Member Author

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

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);
Copy link
Member Author

Choose a reason for hiding this comment

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

_marker: PhantomData<&'a Database>,
struct DBAndColumns {
db: DB,
column_names: Vec<String>,
Copy link
Member Author

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.
Copy link
Member Author

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))
Copy link
Member Author

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)?

ordian and others added 5 commits November 19, 2019 10:24
* master:
  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)
kvdb-rocksdb/src/iter.rs Outdated Show resolved Hide resolved
kvdb-rocksdb/src/iter.rs Outdated Show resolved Hide resolved
kvdb-rocksdb/src/lib.rs Outdated Show resolved Hide resolved
kvdb-rocksdb/src/lib.rs Outdated Show resolved Hide resolved
kvdb-rocksdb/src/lib.rs Outdated Show resolved Hide resolved
kvdb-rocksdb/src/lib.rs Outdated Show resolved Hide resolved
kvdb-rocksdb/src/lib.rs Outdated Show resolved Hide resolved
Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
kvdb-rocksdb/Cargo.toml Outdated Show resolved Hide resolved
@bkchr
Copy link
Member

bkchr commented Nov 27, 2019

Changing the block size seems to have fixed our problems in Polkadot :)

@ordian ordian requested a review from dvdplm November 27, 2019 14:37
Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

lgtm modulo lz4

kvdb-rocksdb/Cargo.toml Outdated Show resolved Hide resolved
* master:
  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)
Copy link
Member

@bkchr bkchr left a 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<()> {
Copy link
Member

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()?

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, good idea :)

Copy link
Contributor

@dvdplm dvdplm Nov 27, 2019

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.

Copy link
Member

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.

Copy link
Contributor

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()?

Copy link
Member Author

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 {
Copy link
Member

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 :)

Copy link
Member Author

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.

kvdb-rocksdb/src/iter.rs Outdated Show resolved Hide resolved
kvdb-rocksdb/src/iter.rs Outdated Show resolved Hide resolved
dvdplm and others added 8 commits November 28, 2019 08:36
…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
@dvdplm dvdplm merged commit 8fb8f13 into master Nov 28, 2019
@dvdplm dvdplm deleted the ao-rocksdb-switch-to-upstream2 branch November 28, 2019 13:21
@ordian ordian restored the ao-rocksdb-switch-to-upstream2 branch November 28, 2019 16:02
ordian pushed a commit to openethereum/parity-ethereum that referenced this pull request Dec 3, 2019
* 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
@sherlock-shi-x
Copy link

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

	pub fn ssd() -> CompactionProfile {
		CompactionProfile {
			initial_file_size: 64 * MB as u64,
			block_size: 16 * KB,
			write_rate_limit: None,
		}
	}

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
parity (cache) configuration due to our machine, thank you.
@ordian @grbIzl

dvdplm added a commit that referenced this pull request Dec 10, 2019
* 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)
@bkchr bkchr deleted the ao-rocksdb-switch-to-upstream2 branch December 10, 2019 07:35
@ordian
Copy link
Member Author

ordian commented Dec 10, 2019

@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.

@sherlock-shi-x
Copy link

@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?

grbIzl pushed a commit to paritytech/secret-store that referenced this pull request Jan 14, 2020
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to rust-rocksdb in kvdb-rocksdb
4 participants