all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC ha-manager 1/3] resources: get static stats: add cache parameter
Date: Fri, 18 Nov 2022 12:32:21 +0100	[thread overview]
Message-ID: <20221118113223.49305-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20221118113223.49305-1-f.ebner@proxmox.com>

so callers can avoid the overhead from load_config() if they already
have the required information.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/HA/Resources.pm       | 2 +-
 src/PVE/HA/Resources/PVECT.pm | 4 ++--
 src/PVE/HA/Resources/PVEVM.pm | 5 +++--
 src/PVE/HA/Sim/Resources.pm   | 2 +-
 4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/PVE/HA/Resources.pm b/src/PVE/HA/Resources.pm
index 7ba90f6..ee8de52 100644
--- a/src/PVE/HA/Resources.pm
+++ b/src/PVE/HA/Resources.pm
@@ -162,7 +162,7 @@ sub remove_locks {
 }
 
 sub get_static_stats {
-    my ($class, $haenv, $id, $service_node) = @_;
+    my ($class, $haenv, $id, $service_node, $cache) = @_;
 
     die "implement in subclass";
 }
diff --git a/src/PVE/HA/Resources/PVECT.pm b/src/PVE/HA/Resources/PVECT.pm
index e77d98c..c10d024 100644
--- a/src/PVE/HA/Resources/PVECT.pm
+++ b/src/PVE/HA/Resources/PVECT.pm
@@ -153,9 +153,9 @@ sub remove_locks {
 }
 
 sub get_static_stats {
-    my ($class, $haenv, $id, $service_node) = @_;
+    my ($class, $haenv, $id, $service_node, $cache) = @_;
 
-    my $conf = PVE::LXC::Config->load_config($id, $service_node);
+    my $conf = $cache->{$id} ||= PVE::LXC::Config->load_config($id, $service_node);
 
     return {
 	maxcpu => $conf->{cpulimit} || $conf->{cores} || 0,
diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index f405d86..ca7fbc4 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -176,9 +176,10 @@ sub remove_locks {
 }
 
 sub get_static_stats {
-    my ($class, $haenv, $id, $service_node) = @_;
+    my ($class, $haenv, $id, $service_node, $cache) = @_;
+
+    my $conf = $cache->{$id} ||= PVE::QemuConfig->load_config($id, $service_node);
 
-    my $conf = PVE::QemuConfig->load_config($id, $service_node);
     my $defaults = PVE::QemuServer::load_defaults();
 
     my $cpus = ($conf->{sockets} || $defaults->{sockets}) * ($conf->{cores} || $defaults->{cores});
diff --git a/src/PVE/HA/Sim/Resources.pm b/src/PVE/HA/Sim/Resources.pm
index e6e1853..999a77a 100644
--- a/src/PVE/HA/Sim/Resources.pm
+++ b/src/PVE/HA/Sim/Resources.pm
@@ -140,7 +140,7 @@ sub remove_locks {
 }
 
 sub get_static_stats {
-    my ($class, $haenv, $id, $service_node) = @_;
+    my ($class, $haenv, $id, $service_node, $cache) = @_;
 
     my $sid = $class->type() . ":$id";
     my $hardware = $haenv->hardware();
-- 
2.30.2





  reply	other threads:[~2022-11-18 11:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 11:32 [pve-devel] [RFC ha-manager] make static usage calculation faster Fiona Ebner
2022-11-18 11:32 ` Fiona Ebner [this message]
2022-11-18 11:32 ` [pve-devel] [RFC ha-manager 2/3] env: add get_static_guest_stats method Fiona Ebner
2022-11-18 11:32 ` [pve-devel] [RFC ha-manager 3/3] manager/usage: cache static service stats to avoid overhead Fiona Ebner

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=20221118113223.49305-2-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal