[PATCH proxmox v3 07/40] resource-scheduling: compare by nodename in score_nodes_to_start_resource

Daniel Kral
2026-03-30T14:43:03Z

Even though comparing by index is slightly faster here, comparing by the
nodename makes factoring this out for an upcoming patch possible.

This should increase runtime only marginally as this is roughly bound by
the 2 * node_count * maximum_hostname_length.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
Reviewed-by: Dominik Rusovac <d.rusovac@proxmox.com>
---
changes v2 -> v3:
- none

proxmox-resource-scheduling/src/scheduler.rs | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/proxmox-resource-scheduling/src/scheduler.rs b/proxmox-resource-scheduling/src/scheduler.rs
index 0a27a25c..33ef4586 100644
--- a/proxmox-resource-scheduling/src/scheduler.rs
+++ b/proxmox-resource-scheduling/src/scheduler.rs
@@ -62,18 +62,17 @@ impl Scheduler {
let matrix = self
.nodes
.iter()
- .enumerate()
- .map(|(target_index, _)| {
+ .map(|node| {
// Base values on percentages to allow comparing nodes with different stats.
let mut highest_cpu = 0.0;
let mut squares_cpu = 0.0;
let mut highest_mem = 0.0;
let mut squares_mem = 0.0;

- for (index, node) in self.nodes.iter().enumerate() {
- let mut new_stats = node.stats;
+ for target_node in self.nodes.iter() {
+ let mut new_stats = target_node.stats;

- if index == target_index {
+ if node.name == target_node.name {
new_stats.add_started_resource(&resource_stats)
};

--
2.47.3