diff --git a/src/new_index/db.rs b/src/new_index/db.rs index ef226d34b..9b0c01833 100644 --- a/src/new_index/db.rs +++ b/src/new_index/db.rs @@ -1,6 +1,7 @@ use rocksdb; use std::path::Path; +use std::str::FromStr; use crate::config::Config; use crate::util::Bytes; @@ -80,6 +81,20 @@ pub enum DBFlush { Enable, } +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).expect("Could not parse {VAR_NAME}"); + + info!("Using custom write buffer size: {size}"); + + size + } else { + 256 << 20 + } +} + impl DB { pub fn open(path: &Path, config: &Config) -> DB { debug!("opening DB at {:?}", path); @@ -89,7 +104,7 @@ impl DB { db_opts.set_compaction_style(rocksdb::DBCompactionStyle::Level); db_opts.set_compression_type(rocksdb::DBCompressionType::Snappy); db_opts.set_target_file_size_base(1_073_741_824); - db_opts.set_write_buffer_size(256 << 20); + db_opts.set_write_buffer_size(get_write_buffer_size()); db_opts.set_disable_auto_compactions(true); // for initial bulk load // db_opts.set_advise_random_on_open(???);