add config option for max RocksDB LOG files

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-03-06 18:20:02 -05:00 committed by June
parent 7bfb86a851
commit d2060c8647
3 changed files with 12 additions and 5 deletions

View file

@ -302,6 +302,10 @@ allow_check_for_updates = true
# Defaults to your CPU physical core count (not logical threads) count divided by 2 (half)
#rocksdb_parallelism_threads = 0
# Maximum number of LOG files RocksDB will keep
# Defaults to 3 as these are not very useful
#rocksdb_max_log_files = 3
### Presence

View file

@ -117,6 +117,8 @@ pub struct Config {
pub rocksdb_optimize_for_spinning_disks: bool,
#[serde(default = "default_rocksdb_parallelism_threads")]
pub rocksdb_parallelism_threads: usize,
#[serde(default = "default_rocksdb_max_log_files")]
pub rocksdb_max_log_files: usize,
pub emergency_password: Option<String>,
@ -339,6 +341,7 @@ impl fmt::Display for Config {
("zstd Response Body Compression", &self.zstd_compression.to_string()),
("RocksDB database log level", &self.rocksdb_log_level),
("RocksDB database log time-to-roll", &self.rocksdb_log_time_to_roll.to_string()),
("RocksDB Max LOG Files", &self.rocksdb_max_log_files.to_string()),
(
"RocksDB database max log file size",
&self.rocksdb_max_log_file_size.to_string(),
@ -443,6 +446,8 @@ fn default_rocksdb_log_level() -> String { "error".to_owned() }
fn default_rocksdb_log_time_to_roll() -> usize { 0 }
fn default_rocksdb_max_log_files() -> usize { 3 }
fn default_rocksdb_parallelism_threads() -> usize { num_cpus::get_physical() / 2 }
// I know, it's a great name

View file

@ -58,21 +58,19 @@ fn db_options(rocksdb_cache: &rocksdb::Cache, config: &Config) -> rocksdb::Optio
db_opts.set_log_level(rocksdb_log_level);
db_opts.set_max_log_file_size(config.rocksdb_max_log_file_size);
db_opts.set_log_file_time_to_roll(config.rocksdb_log_time_to_roll);
db_opts.set_keep_log_file_num(config.rocksdb_max_log_files);
if config.rocksdb_optimize_for_spinning_disks {
db_opts.set_skip_stats_update_on_db_open(true);
db_opts.set_compaction_readahead_size(2 * 1024 * 1024); // default compaction_readahead_size is 0 which is good for SSDs
db_opts.set_target_file_size_base(256 * 1024 * 1024); // default target_file_size is 64MB which is good for SSDs
db_opts.set_optimize_filters_for_hits(true); // doesn't really seem useful for fast storage
db_opts.set_keep_log_file_num(3); // keep as few LOG files as possible for
// spinning hard drives. these are not really
// important
db_opts.set_optimize_filters_for_hits(true); // doesn't really seem useful for
// fast storage
} else {
db_opts.set_skip_stats_update_on_db_open(false);
db_opts.set_max_bytes_for_level_base(512 * 1024 * 1024);
db_opts.set_use_direct_reads(true);
db_opts.set_use_direct_io_for_flush_and_compaction(true);
db_opts.set_keep_log_file_num(20);
}
db_opts.set_block_based_table_factory(&block_based_options);