[pve-devel] [PATCH proxmox-resource-scheduling 1/2] pve ha: fix scoring issue when a node is overcommitted compared to others
Fiona Ebner
f.ebner at proxmox.com
Tue Mar 21 13:33:42 CET 2023
When nodes have different stats, the sum of percentage values will be
different for different alternatives, so the linear average is enough.
But when nodes have the same stats, this is not the case, the sum will
be the same, thus the average won't influence the scoring. If there is
an already overcommitted node, all alternatives besides the already
overcommitted node would be scored the same.
To fix it, use the squares of percentages instead, where more evenly
distributed usage across nodes will lead to a smaller value and thus
better scoring.
It's not really necessary to divide by length or take the sqrt, but it
seemed nicer to have something that would give 1.0 if all inputs are
1.0.
Reported-by: Dominik Csapak <d.csapak at proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
Sorry about the stupid mistake :(
src/pve_static.rs | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/pve_static.rs b/src/pve_static.rs
index 345c0a2..6663b70 100644
--- a/src/pve_static.rs
+++ b/src/pve_static.rs
@@ -79,11 +79,11 @@ pub fn score_nodes_to_start_service(
.iter()
.enumerate()
.map(|(target_index, _)| {
- // all of these are as percentages to be comparable across nodes
+ // Base values on percentages to allow comparing nodes with different stats.
let mut highest_cpu = 0.0;
- let mut sum_cpu = 0.0;
+ let mut squares_cpu = 0.0;
let mut highest_mem = 0.0;
- let mut sum_mem = 0.0;
+ let mut squares_mem = 0.0;
for (index, node) in nodes.iter().enumerate() {
let new_cpu = if index == target_index {
@@ -92,7 +92,7 @@ pub fn score_nodes_to_start_service(
node.cpu
} / (node.maxcpu as f64);
highest_cpu = f64::max(highest_cpu, new_cpu);
- sum_cpu += new_cpu;
+ squares_cpu += new_cpu.powi(2);
let new_mem = if index == target_index {
node.mem + service.maxmem
@@ -101,13 +101,13 @@ pub fn score_nodes_to_start_service(
} as f64
/ node.maxmem as f64;
highest_mem = f64::max(highest_mem, new_mem);
- sum_mem += new_mem;
+ squares_mem += new_mem.powi(2);
}
PveTopsisAlternative {
- average_cpu: sum_cpu / len as f64,
+ average_cpu: (squares_cpu / len as f64).sqrt(),
highest_cpu,
- average_memory: sum_mem / len as f64,
+ average_memory: (squares_mem / len as f64).sqrt(),
highest_memory: highest_mem,
}
.into()
--
2.30.2
More information about the pve-devel
mailing list