public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Michael Ryom <Michael@RyomHerold.dk>
To: pve-devel@lists.proxmox.com
Cc: Michael Ryom <Michael@RyomHerold.dk>
Subject: [PATCH ha-manager 5/7] sim: hardware: allow setting a base load for nodes
Date: Sun, 20 Sep 2026 18:22:12 +0200	[thread overview]
Message-ID: <20260920162220.574802-6-Michael@RyomHerold.dk> (raw)
In-Reply-To: <20260920162220.574802-1-Michael@RyomHerold.dk>

The dynamic node usage stats of the simulated hardware only consisted
of the usage of the running HA-managed services. On a real cluster, the
node usage additionally contains everything else running on the node:
non-HA guests, storage daemons like Ceph or the ZFS ARC, and other host
processes, which fluctuate independently of the HA-managed services.

Read an optional base load ('cpu' and 'mem') for each node from the
hardware status and add a hardware command

    node <node> set-dynamic-stats [cpu <cores>] [mem <MiB>]

to change it during a test, so that regression tests can simulate load
that cannot be attributed to any HA-managed service.

Signed-off-by: Michael Ryom <Michael@RyomHerold.dk>
---
 src/PVE/HA/Sim/Hardware.pm | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index 538bc4e..aa1a886 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -791,6 +791,7 @@ sub get_cfs_state {
 #   crm enable-node-maintenance <node>
 #   crm disable-node-maintenance <node>
 #   pve-manager-version <node> set <version>   # note: this is NOT the *ha*-manager version
+#   node <node> set-dynamic-stats [cpu <cores>] [mem <MiB>]  # load outside HA services
 #   reboot <node>
 #   shutdown <node>
 #   restart-lrm <node>
@@ -881,6 +882,26 @@ sub sim_hardware_cmd {
 
             $self->write_hardware_status_nolock($cstatus);
 
+        } elsif ($cmd eq 'node') {
+            die "sim_hardware_cmd: unknown node action '$action'"
+                if $action ne 'set-dynamic-stats';
+            die "sim_hardware_cmd: missing target stat for '$action' command"
+                if !@params;
+
+            my $conversions = { cpu => sub { 0.0 + $_[0] }, mem => sub { $_[0] * 1024**2 } };
+
+            for my ($target, $val) (@params) {
+                die "sim_hardware_cmd: missing value for '$action $target' command"
+                    if !defined($val);
+
+                my $convert = $conversions->{$target}
+                    or die "sim_hardware_cmd: unknown target stat '$target' for '$action' command";
+
+                $cstatus->{$node}->{$target} = $convert->($val);
+            }
+
+            $self->write_hardware_status_nolock($cstatus);
+
         } elsif ($cmd eq 'cfs') {
             die "sim_hardware_cmd: unknown cfs action '$action' for node '$node'"
                 if $action !~ m/^(rw|update)$/;
@@ -1281,18 +1302,21 @@ sub get_static_node_stats {
 sub get_dynamic_node_stats {
     my ($self) = @_;
 
+    my $cstatus = $self->read_hardware_status_nolock();
+
     my $stats = $self->get_static_node_stats();
     for my $node (keys %$stats) {
         $stats->{$node}->{maxcpu} = $stats->{$node}->{maxcpu} // $default_node_maxcpu;
-        $stats->{$node}->{cpu} = $stats->{$node}->{cpu} // 0.0;
+        # base load of the node outside of the HA-managed services, e.g.
+        # non-HA guests or other host processes
+        $stats->{$node}->{cpu} = $cstatus->{$node}->{cpu} // 0.0;
         $stats->{$node}->{maxmem} = $stats->{$node}->{maxmem} // $default_node_maxmem;
-        $stats->{$node}->{mem} = $stats->{$node}->{mem} // 0;
+        $stats->{$node}->{mem} = $cstatus->{$node}->{mem} // 0;
     }
 
     my $service_conf = $self->read_service_config();
     my $dynamic_service_stats = $self->get_dynamic_service_stats();
 
-    my $cstatus = $self->read_hardware_status_nolock();
     my $node_service_status = { map { $_ => $self->read_service_status($_) } keys %$cstatus };
 
     for my $sid (keys %$service_conf) {
-- 
2.47.3




  parent reply	other threads:[~2026-09-20 16:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 16:22 [PATCH ha-manager 0/7] auto rebalance: fix failure retry loop, oscillation and idle-cluster churn Michael Ryom
2026-09-20 16:22 ` [PATCH ha-manager 1/7] fix #8059: manager: auto rebalance: back off failed motions and add per-resource cooldown Michael Ryom
2026-09-20 16:22 ` [PATCH ha-manager 2/7] env: dynamic service stats: use host-side memory footprint of guests Michael Ryom
2026-09-21  9:18   ` Dominik Rusovac
2026-09-20 16:22 ` [PATCH ha-manager 3/7] manager: auto rebalance: require a minimum absolute imbalance improvement Michael Ryom
2026-09-20 16:22 ` [PATCH ha-manager 4/7] sim: hardware: report actual running state in cluster service stats Michael Ryom
2026-09-20 16:22 ` Michael Ryom [this message]
2026-09-20 16:22 ` [PATCH ha-manager 6/7] usage: dynamic: smooth the unaccounted node load Michael Ryom
2026-09-20 16:22 ` [PATCH ha-manager 7/7] manager: auto rebalance: only balance under actual node resource pressure Michael Ryom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260920162220.574802-6-Michael@RyomHerold.dk \
    --to=michael@ryomherold.dk \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal