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

feat: ELECTRS_ROCKSDB_WRITE_BUFFER_SIZE #975

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 20 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{Context, Result};
use electrs_rocksdb as rocksdb;

use std::path::Path;
use std::str::FromStr;
use std::sync::atomic::{AtomicBool, Ordering};

pub(crate) type Row = Box<[u8]>;
Expand Down Expand Up @@ -95,6 +96,22 @@ impl Default for Config {
}
}

fn get_write_buffer_size() -> usize {
const VAR_NAME: &str = "ELECTRS_ROCKSDB_WRITE_BUFFER_SIZE";

if let Ok(var) = std::env::var(VAR_NAME) {
let size = FromStr::from_str(&var)
.with_context(|| format!("Could not parse {VAR_NAME}"))
.expect("Invalid write buffer size");

info!("Using custom write buffer size: {size}");

size
} else {
256 << 20
}
}

fn default_opts() -> rocksdb::Options {
let mut block_opts = rocksdb::BlockBasedOptions::default();
block_opts.set_checksum_type(rocksdb::ChecksumType::CRC32c);
Expand All @@ -104,8 +121,9 @@ fn default_opts() -> rocksdb::Options {
opts.set_max_open_files(16);
opts.set_compaction_style(rocksdb::DBCompactionStyle::Level);
opts.set_compression_type(rocksdb::DBCompressionType::Zstd);
opts.set_target_file_size_base(256 << 20);
opts.set_write_buffer_size(256 << 20);
let file_size = get_write_buffer_size();
opts.set_target_file_size_base(file_size as u64);
opts.set_write_buffer_size(file_size);
opts.set_disable_auto_compactions(true); // for initial bulk load
opts.set_advise_random_on_open(false); // bulk load uses sequential I/O
opts.set_prefix_extractor(rocksdb::SliceTransform::create_fixed_prefix(8));
Expand Down