[pve-devel] [PATCH qemu] add pve-api-updates trigger

Dominik Csapak d.csapak at proxmox.com
Mon Aug 12 15:21:18 CEST 2019


i just benchmarked a cached stat version vs. not cached
code is the following:

----8<----
use strict;
use warnings;
use utf8;

use Benchmark qw(cmpthese);
use PVE::Tools qw(run_command);

my $kvm_cache;
my $kvm_timestamp;

sub get_kvm_version {
     my $kvm_user_version = 'unknown';

     my $code = sub {
         my $line = shift;
         if ($line =~ m/^QEMU( PC)? emulator version 
(\d+\.\d+(\.\d+)?)(\.\d+)?[,\s]/) {
             $kvm_user_version = $2;
         }
     };

     eval { run_command("kvm -version", outfunc => $code); };
     warn $@ if $@;
     return $kvm_user_version;
}

cmpthese(-10, {
     cache => sub {
         my $mtime = (stat("/usr/bin/kvm"))[9];
         if (!$kvm_timestamp || !$kvm_cache || $kvm_timestamp < $mtime) {
             $kvm_timestamp = $mtime;
             $kvm_cache = get_kvm_version();
         }
         return $kvm_cache;
     },
     noncached => sub {
         return get_kvm_version();
     }
});
---->8----

result is:

               Rate noncached     cache
noncached   27.9/s        --     -100%
cache     696192/s  2490994%        -

so a single call to kvm --version takes ~35ms
(which i can confirm doing 'time kvm --version')

so i would say we use the stat approach?
or are you preferring saving the version into a file?




More information about the pve-devel mailing list