Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
84 changes: 80 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ lru = "0.12.3"
num-bigint = "0.4.3"
num-format = "0.4.4"
num-traits = "0.2.18"
num_cpus = "1.16.0"
octocrab = "0.42.1"
oneshot = "0.1.6"
pathdiff = "0.2.1"
Expand Down Expand Up @@ -172,6 +171,7 @@ similar-asserts = "1.5.0"
static_assertions = "1.1.0"
stdext = "0.3.3"
syn = "2.0.52"
sysinfo = "0.33.1"
tempfile = "3.10.1"
test-case = "3.3.1"
test-log = { version = "0.2.15", default-features = false, features = [
Expand Down
86 changes: 81 additions & 5 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion linera-views/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ linera-base.workspace = true
linera-views-derive.workspace = true
linera-witty.workspace = true
linked-hash-map.workspace = true
num_cpus.workspace = true
prometheus.workspace = true
rand = { workspace = true, features = ["small_rng"] }
rocksdb = { workspace = true, optional = true }
scylla = { workspace = true, optional = true }
serde.workspace = true
sha3.workspace = true
static_assertions.workspace = true
sysinfo.workspace = true
tempfile.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["rt", "sync"] }
Expand Down
40 changes: 30 additions & 10 deletions linera-views/src/backends/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use std::{
};

use linera_base::ensure;
use rocksdb::{BlockBasedOptions, Cache, DBCompactionStyle};
use serde::{Deserialize, Serialize};
use sysinfo::{CpuRefreshKind, MemoryRefreshKind, RefreshKind, System};
use tempfile::TempDir;
use thiserror::Error;

Expand Down Expand Up @@ -49,8 +51,9 @@ const MAX_VALUE_SIZE: usize = 3221225072;
// 8388608 and so for offset reason we decrease by 400
const MAX_KEY_SIZE: usize = 8388208;

const DB_CACHE_SIZE: usize = 128 * 1024 * 1024; // 128 MiB
const DB_MAX_WRITE_BUFFER_NUMBER: i32 = 8;
const WRITE_BUFFER_SIZE: usize = 64 * 1024 * 1024; // 64 MB
const MAX_WRITE_BUFFER_NUMBER: i32 = 32;
const HYPER_CLOCK_CACHE_BLOCK_SIZE: usize = 8 * 1024; // 8 KB

/// The RocksDB client that we use.
type DB = rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>;
Expand Down Expand Up @@ -300,21 +303,38 @@ impl RocksDbStoreInternal {
if !std::path::Path::exists(&path_buf) {
std::fs::create_dir(path_buf.clone())?;
}
let sys = System::new_with_specifics(
RefreshKind::nothing()
.with_cpu(CpuRefreshKind::everything())
.with_memory(MemoryRefreshKind::nothing().with_ram()),
);
let num_cpus = sys.cpus().len() as i32;
let total_ram = sys.total_memory() as usize;
let mut options = rocksdb::Options::default();
options.create_if_missing(true);
options.create_missing_column_families(true);
// Flush in-memory buffer to disk more often
options.set_write_buffer_size(DB_CACHE_SIZE);
options.set_max_write_buffer_number(DB_MAX_WRITE_BUFFER_NUMBER);
options.set_write_buffer_size(WRITE_BUFFER_SIZE);
options.set_max_write_buffer_number(MAX_WRITE_BUFFER_NUMBER);
options.set_compression_type(rocksdb::DBCompressionType::Lz4);
options.set_level_zero_slowdown_writes_trigger(-1);
options.set_level_zero_stop_writes_trigger(48);
options.set_stats_dump_period_sec(60);
options.enable_statistics();
options.increase_parallelism(num_cpus::get() as i32);
options.set_max_background_jobs(8);
options.set_level_zero_slowdown_writes_trigger(12);
options.set_level_zero_stop_writes_trigger(20);
options.increase_parallelism((num_cpus / 2).max(1));
options.set_max_background_jobs((num_cpus / 3).max(1));
options.set_level_compaction_dynamic_level_bytes(true);

options.set_compaction_style(DBCompactionStyle::Level);
options.set_target_file_size_base(WRITE_BUFFER_SIZE as u64);

let mut block_options = BlockBasedOptions::default();
block_options.set_pin_l0_filter_and_index_blocks_in_cache(true);
block_options.set_cache_index_and_filter_blocks(true);
block_options.set_block_cache(&Cache::new_hyper_clock_cache(
total_ram / 4,
HYPER_CLOCK_CACHE_BLOCK_SIZE,
));
options.set_block_based_table_factory(&block_options);

let db = DB::open(&options, path_buf)?;
let executor = RocksDbStoreExecutor {
db: Arc::new(db),
Expand Down
Loading