1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 04:06:47 +00:00

perf(instances): VM lists read each host once, not three calls a VM

A VM list row showed the VM's state, memory, vCPUs and title, read
through the VM's own connection object: a lookup by UUID, virDomainGetInfo
and the live XML, one after the other for every VM on the page.

The lists (Instances, grouped or not, and a compute's VMs) now read each
host once: the states in one getAllDomainStats call (the state group
only, as the lists' poll; no other group, so a VM busy in the QEMU
monitor holds nothing up) and the memory, vCPUs and title from each
VM's live XML, which the title already read. Checked on QEMU against
virDomainGetInfo for running, paused and shut-off VMs: the same values.

A VM gone from its host, or a host that cannot be read or fails its
listing, shows its VMs unknown as before. Only the grouped list, a
superuser's, prefetches every host's VMs and owners.
This commit is contained in:
catborise 2026-11-04 20:43:00 +03:00
parent 37b87839c1
commit 2d0f41ee57
9 changed files with 130 additions and 104 deletions

View file

@ -352,6 +352,20 @@ def record_migration(instance, new_compute):
instance.save()
def read_list_rows(instances):
"""Each VM's info and title for a VM list, read once a host
(get_domain_rows), not three calls a VM; a VM whose host or whose
domain cannot be read has no info: the list shows it unknown."""
rows = {}
for compute in {inst.compute_id: inst.compute for inst in instances}.values():
try:
rows[compute.pk] = compute.proxy.get_domain_rows() if compute.status is True else {}
except libvirtError:
rows[compute.pk] = {}
for inst in instances:
inst.info, inst.title = rows[inst.compute_id].get(inst.uuid, (None, ""))
def vm_states(user, computes):
"""{compute pk: {"ok": True, "vms": {uuid: [name, state]}}, or {"ok": False}
for a host that cannot be read}: what the VM lists poll, read from libvirt;