[pve-devel] [PATCH manager 2/4] ui: fix O(n^2) calculations when loading /cluster/resources
Dominik Csapak
d.csapak at proxmox.com
Fri Sep 5 13:52:00 CEST 2025
when we fetch the cluster resources, the ui calculates some fields for
each resource, such as 'hostmem_usage'. This requires the maxmem
attribute from the host which we have to look up in the resource store.
Since the data is not sorted in the store itself, extjs linearly goes
through the records to make the lookup when we use 'findExact'.
So instead of using findExact for every guest (which iterates the whole
resource store again), use a 'nodeCache' there and clear it out before
we load the new data.
This reduces the total time used for 'cacluate_hostmem_usage'
in my test setup (~10000 non-running vms) from 4,408.2 ms to 12.4 ms.
(Measured with the `Performance` tab in Chromium)
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
www/manager6/Utils.js | 12 ++++--------
www/manager6/data/ResourceStore.js | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 57a818f6..c48ee0b2 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1070,8 +1070,7 @@ Ext.define('PVE.Utils', {
return -1;
}
- var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node);
- var node = PVE.data.ResourceStore.getAt(index);
+ let node = PVE.data.ResourceStore.getNodeById(data.node);
if (!Ext.isDefined(node) || node === null) {
return -1;
}
@@ -1093,8 +1092,7 @@ Ext.define('PVE.Utils', {
return '';
}
- var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node);
- var node = PVE.data.ResourceStore.getAt(index);
+ let node = PVE.data.ResourceStore.getNodeById(record.data.node);
if (!Ext.isDefined(node) || node === null) {
return '';
}
@@ -1148,8 +1146,7 @@ Ext.define('PVE.Utils', {
return -1;
}
- var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node);
- var node = PVE.data.ResourceStore.getAt(index);
+ let node = PVE.data.ResourceStore.getNodeById(data.node);
if (!Ext.isDefined(node) || node === null) {
return -1;
@@ -1199,8 +1196,7 @@ Ext.define('PVE.Utils', {
return '';
}
- var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node);
- var node = PVE.data.ResourceStore.getAt(index);
+ let node = PVE.data.ResourceStore.getNodeById(record.data.node);
var maxmem = node.data.maxmem || 0;
if (record.data.mem > 1) {
diff --git a/www/manager6/data/ResourceStore.js b/www/manager6/data/ResourceStore.js
index d1f3fb63..bf740129 100644
--- a/www/manager6/data/ResourceStore.js
+++ b/www/manager6/data/ResourceStore.js
@@ -2,6 +2,8 @@ Ext.define('PVE.data.ResourceStore', {
extend: 'Proxmox.data.UpdateStore',
singleton: true,
+ nodeCache: {},
+
findVMID: function (vmid) {
let me = this;
return me.findExact('vmid', parseInt(vmid, 10)) >= 0;
@@ -21,6 +23,22 @@ Ext.define('PVE.data.ResourceStore', {
return nodes;
},
+ getNodeById: function (id) {
+ let me = this;
+
+ if (!me.nodeCache[id]) {
+ let idx = me.findExact('id', `node/${id}`);
+ me.nodeCache[id] = me.getAt(idx);
+ }
+
+ return me.nodeCache[id];
+ },
+
+ clearCache: function () {
+ let me = this;
+ me.nodeCache = {};
+ },
+
storageIsShared: function (storage_path) {
let me = this;
@@ -372,5 +390,7 @@ Ext.define('PVE.data.ResourceStore', {
});
me.callParent([config]);
+
+ me.on('beforeload', me.clearCache, me);
},
});
--
2.47.2
More information about the pve-devel
mailing list