adjust readpool size by the number of cpu core
//! TiKV is configured through the `TiKvConfig` type, which is in turn
//! made up of many other configuration types.
+use std::cmp;
use std::error::Error;
use std::fs;
use std::i32;
@@ -1196,7 +1197,8 @@ macro_rules! readpool_config {
};
}
-const DEFAULT_STORAGE_READPOOL_CONCURRENCY: usize = 4;
+const DEFAULT_STORAGE_READPOOL_MIN_CONCURRENCY: usize = 4;
+const DEFAULT_STORAGE_READPOOL_MAX_CONCURRENCY: usize = 8;
// Assume a request can be finished in 1ms, a request at position x will wait about
// 0.001 * x secs to be actual started. A server-is-busy error will trigger 2 seconds
@@ -1210,10 +1212,14 @@ readpool_config!(StorageReadPoolConfig, storage_read_pool_test, "storage");
impl Default for StorageReadPoolConfig {
fn default() -> Self {
+ let cpu_num = sys_info::cpu_num().unwrap();
+ let mut concurrency = (f64::from(cpu_num) * 0.5) as usize;
+ concurrency = cmp::max(DEFAULT_STORAGE_READPOOL_MIN_CONCURRENCY, concurrency);
+ concurrency = cmp::min(DEFAULT_STORAGE_READPOOL_MAX_CONCURRENCY, concurrency);
Self {
- high_concurrency: DEFAULT_STORAGE_READPOOL_CONCURRENCY,
- normal_concurrency: DEFAULT_STORAGE_READPOOL_CONCURRENCY,
- low_concurrency: DEFAULT_STORAGE_READPOOL_CONCURRENCY,
+ high_concurrency: concurrency,
+ normal_concurrency: concurrency,
+ low_concurrency: concurrency,
max_tasks_per_worker_high: DEFAULT_READPOOL_MAX_TASKS_PER_WORKER,
max_tasks_per_worker_normal: DEFAULT_READPOOL_MAX_TASKS_PER_WORKER,
max_tasks_per_worker_low: DEFAULT_READPOOL_MAX_TASKS_PER_WORKER,
@@ -1222,7 +1228,7 @@ impl Default for StorageReadPoolConfig {
}
}
-const DEFAULT_COPROCESSOR_READPOOL_CONCURRENCY: usize = 8;
+const DEFAULT_COPROCESSOR_READPOOL_MIN_CONCURRENCY: usize = 2;
readpool_config!(
CoprReadPoolConfig,
@@ -1233,11 +1239,8 @@ readpool_config!(
impl Default for CoprReadPoolConfig {
fn default() -> Self {
let cpu_num = sys_info::cpu_num().unwrap();
- let concurrency = if cpu_num > 8 {
- (f64::from(cpu_num) * 0.8) as usize
- } else {
- DEFAULT_COPROCESSOR_READPOOL_CONCURRENCY
- };
+ let mut concurrency = (f64::from(cpu_num) * 0.8) as usize;
+ concurrency = cmp::max(DEFAULT_COPROCESSOR_READPOOL_MIN_CONCURRENCY, concurrency);
Self {
high_concurrency: concurrency,
normal_concurrency: concurrency,
