Am 8/12/19 um 3:21 PM schrieb Dominik Csapak: > i just benchmarked a cached stat version vs. not cached
Thanks. > 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') OK, as expected, but good to have it backed up by numbers. > so i would say we use the stat approach? OK for me. > or are you preferring saving the version into a file? Seems like a bit more things to do, your solution for stat looks good, so I would go with that one. Thanks! _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel