1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 19:56:48 +00:00

perf(instances): a VM list reads only the VMs it shows

#394 read each host's states in one call and every domain's XML once,
for the title, memory and vCPUs. A user's list shows only their own VMs,
but it read the XML of every VM on those hosts: a user with two VMs on a
host of 300 made about 301 libvirt calls a list load, where the old
per-VM reads made 6.

get_domain_rows takes the UUIDs the list shows and reads only their XML;
the states still come in one call. The capacity reads every domain, as
before.
This commit is contained in:
catborise 2026-11-04 23:58:36 +03:00
parent 02d4d02757
commit 337063bf7b
5 changed files with 28 additions and 11 deletions

View file

@ -1098,13 +1098,16 @@ class wvmConnect(object):
return {dom.UUIDString(): [dom.name(), stats["state.state"]]
for dom, stats in self.wvm.getAllDomainStats(libvirt.VIR_DOMAIN_STATS_STATE)}
def get_domain_rows(self):
"""{uuid: (info, title)} of every domain, as the VM lists show them:
info in virDomainGetInfo's shape (state, max memory KiB, memory KiB,
vCPUs), the states in one call and the rest from each domain's live
XML, which the title needs anyway. A domain gone meanwhile is left out."""
def get_domain_rows(self, uuids=None):
"""{uuid: (info, title)} of every domain, or of those in uuids, as the
VM lists show them: info in virDomainGetInfo's shape (state, max
memory KiB, memory KiB, vCPUs), the states in one call and the rest
from each domain's live XML, which the title needs anyway. A domain
gone meanwhile is left out."""
rows = {}
for dom, stats in self.wvm.getAllDomainStats(libvirt.VIR_DOMAIN_STATS_STATE):
if uuids is not None and dom.UUIDString() not in uuids:
continue # a VM the list does not show: its XML is not read
try:
doc = etree.fromstring(dom.XMLDesc(0))
except libvirtError: