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 v2 06/14] manager: auto rebalance: add optional cooldown for moved resources
Date: Sun, 18 Oct 2026 14:45:50 +0200	[thread overview]
Message-ID: <20261018124559.24305-7-Michael@RyomHerold.dk> (raw)
In-Reply-To: <20261018124559.24305-1-Michael@RyomHerold.dk>

When a single resource dominates the cluster load, the relative
improvement of moving it between two nodes is 2d / (v + d), where v is
the load of the resource and d is the difference of the node base loads.
Small fluctuations of d around zero are enough to make a motion and,
right afterwards, its reverse qualify, so the resource is moved back and
forth (see bug #8059).

Add the ha-auto-rebalance-cooldown option, which keeps resources that
were successfully moved by the load balancer from being considered for
another rebalance motion for the given time. The cooldown applies to all
resources of a moved resource bundle, as they were all moved, and a
bundle is skipped if any of its resources is still on cooldown.

The cooldown defaults to 0, i.e. it is disabled and the behavior of
existing setups does not change.

Like the other auto rebalance state, the cooldown is not persisted
across a CRM failover.

The expected log of test-crs-dynamic-auto-rebalance7 changes, as vm:101
is not migrated back right after it was migrated, but only after the
configured cooldown of 600 seconds has expired.

Signed-off-by: Michael Ryom <Michael@RyomHerold.dk>
---
 src/PVE/HA/Manager.pm                         | 27 +++++++++++++++++++
 .../log.expect                                | 15 +++++------
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index 18ad12f..c480b73 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -91,6 +91,9 @@ sub new {
             # rebalance motions which failed $count times in a row, the last
             # time in rebalancing attempt $attempt
             failures => {},
+            # $sid => $time until which a resource successfully moved by
+            # load_balance() is not considered for rebalancing
+            cooldown => {},
         },
         group_migration_round => 3, # wait a little bit
     }, $class;
