From: "Daniel Kral" <d.kral@proxmox.com>
To: "Fiona Ebner" <f.ebner@proxmox.com>,
"Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH qemu-server 1/1] config: only fetch necessary default values in get_derived_property helper
Date: Thu, 16 Oct 2025 11:07:47 +0200 [thread overview]
Message-ID: <DDJMMDTV4X36.27TN8Y2Q4Q5DY@proxmox.com> (raw)
In-Reply-To: <04c02890-b538-407a-bcf8-f35f5912e4ab@proxmox.com>
On Wed Oct 15, 2025 at 4:31 PM CEST, Fiona Ebner wrote:
> Am 30.09.25 um 4:20 PM schrieb Daniel Kral:
>> get_derived_property(...) is called in the semi-hot path of the HA
>> Manager's static load scheduler to retrieve the static stats of each VM.
>> As the defaults are only needed in certain cases and for a very small
>> subset of properties in the VM config, get those separately when needed.
>>
>> Signed-off-by: Daniel Kral <d.kral@proxmox.com>
>> ---
>> get_current_memory(...) is still quite costly here, because it calls
>> parse_memory(...), which calls
>> PVE::JSONSchema::parse_property_string(...), which adds up for many
>> guest configurations parsed in every manage(...) call, but this already
>> helps quite a lot.
>
> If this really is a problem, we could do our own parsing, i.e. returning
> the value if the property string starts with \d+ or current=\d+ and
> falling back to get_current_memory() if it doesn't. Of course also using
> the default from $memory_fmt if not set.
>
>>
>> src/PVE/QemuConfig.pm | 8 +++-----
>> src/PVE/QemuServer.pm | 6 ++++++
>> 2 files changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/src/PVE/QemuConfig.pm b/src/PVE/QemuConfig.pm
>> index d0844c4c..078c87e0 100644
>> --- a/src/PVE/QemuConfig.pm
>> +++ b/src/PVE/QemuConfig.pm
>> @@ -582,12 +582,10 @@ sub load_current_config {
>
> We could go a step further and save the three defaults we are interested
> in during module load into variables. Then you also save the hash
> accesses into $confdesc and $memory_fmt.
>
>> sub get_derived_property {
>> my ($class, $conf, $name) = @_;
>>
>> - my $defaults = PVE::QemuServer::load_defaults();
>> -
>> if ($name eq 'max-cpu') {
>> - my $cpus =
>> - ($conf->{sockets} || $defaults->{sockets}) * ($conf->{cores} || $defaults->{cores});
>> - return $conf->{vcpus} || $cpus;
>> + my $sockets = $conf->{sockets} || PVE::QemuServer::get_default_property_value('sockets');
>> + my $cores = $conf->{cores} || PVE::QemuServer::get_default_property_value('cores');
>> + return $conf->{vcpus} || ($sockets * $cores);
>> } elsif ($name eq 'max-memory') { # current usage maximum, not maximum hotpluggable
>> return get_current_memory($conf->{memory}) * 1024 * 1024;
>> } else {
>
> Question is, how much do we really need to optimize the function here?
> I'm not against it, but just want to note that looking at the static
> usage will always have its limitations in practice (independent of
> performance). With PSI-based usage, we should only need the static
> information for to-be-started or to-be-recovered guests rather than all,
> so performance of get_derived_property() becomes much less relevant. Or
> what do you think?
That's a good point, in that regard I definitely favor maintainability
over minor performance improvements here. The (one-time) profile of
9,000 HA resources being balanced on start with all patches applied
(except ha #9) shows the following runtimes:
+---------------------------------------------+------------+------------+
| Function | Excl. time | Incl. time |
+---------------------------------------------+------------+------------+
| PVE::HA::Resources::PVEVM::get_static_stats | 55 ms | 437 ms |
| PVE::QemuConfig::get_derived_property | 40 ms | 363 ms |
| PVE::QemuServer::Memory::get_current_memory | 23 ms | 340 ms |
| PVE::QemuServer::Memory::parse_memory | 22 ms | 317 ms |
| PVE::JSONSchema::parse_property_string | 94 ms | 223 ms |
+---------------------------------------------+------------+------------+
parse_property_string does show up as the 6th highest-exclusive-runtime
function, but my main objective was that that `manage(...)` should
finish under ~10 seconds for ~10,000 HA resources. That should be doable
now, especially as the amount of calls to get_static_usage(...) is now
constant per manage(...) call instead of proportional to the amount of
HA resource state changes.
So let's stay with the current patch unless there are actually people
running into this..
By the way, the highest-exclusive-runtime function in that profile is
Sys::Syslog::syslog now (excluding CORE::sleep of course) ;). But since
that should happen only in very special cases, I don't think that's an
actual performance problem either.
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-10-16 9:08 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 14:19 [pve-devel] [RFC ha-manager/perl-rs/proxmox/qemu-server 00/12] Granular online_node_usage accounting Daniel Kral
2025-09-30 14:19 ` [pve-devel] [PATCH qemu-server 1/1] config: only fetch necessary default values in get_derived_property helper Daniel Kral
2025-10-15 14:31 ` Fiona Ebner
2025-10-16 9:07 ` Daniel Kral [this message]
2025-09-30 14:19 ` [pve-devel] [PATCH proxmox 1/1] resource-scheduling: change score_nodes_to_start_service signature Daniel Kral
2025-09-30 14:19 ` [pve-devel] [PATCH perl-rs 1/1] pve-rs: resource_scheduling: allow granular usage changes Daniel Kral
2025-10-16 10:32 ` Fiona Ebner
2025-10-16 15:34 ` Daniel Kral
2025-10-17 10:55 ` Fiona Ebner
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 1/9] implement static service stats cache Daniel Kral
2025-10-16 11:12 ` Fiona Ebner
2025-10-16 15:15 ` Daniel Kral
2025-10-17 10:02 ` Fiona Ebner
2025-10-17 10:08 ` Fiona Ebner
2025-10-17 16:18 ` Daniel Kral
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 2/9] manager: remove redundant recompute_online_node_usage from next_state_recovery Daniel Kral
2025-10-16 11:25 ` Fiona Ebner
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 3/9] manager: remove redundant add_service_usage_to_node " Daniel Kral
2025-10-16 11:33 ` Fiona Ebner
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 4/9] manager: remove redundant add_service_usage_to_node from next_state_started Daniel Kral
2025-10-16 11:39 ` Fiona Ebner
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 5/9] rules: resource affinity: decouple get_resource_affinity helper from Usage class Daniel Kral
2025-10-17 11:14 ` Fiona Ebner
2025-10-17 15:46 ` Daniel Kral
2025-10-20 15:18 ` Fiona Ebner
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 6/9] manager: make recompute_online_node_usage use get_service_nodes helper Daniel Kral
2025-10-17 11:25 ` Fiona Ebner
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 7/9] usage: allow granular changes to Usage implementations Daniel Kral
2025-10-17 11:57 ` Fiona Ebner
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 8/9] manager: make online node usage computation granular Daniel Kral
2025-10-17 12:32 ` Fiona Ebner
2025-10-17 16:07 ` Daniel Kral
2025-09-30 14:19 ` [pve-devel] [PATCH ha-manager 9/9] manager: make service node usage computation more granular Daniel Kral
2025-10-17 12:42 ` Fiona Ebner
2025-10-17 15:59 ` Daniel Kral
2025-10-20 16:50 ` [pve-devel] superseded: [RFC ha-manager/perl-rs/proxmox/qemu-server 00/12] Granular online_node_usage accounting Daniel Kral
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=DDJMMDTV4X36.27TN8Y2Q4Q5DY@proxmox.com \
--to=d.kral@proxmox.com \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox