Skip to content
Merged
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
18 changes: 11 additions & 7 deletions kvdb-rocksdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ fn other_io_err<E>(e: E) -> io::Error where E: Into<Box<error::Error + Send + Sy
io::Error::new(io::ErrorKind::Other, e)
}

const KB: usize = 1024;
const MB: usize = 1024 * KB;
const DB_DEFAULT_MEMORY_BUDGET_MB: usize = 128;

enum KeyState {
Expand Down Expand Up @@ -142,18 +144,18 @@ impl CompactionProfile {
/// Default profile suitable for SSD storage
pub fn ssd() -> CompactionProfile {
CompactionProfile {
initial_file_size: 64 * 1024 * 1024,
block_size: 16 * 1024,
initial_file_size: 64 * MB as u64,
block_size: 16 * KB,
write_rate_limit: None,
}
}

/// Slow HDD compaction profile
pub fn hdd() -> CompactionProfile {
CompactionProfile {
initial_file_size: 256 * 1024 * 1024,
block_size: 64 * 1024,
write_rate_limit: Some(16 * 1024 * 1024),
initial_file_size: 256 * MB as u64,
block_size: 64 * KB,
write_rate_limit: Some(16 * MB as u64),
}
}
}
Expand Down Expand Up @@ -181,7 +183,7 @@ impl DatabaseConfig {
}

pub fn memory_budget(&self) -> usize {
self.memory_budget.unwrap_or(DB_DEFAULT_MEMORY_BUDGET_MB) * 1024 * 1024
self.memory_budget.unwrap_or(DB_DEFAULT_MEMORY_BUDGET_MB) * MB
}

pub fn memory_budget_per_col(&self) -> usize {
Expand Down Expand Up @@ -303,7 +305,9 @@ impl Database {

{
block_opts.set_block_size(config.compaction.block_size);
let cache_size = cmp::max(8, config.memory_budget() / 3);
// Set cache size as recommended by
// https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning#block-cache-size
let cache_size = config.memory_budget() / 3;
let cache = Cache::new(cache_size);
block_opts.set_cache(cache);
}
Expand Down