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 D234E1FF138 for ; Mon, 20 Jul 2026 14:39:37 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 10287216A3; Mon, 20 Jul 2026 14:38:17 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Subject: [PATCH ha-manager 16/16] lrm: prune non-existent HA resources from results once per work iteration Date: Mon, 20 Jul 2026 14:37:05 +0200 Message-ID: <20260720123705.216089-17-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260720123705.216089-1-d.kral@proxmox.com> References: <20260720123705.216089-1-d.kral@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1784551006705 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.237 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_LOW -0.7 Sender listed at https://www.dnswl.org/, low 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: DH6O2B2PUDXRI6EVUJLJLF5LCJ7LNVHG X-Message-ID-Hash: DH6O2B2PUDXRI6EVUJLJLF5LCJ7LNVHG X-MailFrom: d.kral@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: The $self->{service_status_uids} property is updated once per work iteration. This makes the pruning and re-creation of the $self->{results} hash on every resource command completion in resource_command_finished() unnecessary. In a test startup of 768 HA resources on a single node at the same time showed a ~21.8 speedup for resource_command_finished(). +---------------------------+---------------+--------------+ | Subroutine | Before Change | After Change | +---------------------------+---------------+--------------+ | check_active_workers | 4.09ms | 998µs | | resource_command_finished | 1.09ms | 50µs | +---------------------------+---------------+--------------+ The profiling was done on a physical host with Devel::NYTProf 6.14 [0]. [0] https://metacpan.org/pod/Devel::NYTProf Signed-off-by: Daniel Kral --- src/PVE/HA/LRM.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm index 911672cb..41a925ff 100644 --- a/src/PVE/HA/LRM.pm +++ b/src/PVE/HA/LRM.pm @@ -199,6 +199,15 @@ sub flush_lrm_status { return 0 if !$haenv->quorate(); + # remove results from non-existing HA resources just before writing it out + # to prevent persisting any leftover LRM results + my $results = {}; + for my $id (keys $self->{results}->%*) { + next if !$self->{service_status_uids}->{$id}; + $results->{$id} = $self->{results}->{$id}; + } + $self->{results} = $results; + my $lrm_status = { state => $self->{status}->{state}, mode => $self->{mode}, @@ -890,13 +899,6 @@ sub resource_command_finished { state => $w->{state}, exit_code => $exit_code, }; - - my $results = {}; - foreach my $id (keys %{ $self->{results} }) { - next if !$self->{service_status_uids}->{$id}; - $results->{$id} = $self->{results}->{$id}; - } - $self->{results} = $results; } # processes the exit code from a finished resource agent, so that the CRM knows -- 2.47.3