@@ -138,6 +141,7 @@ sub update_crs_scheduler_mode {
         // 3;
     $self->{crs}->{auto_rebalance}->{margin} =
         ($crs_cfg->{'ha-auto-rebalance-margin'} // 10) / 100.0;
+    $self->{crs}->{auto_rebalance}->{cooldown} = $crs_cfg->{'ha-auto-rebalance-cooldown'} // 0;
 
     my $old_mode = $self->{crs}->{scheduler};
     my $new_mode = $crs_cfg->{ha} || 'basic';
@@ -259,6 +263,10 @@ sub record_rebalance_motion_result {
     if ($success) {
         delete $state->{failures}->{$key};
         $state->{attempt_ongoing} = 0;
+
+        my $cooldown = $self->{crs}->{auto_rebalance}->{cooldown};
+        $state->{cooldown}->{$sid} = $self->{haenv}->get_time() + $cooldown if $cooldown > 0;
+
         return;
     }
 
@@ -277,6 +285,20 @@ sub record_rebalance_motion_result {
     $self->{haenv}->log('warning', $msg);
 }
 
+# Returns whether $sid was moved by load_balance() too recently to be considered
+# for rebalancing again.
+my sub is_on_rebalance_cooldown {
+    my ($self, $sid, $now) = @_;
+
+    my $cooldown = $self->{auto_rebalance_state}->{cooldown};
+    my $until = $cooldown->{$sid} // return 0;
+
+    return 1 if $now < $until;
+
+    delete $cooldown->{$sid};
+    return 0;
+}
+
 # Returns a hash of hashes, where each item contains the resource bundle's
 # leader, the list of HA resources in the resource bundle, and the list of
 # possible nodes to migrate to.
@@ -291,8 +313,13 @@ sub get_resource_migration_candidates {
     my $resource_bundles =
         get_active_stationary_movable_resource_bundles($ss, $sc, $resource_affinity);
 
+    my $now = $self->{haenv}->get_time();
+
     my @compact_migration_candidates = ();
     for my $leader_sid (sort keys %$resource_bundles) {
+        my $bundle = $resource_bundles->{$leader_sid};
+        next if grep { is_on_rebalance_cooldown($self, $_, $now) } @$bundle;
+
         my $current_leader_node = $ss->{$leader_sid}->{node};
         my $online_nodes = { map { $_ => 1 } $online_node_usage->list_nodes() };
 
diff --git a/src/test/test-crs-dynamic-auto-rebalance7/log.expect b/src/test/test-crs-dynamic-auto-rebalance7/log.expect
index c87f487..a82f4bc 100644
--- a/src/test/test-crs-dynamic-auto-rebalance7/log.expect
+++ b/src/test/test-crs-dynamic-auto-rebalance7/log.expect
@@ -38,13 +38,10 @@ info    103    node2/lrm: starting service vm:101
 info    103    node2/lrm: service status vm:101 started
 info    120      cmdlist: execute service vm:100 set-dynamic-stats cpu 0.96 mem 0
 info    120      cmdlist: execute service vm:200 set-dynamic-stats cpu 14.4 mem 0
-info    160    node1/crm: auto rebalance - migrate vm:101 to node1 (expected change for imbalance from 90.5% to 42.9%)
-info    160    node1/crm: got crm command: migrate vm:101 node1
-info    160    node1/crm: migrate service 'vm:101' to node 'node1'
-info    160    node1/crm: service 'vm:101': state changed from 'started' to 'migrate'  (node = node2, target = node1)
-info    163    node2/lrm: service vm:101 - start migrate to node 'node1'
-info    163    node2/lrm: service vm:101 - end migrate to node 'node1'
-info    180    node1/crm: service 'vm:101': state changed from 'migrate' to 'started'  (node = node1)
-info    181    node1/lrm: starting service vm:101
-info    181    node1/lrm: service status vm:101 started
+info    700    node1/crm: auto rebalance - migrate vm:101 to node1 (expected change for imbalance from 90.5% to 42.9%)
+info    700    node1/crm: got crm command: migrate vm:101 node1
+info    700    node1/crm: migrate service 'vm:101' to node 'node1'
+info    700    node1/crm: service 'vm:101': state changed from 'started' to 'migrate'  (node = node2, target = node1)
+info    703    node2/lrm: service vm:101 - start migrate to node 'node1'
+info    703    node2/lrm: service vm:101 - end migrate to node 'node1'
 info    720     hardware: exit simulation - done
-- 
2.47.3




  parent reply	other threads:[~2026-10-18 12:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-18 12:45 [PATCH cluster/ha-manager/manager/docs v2 00/14] auto rebalance: fix failure retry loop and oscillation Michael Ryom
2026-10-18 12:45 ` [PATCH cluster v2 01/14] datacenter config: add HA auto-rebalance margin mode and cooldown Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 02/14] manager: factor out checking whether a resource motion is queued or running Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 03/14] test: add auto rebalance test cases for failing rebalance motions Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 04/14] fix #8059: manager: auto rebalance: do not retry failed rebalance motions right away Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 05/14] test: add auto rebalance test case for an immediate reverse motion Michael Ryom
2026-10-18 12:45 ` Michael Ryom [this message]
2026-10-18 12:45 ` [PATCH ha-manager v2 07/14] test: add auto rebalance test case for a marginal absolute improvement Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 08/14] manager: auto rebalance: allow an absolute margin Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 09/14] sim: hardware: report actual running state in cluster service stats Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 10/14] sim: hardware: allow setting a base load for nodes Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 11/14] test: add auto rebalance test case for fluctuating node base loads Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 12/14] usage: dynamic: smooth the unaccounted node load Michael Ryom
2026-10-18 12:45 ` [PATCH manager v2 13/14] ui: crs options: expose the auto-rebalance margin mode and cooldown Michael Ryom
2026-10-18 12:45 ` [PATCH docs v2 14/14] ha-manager: document the auto-rebalance margin mode, cooldown and failed migrations 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=20261018124559.24305-7-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