Skip to content

Commit 1f14542

Browse files
Tweaking the number of threads to attribute to the different runtimes (#5875)
This changes the result for 3vcpu and 2vcpus. In that case, dedicated one vcpus to non-blocking tasks was judged overkill. Co-authored-by: fulmicoton <paul.masurel@datadoghq.com>
1 parent 15cd9e5 commit 1f14542

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

quickwit/quickwit-common/src/runtimes.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,26 @@ impl RuntimesConfig {
6363
}
6464

6565
pub fn with_num_cpus(num_cpus: usize) -> Self {
66-
// Non blocking task are supposed to be io intensive, and not require many threads...
67-
let num_threads_non_blocking = if num_cpus > 6 { 2 } else { 1 };
66+
// Non blocking task are supposed to be io intensive, and not require many threads.
6867
// On the other hand the blocking actors are cpu intensive. We allocate
6968
// almost all of the threads to them.
70-
let num_threads_blocking = (num_cpus - num_threads_non_blocking).max(1);
71-
RuntimesConfig {
72-
num_threads_non_blocking,
73-
num_threads_blocking,
69+
match num_cpus {
70+
0..=3 => {
71+
// We do not have enough vCPUs to allocate a full thread to
72+
// non-blocking.
73+
RuntimesConfig {
74+
num_threads_non_blocking: 1,
75+
num_threads_blocking: num_cpus,
76+
}
77+
}
78+
4..=6 => RuntimesConfig {
79+
num_threads_non_blocking: 1,
80+
num_threads_blocking: num_cpus - 1,
81+
},
82+
7.. => RuntimesConfig {
83+
num_threads_non_blocking: 2,
84+
num_threads_blocking: num_cpus - 2,
85+
},
7486
}
7587
}
7688
}
@@ -232,7 +244,7 @@ mod tests {
232244
#[test]
233245
fn test_runtimes_with_given_num_cpus_3() {
234246
let runtime = RuntimesConfig::with_num_cpus(3);
235-
assert_eq!(runtime.num_threads_blocking, 2);
247+
assert_eq!(runtime.num_threads_blocking, 3);
236248
assert_eq!(runtime.num_threads_non_blocking, 1);
237249
}
238250
}

0 commit comments

Comments
 (0)