Clamp JSON CPU count to available CPU count
This commit is contained in:
parent
7f60a00ee4
commit
86471990bb
2 changed files with 16 additions and 1 deletions
2
backend/Cargo.lock
generated
2
backend/Cargo.lock
generated
|
@ -567,7 +567,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "powertools-rs"
|
name = "powertools-rs"
|
||||||
version = "1.0.0-rc2"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -101,9 +101,24 @@ impl Settings {
|
||||||
|
|
||||||
fn convert_cpus(mut cpus: Vec<CpuJson>, version: u64) -> Vec<Cpu> {
|
fn convert_cpus(mut cpus: Vec<CpuJson>, version: u64) -> Vec<Cpu> {
|
||||||
let mut result = Vec::with_capacity(cpus.len());
|
let mut result = Vec::with_capacity(cpus.len());
|
||||||
|
let max_cpus = Cpu::cpu_count();
|
||||||
for (i, cpu) in cpus.drain(..).enumerate() {
|
for (i, cpu) in cpus.drain(..).enumerate() {
|
||||||
|
// prevent having more CPUs than available
|
||||||
|
if let Some(max_cpus) = max_cpus {
|
||||||
|
if i == max_cpus {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
result.push(Cpu::from_json(cpu, version, i));
|
result.push(Cpu::from_json(cpu, version, i));
|
||||||
}
|
}
|
||||||
|
if let Some(max_cpus) = max_cpus {
|
||||||
|
if result.len() != max_cpus {
|
||||||
|
let mut sys_cpus = Cpu::system_default();
|
||||||
|
for i in result.len()..sys_cpus.len() {
|
||||||
|
result.push(sys_cpus.remove(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue