X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=examples%2Fperftest.pl.in;h=022a954473a8270b37d320d7a3c04218144d4ffc;hp=312ca5781795096fac0ef329fff5db65f9152530;hb=efd1e552c995d417113ab843edbc9f2974eeb20d;hpb=264a94560ae83c638e05b0b93b85fd6285b07dac diff --git a/examples/perftest.pl.in b/examples/perftest.pl.in index 312ca57..022a954 100755 --- a/examples/perftest.pl.in +++ b/examples/perftest.pl.in @@ -7,188 +7,41 @@ # #makes programm work AFTER install -use lib qw( @prefix@/lib/perl ); +my $Chunk = shift @ARGV || 10000; + +use lib qw( ../bindings/perl-shared/blib/lib ../bindings/perl-shared/blib/arch @prefix@/lib/perl ); print < Update RRD file, Sync -sub create($$){ - my $file = shift; - my $time = shift; - my $start = time; #since we loaded HiRes - RRDs::create ( $file.".rrd", "-b$time", qw( - -s300 - DS:in:GAUGE:400:U:U - DS:out:GAUGE:400:U:U - RRA:AVERAGE:0.5:1:600 - RRA:AVERAGE:0.5:6:600 - RRA:MAX:0.5:6:600 - RRA:AVERAGE:0.5:24:600 - RRA:MAX:0.5:24:600 - RRA:AVERAGE:0.5:144:600 - RRA:MAX:0.5:144:600 - )); - my $total = time - $start; - my $error = RRDs::error; - die $error if $error; - return $total; -} - -sub update($$){ - my $file = shift; - my $time = shift; - my $in = rand(1000); - my $out = rand(1000); - my $start = time; - my $ret = RRDs::updatev($file.".rrd", $time.":$in:$out"); -# print join("",map {" $_ " . $ret->{$_}."\n" } grep /AVERAGE.\[1\]/, sort keys %$ret)."\n** $time\n\n"; - # sync updates to disk immediately -# usleep(1) if (rand(3) <1 ); - my $total = time - $start; - my $error = RRDs::error; - die $error if $error; - return $total; -} +3) goto 1) -sub tune($){ - my $file = shift; - my $start = time; - RRDs::tune ($file.".rrd", "-a","in:U","-a","out:U","-d","in:GAUGE","-d","out:GAUGE"); - my $total = time - $start; - my $error = RRDs::error; - die $error if $error; - return $total; -} +The numbers at the start of the row, show which +RRA is being updated. So if several RRAs are being updated, +you should see a slowdown as data has to be read from disk. -sub infofetch($){ - my $file = shift; - my $start = time; - my $info = RRDs::info ($file.".rrd"); - my $error = RRDs::error; - die $error if $error; - my $lasttime = $info->{last_update} - $info->{last_update} % $info->{step}; - my $fetch = RRDs::fetch ($file.".rrd",'AVERAGE','-s',$lasttime-1,'-e',$lasttime); - my $total = time - $start; - my $error = RRDs::error; - die $error if $error; - return $total; -} +The growning number in the second column shows how many RRD have been +updated ... If everything is in cache, the number will Jump to $Chunk almost +immediately. Then the system will seem to hang as 'sync' runs, to make sure +all data has been written to disk prior to the next perftest run. This may +not be 100% real-life, so you may want to remove the sync just for fun +(then it is even less real-life, but different) -sub stddev ($$$){ #http://en.wikipedia.org/wiki/Standard_deviation - my $sum = shift; - my $squaresum = shift; - my $count = shift; - return sqrt( 1 / $count * ( $squaresum - $sum*$sum / $count )) -} - -sub makerrds($$$$){ - my $count = shift; - my $total = shift; - my $list = shift; - my $time = shift; - my @files; - for (1..$count){ - my $id = sprintf ("%07d",$total); - $id =~ s/^(.)(.)(.)(.)(.)//; - push @$list, "$1/$2/$3/$4/$5/$id"; - -d "$1" or mkdir "$1"; - -d "$1/$2" or mkdir "$1/$2"; - -d "$1/$2/$3" or mkdir "$1/$2/$3"; - -d "$1/$2/$3/$4" or mkdir "$1/$2/$3/$4"; - -d "$1/$2/$3/$4/$5" or mkdir "$1/$2/$3/$4/$5"; - push @files, $list->[$total]; - create $list->[$total++],$time-2; - print STDERR "."; - } - for (@files){ - my $fd = new IO::File("$_.rrd","r"); - if (defined $fd) { - $fd->sync; - $fd->close; - } else { - warn "failed to sync $_\n"; - } - } - return $count; -} - - -sub main (){ - mkdir "db-$$" or die $!; - chdir "db-$$"; - - my $step = 100000; # number of rrds to creat for every round - - my @path; - my $time=int(time); - - my $tracksize = 0; - my $uppntr = 0; - - - my %squaresum = ( cr => 0, up => 0 ); - my %sum = ( cr => 0, up => 0 ); - my %count =( cr => 0, up => 0 ); - - my $printtime = time; - while (1) { - # enhance the track - $time += 300; - $tracksize += makerrds $step,$tracksize,\@path,$time; - # run benchmark - for (0..10){ - $time += 300; - my $count = 0; - my $sum = 0; - my $squaresum = 0; - for (my $i = 0; $i<$tracksize;$i ++){ - my $elapsed = update($path[$i],$time); - $sum += $elapsed; - $squaresum += $elapsed**2; - $count++; - }; -# for (my $i = 0; $i<$tracksize;$i ++){ -# my $fh = new IO::File "$path[$i].rrd","r"; -# if (defined $fh) { -# $fh->sync; -# $fh->close; -# } else { -# warn "failed to sync $path[$i]\n"; -# } -# } - my $ups = $count/$sum; - my $sdv = stddev($sum,$squaresum,$count); - printf STDERR "%4d %6.0f Up/s (%6.5f sdv)\n",$count,$ups,$sdv; - } - print STDERR "\n"; - exit ; - } -} +NOTE -main; use strict; use Time::HiRes qw(time); use RRDs; @@ -224,9 +77,6 @@ sub update($$){ my $out = rand(1000); my $start = time; my $ret = RRDs::updatev($file.".rrd", $time.":$in:$out"); -# print join("",map {" $_ " . $ret->{$_}."\n" } grep /AVERAGE.\[1\]/, sort keys %$ret)."\n** $time\n\n"; - # sync updates to disk immediately -# usleep(1) if (rand(3) <1 ); my $total = time - $start; my $error = RRDs::error; die $error if $error; @@ -270,6 +120,7 @@ sub makerrds($$$$){ my $list = shift; my $time = shift; my @files; + my $now = int(time); for (1..$count){ my $id = sprintf ("%07d",$total); $id =~ s/^(.)(.)(.)(.)(.)//; @@ -281,26 +132,19 @@ sub makerrds($$$$){ -d "$1/$2/$3/$4/$5" or mkdir "$1/$2/$3/$4/$5"; push @files, $list->[$total]; create $list->[$total++],$time-2; - print STDERR "."; - } - for (@files){ - my $fd = new IO::File("$_.rrd","r"); - if (defined $fd) { - $fd->sync; - $fd->close; - } else { - warn "failed to sync $_\n"; - } + if ($now < int(time)){ + $now = int(time); + print STDERR "Creating RRDs: ", $count - $_," rrds to go. \r"; + } } return $count; } - - + sub main (){ mkdir "db-$$" or die $!; chdir "db-$$"; - my $step = 200000; # number of rrds to creat for every round + my $step = $Chunk; # number of rrds to creat for every round my @path; my $time=int(time); @@ -314,37 +158,56 @@ sub main (){ my %count =( cr => 0, up => 0 ); my $printtime = time; - while (1) { + my %step; + for (qw(1 6 24 144)){ + $step{$_} = int($time / 300 / $_); + } + + for (0..2) { # enhance the track - $time += 300; + $time += 300; $tracksize += makerrds $step,$tracksize,\@path,$time; # run benchmark - for (0..10){ + + for (0..50){ $time += 300; my $count = 0; my $sum = 0; my $squaresum = 0; + my $prefix = ""; + for (qw(1 6 24 144)){ + if (int($time / 300 / $_) > $step{$_}) { + $prefix .= "$_ "; + $step{$_} = int($time / 300 / $_); + } + else { + $prefix .= (" " x length("$_")) . " "; + } + } + my $now = int(time); for (my $i = 0; $i<$tracksize;$i ++){ - my $elapsed = update($path[$i],$time); + my $ntime = int(time); + if ($now < $ntime or $i == $tracksize){ + printf STDERR "$prefix %7d \r",$i; + $now = $ntime; + } + my $elapsed = update($path[$i],$time); $sum += $elapsed; $squaresum += $elapsed**2; $count++; }; -# for (my $i = 0; $i<$tracksize;$i ++){ -# my $fh = new IO::File "$path[$i].rrd","r"; -# if (defined $fh) { -# $fh->sync; -# $fh->close; -# } else { -# warn "failed to sync $path[$i]\n"; -# } -# } + my $startsync = time; + print STDERR 's'; + system "sync"; + print STDERR "\h"; + my $synctime = time-$startsync; + $sum += $synctime; + $squaresum += $synctime**2; my $ups = $count/$sum; my $sdv = stddev($sum,$squaresum,$count); - printf STDERR "%4d %6.0f Up/s (%6.5f sdv)\n",$count,$ups,$sdv; + printf STDERR "$prefix %7d %6.0f Up/s (%6.5f sdv)\n",$count,$ups,$sdv; } print STDERR "\n"; - exit ; } }