replace num_cpus dependency with available_parallelism()

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-05-25 20:58:37 +00:00 committed by June 🍓🦴
parent d2aef071bc
commit a537462d51
8 changed files with 22 additions and 13 deletions

View file

@ -56,7 +56,6 @@ conduit-core.workspace = true
futures-util.workspace = true
log.workspace = true
lru-cache.workspace = true
num_cpus.workspace = true
parking_lot.optional = true
parking_lot.workspace = true
ruma.workspace = true

View file

@ -1,5 +1,7 @@
#![allow(dead_code)]
use std::collections::HashMap;
use std::{cmp, collections::HashMap};
use conduit::utils;
use super::{
rust_rocksdb::{
@ -21,10 +23,11 @@ pub(crate) fn db_options(config: &Config, env: &mut Env, row_cache: &Cache, col_
set_logging_defaults(&mut opts, config);
// Processing
const MIN_PARALLELISM: usize = 2;
let threads = if config.rocksdb_parallelism_threads == 0 {
std::cmp::max(2, num_cpus::get()) // max cores if user specified 0
cmp::max(MIN_PARALLELISM, utils::available_parallelism())
} else {
config.rocksdb_parallelism_threads
cmp::max(MIN_PARALLELISM, config.rocksdb_parallelism_threads)
};
opts.set_max_background_jobs(threads.try_into().unwrap());

View file

@ -108,7 +108,8 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
clippy::cast_precision_loss,
clippy::cast_sign_loss
)]
let cache_size_per_thread = ((config.db_cache_capacity_mb * 1024.0) / ((num_cpus::get() as f64 * 2.0) + 1.0)) as u32;
let cache_size_per_thread = ((config.db_cache_capacity_mb * 1024.0)
/ ((conduit::utils::available_parallelism() as f64 * 2.0) + 1.0)) as u32;
let writer = Mutex::new(Engine::prepare_conn(&path, cache_size_per_thread)?);