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

perf(computes): the host's info is read once per request

The overview read the host's info four times, now once (12 libvirt calls).
A connection object keeps it next to the capabilities, and the VM page and
VM stats take it from there; the VM page's cached_reads block holds only
the VM's own data. Free memory is still read each time.
This commit is contained in:
catborise 2026-10-09 15:52:11 +03:00
parent 9adc808d26
commit 57f592df70
6 changed files with 57 additions and 32 deletions

View file

@ -1,7 +1,7 @@
"""wvmInstance.cached_reads(): inside the block the domain XML (per flags),
the VM's state, the host info and each disk's volume are read from libvirt
once; outside it every read goes to libvirt, as code that changes the VM
needs. The host capabilities are read once per object."""
the VM's state and each disk's volume are read from libvirt once; outside it
every read goes to libvirt, as code that changes the VM needs. The host's
info and capabilities are read once per object."""
import unittest
from unittest.mock import MagicMock
@ -60,20 +60,17 @@ class CachedReadsTestCase(unittest.TestCase):
p = proxy()
p._XMLDesc(0)
p._XMLDesc(0)
p._host_info()
p._host_info()
self.assertEqual((p.instance.reads, p.wvm.caps), ([0, 0], 2))
p.get_status()
p.get_status()
self.assertEqual(p.instance.reads, [0, 0, "info", "info"])
def test_inside_the_block_each_flags_value_is_read_once(self):
p = proxy()
with p.cached_reads():
first = [p._XMLDesc(0), p._XMLDesc(1), p._XMLDesc(3)]
again = [p._XMLDesc(0), p._XMLDesc(1), p._XMLDesc(3)]
p._host_info()
p._host_info()
self.assertEqual(first, again)
self.assertEqual(p.instance.reads, [0, 1, 3])
self.assertEqual(p.wvm.caps, 1)
def test_the_block_ends_with_its_cache(self):
p = proxy()