mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 12:16:49 +00:00
perf(instances): VM statistics sample all devices in one second
Each open VM page asks for its statistics every 10 seconds. For a running VM the stats view measured the CPU, then each disk, then each NIC, sleeping one second for each. With two disks and a NIC a request held a sync gunicorn worker for over 4 s, so a few dozen open VM pages could keep every worker busy. wvmInstance.usage() replaces cpu_usage, disk_usage and net_usage, the stats view's only callers: it reads all counters, sleeps one second once and reads them again. Values and units are unchanged (CPU percent of the host, disk bytes, network bits per second); compared against the previous methods on the same counters, the results are identical. Measured on the test host for a running VM with two disks and a NIC: the stats request took 4.1-4.3 s before, 1.1-1.3 s now. The new test fails on the previous code.
This commit is contained in:
parent
f3929b8e8f
commit
5bb3a545a0
3 changed files with 116 additions and 51 deletions
|
|
@ -236,10 +236,8 @@ def stats(request, pk):
|
|||
json_net = []
|
||||
|
||||
# TODO: stats are inaccurate
|
||||
cpu_usage = instance.proxy.cpu_usage()
|
||||
cpu_usage, blk_usage, net_usage = instance.proxy.usage()
|
||||
mem_usage = instance.proxy.mem_usage()
|
||||
blk_usage = instance.proxy.disk_usage()
|
||||
net_usage = instance.proxy.net_usage()
|
||||
|
||||
current_time = time.strftime("%H:%M:%S")
|
||||
for blk in blk_usage:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue