mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-25 22:48:34 +00:00
simplify/tune rocksdb options, config option for compression algo
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
6f77f7ee9e
commit
20c089b7ed
|
@ -309,6 +309,11 @@ url_preview_check_root_domain = false
|
||||||
# Defaults to 3 as these are not very useful
|
# Defaults to 3 as these are not very useful
|
||||||
#rocksdb_max_log_files = 3
|
#rocksdb_max_log_files = 3
|
||||||
|
|
||||||
|
# Type of RocksDB database compression to use.
|
||||||
|
# Available options are "zstd", "zlib", "bz2" and "lz4"
|
||||||
|
# Defaults to "zstd"
|
||||||
|
#rocksdb_compression_algo = "zstd"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Presence
|
### Presence
|
||||||
|
|
|
@ -119,6 +119,8 @@ pub struct Config {
|
||||||
pub rocksdb_parallelism_threads: usize,
|
pub rocksdb_parallelism_threads: usize,
|
||||||
#[serde(default = "default_rocksdb_max_log_files")]
|
#[serde(default = "default_rocksdb_max_log_files")]
|
||||||
pub rocksdb_max_log_files: usize,
|
pub rocksdb_max_log_files: usize,
|
||||||
|
#[serde(default = "default_rocksdb_compression_algo")]
|
||||||
|
pub rocksdb_compression_algo: String,
|
||||||
|
|
||||||
pub emergency_password: Option<String>,
|
pub emergency_password: Option<String>,
|
||||||
|
|
||||||
|
@ -352,6 +354,7 @@ impl fmt::Display for Config {
|
||||||
&self.rocksdb_optimize_for_spinning_disks.to_string(),
|
&self.rocksdb_optimize_for_spinning_disks.to_string(),
|
||||||
),
|
),
|
||||||
("RocksDB Parallelism Threads", &self.rocksdb_parallelism_threads.to_string()),
|
("RocksDB Parallelism Threads", &self.rocksdb_parallelism_threads.to_string()),
|
||||||
|
("RocksDB Compression Algorithm", &self.rocksdb_compression_algo),
|
||||||
("Prevent Media Downloads From", {
|
("Prevent Media Downloads From", {
|
||||||
let mut lst = vec![];
|
let mut lst = vec![];
|
||||||
for domain in &self.prevent_media_downloads_from {
|
for domain in &self.prevent_media_downloads_from {
|
||||||
|
@ -451,6 +454,8 @@ fn default_rocksdb_max_log_files() -> usize { 3 }
|
||||||
|
|
||||||
fn default_rocksdb_parallelism_threads() -> usize { num_cpus::get_physical() / 2 }
|
fn default_rocksdb_parallelism_threads() -> usize { num_cpus::get_physical() / 2 }
|
||||||
|
|
||||||
|
fn default_rocksdb_compression_algo() -> String { "zstd".to_owned() }
|
||||||
|
|
||||||
// I know, it's a great name
|
// I know, it's a great name
|
||||||
pub(crate) fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 }
|
pub(crate) fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 }
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,10 @@ fn db_options(rocksdb_cache: &rust_rocksdb::Cache, config: &Config) -> rust_rock
|
||||||
block_based_options.set_block_size(64 * 1024);
|
block_based_options.set_block_size(64 * 1024);
|
||||||
block_based_options.set_cache_index_and_filter_blocks(true);
|
block_based_options.set_cache_index_and_filter_blocks(true);
|
||||||
|
|
||||||
|
block_based_options.set_bloom_filter(10.0, false);
|
||||||
|
block_based_options.set_pin_l0_filter_and_index_blocks_in_cache(true);
|
||||||
|
block_based_options.set_optimize_filters_for_memory(true);
|
||||||
|
|
||||||
// database options: https://docs.rs/rocksdb/latest/rocksdb/struct.Options.html#
|
// database options: https://docs.rs/rocksdb/latest/rocksdb/struct.Options.html#
|
||||||
let mut db_opts = rust_rocksdb::Options::default();
|
let mut db_opts = rust_rocksdb::Options::default();
|
||||||
|
|
||||||
|
@ -49,6 +53,14 @@ fn db_options(rocksdb_cache: &rust_rocksdb::Cache, config: &Config) -> rust_rock
|
||||||
_ => Error,
|
_ => Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let rocksdb_compression_algo = match config.rocksdb_compression_algo.as_ref() {
|
||||||
|
"zstd" => rust_rocksdb::DBCompressionType::Zstd,
|
||||||
|
"zlib" => rust_rocksdb::DBCompressionType::Zlib,
|
||||||
|
"lz4" => rust_rocksdb::DBCompressionType::Lz4,
|
||||||
|
"bz2" => rust_rocksdb::DBCompressionType::Bz2,
|
||||||
|
_ => rust_rocksdb::DBCompressionType::Zstd,
|
||||||
|
};
|
||||||
|
|
||||||
let threads = if config.rocksdb_parallelism_threads == 0 {
|
let threads = if config.rocksdb_parallelism_threads == 0 {
|
||||||
num_cpus::get_physical() // max cores if user specified 0
|
num_cpus::get_physical() // max cores if user specified 0
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,30 +73,27 @@ fn db_options(rocksdb_cache: &rust_rocksdb::Cache, config: &Config) -> rust_rock
|
||||||
db_opts.set_keep_log_file_num(config.rocksdb_max_log_files);
|
db_opts.set_keep_log_file_num(config.rocksdb_max_log_files);
|
||||||
|
|
||||||
if config.rocksdb_optimize_for_spinning_disks {
|
if config.rocksdb_optimize_for_spinning_disks {
|
||||||
db_opts.set_skip_stats_update_on_db_open(true);
|
db_opts.set_skip_stats_update_on_db_open(true); // speeds up opening DB on hard drives
|
||||||
db_opts.set_compaction_readahead_size(2 * 1024 * 1024); // default compaction_readahead_size is 0 which is good for SSDs
|
db_opts.set_compaction_readahead_size(4 * 1024 * 1024); // "If you’re running RocksDB on spinning disks, you should set this to at least
|
||||||
db_opts.set_target_file_size_base(256 * 1024 * 1024); // default target_file_size is 64MB which is good for SSDs
|
// 2MB. That way RocksDB’s compaction is doing sequential instead of random
|
||||||
db_opts.set_optimize_filters_for_hits(true); // doesn't really seem useful for
|
// reads."
|
||||||
// fast storage
|
db_opts.set_target_file_size_base(256 * 1024 * 1024);
|
||||||
} else {
|
} 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_max_bytes_for_level_base(512 * 1024 * 1024);
|
||||||
db_opts.set_use_direct_reads(true);
|
db_opts.set_use_direct_reads(true);
|
||||||
db_opts.set_use_direct_io_for_flush_and_compaction(true);
|
db_opts.set_use_direct_io_for_flush_and_compaction(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
db_opts.set_block_based_table_factory(&block_based_options);
|
db_opts.set_block_based_table_factory(&block_based_options);
|
||||||
db_opts.set_level_compaction_dynamic_level_bytes(true);
|
|
||||||
db_opts.create_if_missing(true);
|
db_opts.create_if_missing(true);
|
||||||
db_opts.increase_parallelism(
|
db_opts.increase_parallelism(
|
||||||
threads.try_into().expect("Failed to convert \"rocksdb_parallelism_threads\" usize into i32"),
|
threads.try_into().expect("Failed to convert \"rocksdb_parallelism_threads\" usize into i32"),
|
||||||
);
|
);
|
||||||
//db_opts.set_max_open_files(config.rocksdb_max_open_files);
|
db_opts.set_compression_type(rocksdb_compression_algo);
|
||||||
db_opts.set_compression_type(rust_rocksdb::DBCompressionType::Zstd);
|
|
||||||
db_opts.set_compaction_style(rust_rocksdb::DBCompactionStyle::Level);
|
|
||||||
db_opts.optimize_level_style_compaction(10 * 1024 * 1024);
|
db_opts.optimize_level_style_compaction(10 * 1024 * 1024);
|
||||||
|
|
||||||
// https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning
|
// https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning
|
||||||
|
db_opts.set_level_compaction_dynamic_level_bytes(true);
|
||||||
db_opts.set_max_background_jobs(6);
|
db_opts.set_max_background_jobs(6);
|
||||||
db_opts.set_bytes_per_sync(1_048_576);
|
db_opts.set_bytes_per_sync(1_048_576);
|
||||||
|
|
||||||
|
|
|
@ -369,6 +369,8 @@ impl Service<'_> {
|
||||||
|
|
||||||
pub fn rocksdb_parallelism_threads(&self) -> usize { self.config.rocksdb_parallelism_threads }
|
pub fn rocksdb_parallelism_threads(&self) -> usize { self.config.rocksdb_parallelism_threads }
|
||||||
|
|
||||||
|
pub fn rocksdb_compression_algo(&self) -> &String { &self.config.rocksdb_compression_algo }
|
||||||
|
|
||||||
pub fn prevent_media_downloads_from(&self) -> &[OwnedServerName] { &self.config.prevent_media_downloads_from }
|
pub fn prevent_media_downloads_from(&self) -> &[OwnedServerName] { &self.config.prevent_media_downloads_from }
|
||||||
|
|
||||||
pub fn ip_range_denylist(&self) -> &[String] { &self.config.ip_range_denylist }
|
pub fn ip_range_denylist(&self) -> &[String] { &self.config.ip_range_denylist }
|
||||||
|
|
Loading…
Reference in a new issue