replace num_cpus dependency with available_parallelism()
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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)?);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user