diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 96b2f76f79f9a4c426c8aec95f2b543c47eae297..fdf537832eb60b5e08ddd4cc8234f27d31c89872 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -514,6 +514,19 @@ allow_profile_lookup_federation_requests = true # Defaults to false as this uses more CPU when compressing. #rocksdb_bottommost_compression = false +# Level of statistics collection. Some admin commands to display database statistics may require +# this option to be set. Database performance may be impacted by higher settings. +# +# Option is a number ranging from 0 to 6: +# 0 = No statistics. +# 1 = No statistics in release mode (default). +# 2 to 3 = Statistics with no performance impact. +# 3 to 5 = Statistics with possible performance impact. +# 6 = All statistics. +# +# Defaults to 1 (No statistics, except in debug-mode) +#rocksdb_stats_level = 1 + # Database repair mode (for RocksDB SST corruption) # # Use this option when the server reports corruption while running or panics. If the server refuses diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 6ccb055958eabcf321723b04a07efd45607fe15b..bec7c4ea3f49c8c68c9d648f694a9d5ee188716f 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -236,6 +236,8 @@ pub struct Config { pub rocksdb_compaction_ioprio_idle: bool, #[serde(default = "true_fn")] pub rocksdb_compaction: bool, + #[serde(default = "default_rocksdb_stats_level")] + pub rocksdb_stats_level: u8, pub emergency_password: Option<String>, @@ -718,6 +720,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { &self.rocksdb_compaction_ioprio_idle.to_string(), ); line("RocksDB Compaction enabled", &self.rocksdb_compaction.to_string()); + line("RocksDB Statistics level", &self.rocksdb_stats_level.to_string()); line("Media integrity checks on startup", &self.media_startup_check.to_string()); line("Media compatibility filesystem links", &self.media_compat_file_link.to_string()); line("Prevent Media Downloads From", { @@ -1002,6 +1005,8 @@ fn default_rocksdb_compression_level() -> i32 { 32767 } #[allow(clippy::doc_markdown)] fn default_rocksdb_bottommost_compression_level() -> i32 { 32767 } +fn default_rocksdb_stats_level() -> u8 { 1 } + // I know, it's a great name #[must_use] pub fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 } diff --git a/src/database/opts.rs b/src/database/opts.rs index 3c3ad4242b68bad365eec31260da0d0253befbd3..8791e77834d994845075919dcd60cacb3c82889b 100644 --- a/src/database/opts.rs +++ b/src/database/opts.rs @@ -2,8 +2,8 @@ use conduit::{utils, Config}; use rocksdb::{ - BlockBasedOptions, Cache, DBCompactionStyle, DBCompressionType, DBRecoveryMode, Env, LogLevel, Options, - UniversalCompactOptions, UniversalCompactionStopStyle, + statistics::StatsLevel, BlockBasedOptions, Cache, DBCompactionStyle, DBCompressionType, DBRecoveryMode, Env, + LogLevel, Options, UniversalCompactOptions, UniversalCompactionStopStyle, }; /// Create database-wide options suitable for opening the database. This also @@ -13,6 +13,11 @@ /// through cf_options(). pub(crate) fn db_options(config: &Config, env: &mut Env, row_cache: &Cache, col_cache: &Cache) -> Options { const MIN_PARALLELISM: usize = 2; + const DEFAULT_STATS_LEVEL: StatsLevel = if cfg!(debug_assertions) { + StatsLevel::ExceptDetailedTimers + } else { + StatsLevel::DisableAll + }; let mut opts = Options::default(); @@ -68,8 +73,18 @@ pub(crate) fn db_options(config: &Config, env: &mut Env, row_cache: &Cache, col_ set_compression_defaults(&mut opts, config); // Misc - opts.set_disable_auto_compactions(!config.rocksdb_compaction); opts.create_if_missing(true); + opts.set_disable_auto_compactions(!config.rocksdb_compaction); + + opts.set_statistics_level(match config.rocksdb_stats_level { + 0 => StatsLevel::DisableAll, + 1 => DEFAULT_STATS_LEVEL, + 2 => StatsLevel::ExceptHistogramOrTimers, + 3 => StatsLevel::ExceptTimers, + 4 => StatsLevel::ExceptDetailedTimers, + 5 => StatsLevel::ExceptTimeForMutex, + 6_u8..=u8::MAX => StatsLevel::All, + }); // Default: https://github.com/facebook/rocksdb/wiki/WAL-Recovery-Modes#ktoleratecorruptedtailrecords //