X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=examples%2Fperftest.pl.in;h=312ca5781795096fac0ef329fff5db65f9152530;hp=7a04220df1ccfb5fbf666ee2a63bbc4016805c6a;hb=264a94560ae83c638e05b0b93b85fd6285b07dac;hpb=fd78b70414d41ed431ca0e21a7c1aaec10658a8b diff --git a/examples/perftest.pl.in b/examples/perftest.pl.in index 7a04220..312ca57 100755 --- a/examples/perftest.pl.in +++ b/examples/perftest.pl.in @@ -13,24 +13,34 @@ print <{$_}."\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; +} + +sub tune($){ + my $file = shift; my $start = time; - RRDs::update ($file.".rrd", $time.":$in:$out"); + 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; +} + +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; @@ -67,86 +104,248 @@ sub stddev ($$$){ #http://en.wikipedia.org/wiki/Standard_deviation return sqrt( 1 / $count * ( $squaresum - $sum*$sum / $count )) } -mkdir "db-$$" or die $!; -chdir "db-$$"; - -my $totaldbs=10; -my $createddbs=0; -my %path; -my $time=time; -my $prevups; -my $over = 0; - -while (1) { - - # create ############################################################### - my $squaresum=0; - my $sum=0; - my $count=0; - - for(my $db=$createddbs;$db<$totaldbs;$db++){ - # make sure we do not get bitten by - # expensive directory searches - # store 100 rrds per directory. - my $id = sprintf ("%06d",$db); - $id =~ s/^(.)(.)(.)(.)//; - $path{$db}="$1/$2/$3/$4/$id"; +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-$$"; - $createddbs=$db+1; + my $step = 100000; # number of rrds to creat for every round + + my @path; + my $time=int(time); - my $total = create $path{$db}; - $sum += $total; - $squaresum += $total*$total; - $count++; - } - printf STDERR "Create %6d rrds %6d c/s (%6.5f sdv)",$count,$count/$sum,stddev($sum,$squaresum,$count); - - # update ################################################################# - - $squaresum=0; - $sum=0; - $count=0; - my $now = time; - while(1){ - for(my $db=0;$db<$totaldbs;$db++){ - my $total = update($path{$db},$time); - $sum += $total; - $squaresum += $total*$total; - $count++; + 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; } - $time += 300; - last if time - $now > 5; # stop testing after 5 seconds or one round + print STDERR "\n"; + exit ; } - my $ups = $count/$sum; - my $sdv = stddev($sum,$squaresum,$count); - printf STDERR " Update %6d rrds %6d u/s (%6.5f sdv)\n",$totaldbs,$ups,$sdv; - - if ((not $prevups or $prevups / $ups < 2 or $totaldbs < 500 )and $over < 1){ - $totaldbs *= 2; - } elsif ( $over < 1 ) { - # just run another round to see if we realy hit the block - $over ++; - $totaldbs *= 1.3; - } else { - print <{$_}."\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; +} + +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; +} + +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; +} + +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 = 200000; # 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 ; + } +} + +main;