mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +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:
parent
37b87839c1
commit
2d0f41ee57
9 changed files with 130 additions and 104 deletions
|
|
@ -81,22 +81,25 @@ def index(request):
|
|||
computes = list(Compute.objects.all().order_by("name"))
|
||||
for compute in computes:
|
||||
utils.refr(compute)
|
||||
# each host's VMs by name: the database keeps no order of its own
|
||||
prefetch_related_objects(computes, Prefetch("instance_set", queryset=Instance.objects.order_by("name")),
|
||||
"instance_set__userinstance_set__user")
|
||||
|
||||
show_hosts = request.user.is_superuser or request.user.has_perm("instances.view_instances")
|
||||
own_hosts_down = False
|
||||
if show_hosts:
|
||||
instances = Instance.objects.order_by("name").prefetch_related("userinstance_set__user")
|
||||
if request.user.is_superuser and app_settings.VIEW_INSTANCES_LIST_STYLE == "grouped":
|
||||
# each host's VMs by name: the database keeps no order of its own
|
||||
prefetch_related_objects(computes, Prefetch("instance_set", queryset=Instance.objects.order_by("name")),
|
||||
"instance_set__userinstance_set__user")
|
||||
instances = [inst for compute in computes for inst in compute.instance_set.all()]
|
||||
elif show_hosts:
|
||||
instances = list(Instance.objects.order_by("name").prefetch_related("userinstance_set__user"))
|
||||
else:
|
||||
instances = Instance.objects.filter(
|
||||
instances = list(Instance.objects.filter(
|
||||
userinstance__user=request.user
|
||||
).order_by("name").prefetch_related("userinstance_set__user")
|
||||
).order_by("name").prefetch_related("userinstance_set__user"))
|
||||
# other users get no host names or connection errors, only whether
|
||||
# a host of their own VMs is down
|
||||
own = set(instances.values_list("compute_id", flat=True))
|
||||
own = {inst.compute_id for inst in instances}
|
||||
own_hosts_down = any(c.status is not True for c in computes if c.pk in own)
|
||||
utils.read_list_rows(instances)
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue