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

lz4+zstd compression #6365

Merged
merged 21 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@

* Enable access key nonce range for implicit accounts to prevent tx hash collisions [#5482](https://github.com/near/nearcore/pull/5482)

### Non-protocol Changes

* Switch to LZ4+ZSTD compression from Snappy in RocksDB [#6365](https://github.com/near/nearcore/pull/6365)

## `1.23.0` [13-12-2021]

### Protocol Changes

* Further lower regular_op_cost from 2_207_874 to 822_756.
* Limit number of wasm functions in one contract to 10_000. [#4954](https://github.com/near/nearcore/pull/4954)
* Add block header v3, required by new validator selection algorithm
* Move to new validator selection and sampling algorithm. Now we would be able to use all available seats. First step to enable chunk only producers.
* Move to new validator selection and sampling algorithm. Now we would be able to use all available seats. First step to enable chunk only producers.

### Non-protocol Changes

Expand Down
24 changes: 23 additions & 1 deletion core/store/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,32 @@ impl Database for TestDB {
}
}

fn set_compression_options(opts: &mut Options) {
EdvardD marked this conversation as resolved.
Show resolved Hide resolved
opts.set_compression_type(rocksdb::DBCompressionType::Lz4);
opts.set_bottommost_compression_type(rocksdb::DBCompressionType::Zstd);
// RocksDB documenation says that 16KB is a typical dictionary size.
// We've empirically tuned the dicionary size to twice of that 'typical' size.
// Having train data size x100 from dictionary size is a recommendation from RocksDB.
// See: https://rocksdb.org/blog/2021/05/31/dictionary-compression.html?utm_source=dbplatz
let dict_size = 2 * 16384;
let max_train_bytes = dict_size * 100;
// We use default parameters of RocksDB here:
// window_bits is -14 and is unused (Zlib-specific parameter),
// compression_level is 32767 meaning the default compression level for ZSTD,
// compression_strategy is 0 and is unused (Zlib-specific parameter).
// See: https://github.com/facebook/rocksdb/blob/main/include/rocksdb/advanced_options.h#L176:
opts.set_bottommost_compression_options(
/*window_bits */ -14, /*compression_level */ 32767,
/*compression_strategy */ 0, dict_size, /*enabled */ true,
);
opts.set_bottommost_zstd_max_train_bytes(max_train_bytes, true);
}

/// DB level options
fn rocksdb_options() -> Options {
let mut opts = Options::default();

set_compression_options(&mut opts);
opts.create_missing_column_families(true);
opts.create_if_missing(true);
opts.set_use_fsync(false);
Expand Down Expand Up @@ -817,12 +839,12 @@ fn choose_cache_size(col: DBCol) -> usize {

fn rocksdb_column_options(col: DBCol) -> Options {
let mut opts = Options::default();
set_compression_options(&mut opts);
EdvardD marked this conversation as resolved.
Show resolved Hide resolved
opts.set_level_compaction_dynamic_level_bytes(true);
let cache_size = choose_cache_size(col);
opts.set_block_based_table_factory(&rocksdb_block_based_options(cache_size));
opts.optimize_level_style_compaction(128 * bytesize::MIB as usize);
opts.set_target_file_size_base(64 * bytesize::MIB);
opts.set_compression_per_level(&[]);
if col.is_rc() {
opts.set_merge_operator("refcount merge", RocksDB::refcount_merge, RocksDB::refcount_merge);
opts.set_compaction_filter("empty value filter", RocksDB::empty_value_compaction_filter);
Expand Down