]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/CLI/pmgperf.pm
1 package PMG
::CLI
::pmgperf
;
7 use Time
::HiRes
qw( usleep ualarm gettimeofday tv_interval );
8 use Net
::DNS
::Resolver
;
11 use PVE
::Tools
qw(extract_param);
15 use PMG
::RESTEnvironment
;
17 use base
qw(PVE::CLIHandler);
19 sub setup_environment
{
20 PMG
::RESTEnvironment-
>setup_default_cli_env();
25 # free pagecache,dentries,inode cache
26 if (-f
'/proc/sys/vm/drop_caches') {
27 system ("echo 3 > /proc/sys/vm/drop_caches");
34 open (TMP
, "/proc/cpuinfo");
36 while (my $line = <TMP
>) {
37 if ($line =~ m/^bogomips\s*:\s*(\d+\.\d+)\s*$/) {
44 printf "CPU BOGOMIPS: %.2f\n", $bogomips;
49 my $starttime = [gettimeofday
];
56 my $str = int(rand(1000000)) . time();
57 if ($str =~ m/(.+)123.?123/) {
59 $elapsed = tv_interval
($starttime);
64 printf "REGEX/SECOND: %d\n", $count;
72 my $dir = "$basedir/ptest.$$";
78 my $data = ('A' x
4000) . "\n";
80 my $starttime = [gettimeofday
];
85 for ($count=1;;$count++) {
88 my $filename = "$dir/tf_$m.dat";
90 open (TMP
, ">$filename") || die "open failed";
94 File
::Sync
::fsync
(\
*TMP
);
98 $elapsed = tv_interval
($starttime);
100 last if $elapsed > 3;
102 my $sps = $count /$elapsed; # fsync per second
104 printf "FSYNCS/SECOND: %.2f\n", $sps;
109 system ("rm -rf $dir");
115 my ($rootdev, $hdsize) = @_;
119 open (ROOTHD
, "<$rootdev") || die "unable to open HD";
121 my $starttime = [gettimeofday
];
126 for ($count=1;;$count++) {
128 my $pos = int (rand (int($hdsize/512))) * 512;
130 sysseek (ROOTHD
, $pos, 0);
132 (sysread (ROOTHD
, $readbuf, 512) == 512) || die "read failed";
134 $elapsed = tv_interval
($starttime);
136 last if $elapsed > 3;
141 my $rps = $count /$elapsed; # blocks per second
142 my $ast = (1000/$rps);
143 printf "AVERAGE SEEK TIME: %.2f ms\n", $ast;
151 my $starttime = [gettimeofday
];
157 open (ROOTHD
, "<$rootdev") || die "unable to open HD";
162 my $c = sysread (ROOTHD
, $readbuf, 2 * 1024 *1024);
163 die "read failed" if $c < 0;
167 $elapsed = tv_interval
($starttime);
169 last if $elapsed > 3;
174 my $bps = $bytes /($elapsed * 1024 * 1024); # MB per second
175 printf "BUFFERED READS: %.2f MB/sec\n", $bps;
179 my ($resolv, $dns) = @_;
181 if (my $a = $resolv->send ($dns, 'A')) {
182 foreach my $rra ($a->answer) {
183 if ($rra->type eq 'A') {
184 return $rra->address;
204 #$dnsargs{nameservers} = [ qw (208.67.222.222) ];
205 #$dnsargs{nameservers} = [ qw (127.0.0.1) ];
207 my $resolv = Net
::DNS
::Resolver-
>new (%dnsargs);
209 my $starttime = [gettimeofday
];
214 my $uid = time() . int(rand(1000000));
215 my $domain = "nonexistent$uid.com";
217 for ($count=1;;$count++) {
219 my $hid = int(rand(1000000));
220 my $hname = "test${hid}.$domain";
221 get_address
($resolv, $hname);
222 $elapsed = tv_interval
($starttime);
224 last if ($count > 100) || ($elapsed > 3);
227 printf "DNS EXT: %0.2f ms\n", ($elapsed * 1000)/$count;
229 my $resolv_conf = `cat /etc/resolv.conf`;
230 ($domain) = $resolv_conf =~ m/^search\s+(\S+)\s*$/mg;
233 $starttime = [gettimeofday
];
236 for ($count=1;;$count++) {
238 my $hid = int(rand(1000000));
239 my $hname = "test${hid}.$domain";
240 get_address
($resolv, $hname);
241 $elapsed = tv_interval
($starttime);
243 last if ($count > 100) || ($elapsed > 3);
246 printf "DNS INT: %0.2f ms (%s)\n",
247 ($elapsed * 1000)/ $count, $domain;
253 use base
qw(PVE::CLIHandler);
254 __PACKAGE__-
>register_method ({
258 description
=> "Proxmox benchmark.",
260 additionalProperties
=> 0,
263 description
=> "File system location to test.",
270 returns
=> { type
=> 'null'},
274 my $path = $param->{path
} // '/';
279 my $hd = `df -P '$path'`;
281 my ($rootdev, $hdo_total, $hdo_used, $hdo_avail) = $hd =~
282 m/^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+\S+\s+.*$/mg;
285 my $hdsize = $hdo_total*1024;
286 printf "HD SIZE: %.2f GB ($rootdev)\n", ($hdsize / (1024*1024*1024));
288 if ($rootdev =~ m
|^/dev/|) {
289 test_read
($rootdev);
291 test_seektime
($rootdev, $hdsize);
295 test_fsync
($path) if $hdo_avail;
302 our $cmddef = [ __PACKAGE__
, 'pmgperf', ['path']];