From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id B94881FF0B2 for ; Tue, 22 Sep 2026 08:19:25 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 190C1214C5; Tue, 22 Sep 2026 08:19:25 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 22 Sep 2026 08:18:59 +0200 Message-Id: Subject: Re: [PATCH ha-manager 3/7] manager: auto rebalance: require a minimum absolute imbalance improvement From: "Dominik Rusovac" To: "Michael Ryom" , X-Mailer: aerc 0.20.0 References: <20260920162220.574802-1-Michael@RyomHerold.dk> <20260920162220.574802-4-Michael@RyomHerold.dk> In-Reply-To: <20260920162220.574802-4-Michael@RyomHerold.dk> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1790057939789 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.150 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: JBXJWIOE72F4M5OEWJ3KOWZM46ZEYZJO X-Message-ID-Hash: JBXJWIOE72F4M5OEWJ3KOWZM46ZEYZJO X-MailFrom: d.rusovac@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: thanks for all the helpful details in the related report [0]! see comments inline=20 [0]: https://bugzilla.proxmox.com/show_bug.cgi?id=3D8059 On Sun Sep 20, 2026 at 6:22 PM CEST, Michael Ryom wrote: > The automatic load balancer only requires a relative improvement of the > node imbalance (default 10%). When a single resource dominates the > cluster load, the relative margin provides almost no hysteresis: with > two nodes, a resource load v and a node base load difference d, the > relative improvement of moving the resource is 2d / (v + d), so it > exceeds a margin m as soon as d > v * m / (2 - m). For a mid-size VM > that is a base load difference of about half a percentage point, well > within the normal fluctuation of e.g. the ZFS ARC or Ceph daemons, and > each fluctuation then qualifies a motion (and, after it was carried > out, its reverse). > > Additionally require the imbalance improvement to exceed a minimum > absolute value of 5 percentage points. This creates a dead band for > motions that shuffle load without meaningfully improving the cluster > balance. No expected motion of an existing regression test is affected; > the smallest occurring improvement there is 9.6 percentage points. > thanks for unveiling this! the math deriving d > v * m / (2 - m) in [0] checks out TL;DR: in the given scenario the load-heavy resource keeps getting migrated back and forth between the two nodes, because the load balancer's decisions are triggered by background noise in d, rather than by a genuine change in the cluster's load imbalance that the relative margin m is meant to filter for to me, checking that the imbalance improvement exceeds an "absolute" margin appears to be a good way of guarding against this issue > Like the backoff and cooldown constants, this could be exposed as a > ha-auto-rebalance-* option later. rather than using a constant, I'd expose this as an ha-auto-rebalance option right away. I'd suggest using 0.0 as the default value, meaning this kind of protection is disabled by default [snip]=20 > > diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm > index 30b9ae2..2c4c273 100644 > --- a/src/PVE/HA/Manager.pm > +++ b/src/PVE/HA/Manager.pm > @@ -151,6 +151,13 @@ my $auto_rebalance_failure_backoff_max =3D 3600; > # minimum time before a resource is considered for rebalancing again aft= er it > # was successfully moved by the load balancer > my $auto_rebalance_resource_cooldown =3D 600; > +# minimum absolute improvement of the node imbalance for a rebalance mot= ion; > +# the relative margin alone provides almost no hysteresis when a single > +# resource dominates the cluster load: with two nodes, a resource load v= and > +# a node base load difference d, the relative improvement of a motion is > +# 2d / (v + d), so for large v tiny fluctuations of d around zero are en= ough > +# to make the motion (and afterwards its reverse) qualify > +my $auto_rebalance_min_imbalance_improvement =3D 0.05; > =20 > my $is_on_rebalance_cooldown =3D sub { > my ($self, $sid, $now) =3D @_; > @@ -387,6 +394,7 @@ sub load_balance { > =20 > my $relative_change =3D ($imbalance - $target_imbalance) / $imbalanc= e; > return if $relative_change < $margin; > + return if ($imbalance - $target_imbalance) < $auto_rebalance_min_imb= alance_improvement; nit: factor out the absolute change and reuse it my $absolute_change =3D $imbalance - $target_imbalance; my $relative_change =3D $absolute_change / $imbalance; return if $relative_change < $margin; return if $absolute_change < $auto_rebalance_min_imbalance_improveme= nt; [snip] > diff --git a/src/test/test-crs-dynamic-auto-rebalance7/README b/src/test/= test-crs-dynamic-auto-rebalance7/README > new file mode 100644 > index 0000000..488a018 > --- /dev/null > +++ b/src/test/test-crs-dynamic-auto-rebalance7/README > @@ -0,0 +1,12 @@ > +Test that the auto rebalance system does not act on a rebalance motion w= hose > +absolute improvement of the node imbalance is below the minimum, even th= ough > +the relative improvement exceeds the configured margin. > + > +The cluster has two nodes with a HA resource excluded from auto rebalanc= ing > +on each (vm:100 on node1 and vm:200 on node2) acting as node base loads,= and > +one movable HA resource vm:101 on node1. The imbalance is 35.6% and stay= s > +above the default trigger threshold of 30%, and migrating vm:101 to node= 2 > +would improve the imbalance to 31.1%, i.e. by 12.5% relative, which exce= eds > +the default margin of 10%. However, the absolute improvement of 4.4 > +percentage points is below the required minimum of 5 percentage points, = so > +the motion must not be issued. the numbers check out thx for adding a test right away! [snip]