public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Aaron Lauterer <a.lauterer@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pve-devel] [PATCH manager 1/4] API2Tools: rrd: remove O(n^2) lookup for keys
Date: Fri, 5 Sep 2025 15:49:29 +0200	[thread overview]
Message-ID: <7fcdb7f7-9a30-4e3b-abcb-1971c2004f05@proxmox.com> (raw)
In-Reply-To: <20250905120627.2585826-2-d.csapak@proxmox.com>



On  2025-09-05  14:06, Dominik Csapak wrote:
> the idea was that we get any of the 'new' versions on lookup, but that
> lead to iterating through possibly all keys. Since that was called for
> each resource in e.g. /cluster/resources api call, the runtime was
> O(n^2) for the number of resources.
> 
> To avoid that, simply look up the currently only valid key here which
> makes this lookup much cheaper.
> 
> In my test setup with ~10000 guests, it reduces the time for a call
> to /cluster/resources from ~22s to ~400ms
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> NOTE: this is only a workaround and Aaron is working to making this
> whole part unnecessary, but for now i think this is a good stop-gap
> 
>   PVE/API2Tools.pm | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/PVE/API2Tools.pm b/PVE/API2Tools.pm
> index abe73fa2..863f5f55 100644
> --- a/PVE/API2Tools.pm
> +++ b/PVE/API2Tools.pm
> @@ -52,10 +52,9 @@ sub get_rrd_key {
>           return "pve2.3-${type}/${id}";
>       }
>   
> -    # if no old key has been found, we expect on in the newer format: pve-{type}-{version}/{id}
> -    # We accept all new versions, as the expectation is that they are only allowed to add new colums as non-breaking change
> -    for my $k (keys %$rrd) {
> -        return $k if $k =~ m/^pve-\Q${type}\E-\d\d?.\d\/\Q${id}\E$/;
> +    my $key = "pve-${type}-9.0/${id}";
> +    if (defined($rrd->{$key})) {
> +        return $key;

Have you tested this in a mixed PVE8 + PVE9 cluster? This might break it 
and we might have to keep the dynamic checking around.

I don't have too much time right now. But I think this would break a 
mixed version situation, e.g. during a cluster upgrade, where we receive 
both keys, pve2-... and pve-...-9.0 ones.

>       }
>   }
>   



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  reply	other threads:[~2025-09-05 13:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 11:51 [pve-devel] [PATCH manager 0/4] gui/api performance improvements Dominik Csapak
2025-09-05 11:51 ` [pve-devel] [PATCH manager 1/4] API2Tools: rrd: remove O(n^2) lookup for keys Dominik Csapak
2025-09-05 13:49   ` Aaron Lauterer [this message]
2025-09-05 13:53     ` Dominik Csapak
2025-09-05 13:58       ` Aaron Lauterer
2025-09-05 13:57   ` Daniel Kral
2025-09-05 11:52 ` [pve-devel] [PATCH manager 2/4] ui: fix O(n^2) calculations when loading /cluster/resources Dominik Csapak
2025-09-05 11:52 ` [pve-devel] [PATCH manager 3/4] ui: resource tree: improve performance on initial update Dominik Csapak
2025-09-05 11:52 ` [pve-devel] [PATCH manager 4/4] ui: resource tree: fix change detection Dominik Csapak
2025-09-05 17:40 ` [pve-devel] applied: [PATCH manager 0/4] gui/api performance improvements Thomas Lamprecht

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=7fcdb7f7-9a30-4e3b-abcb-1971c2004f05@proxmox.com \
    --to=a.lauterer@proxmox.com \
    --cc=d.csapak@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 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