5 # Created By Tobi Oetiker <tobi@oetiker.ch>
8 #makes programm work AFTER install
10 use lib qw( @prefix@/lib/perl );
14 RRDtool Performance Tester
15 --------------------------
16 Runnion on $RRDs::VERSION;
18 RRDtool update performance is ultimately disk-bound. Since very little data
19 does actually get written to disk in a single update, the performance
20 is highly dependent on the cache situation in your machine.
22 This test tries to cater for this. It works like this:
24 1) Create 100 RRD files (and sync them to disk)
26 2) Update the 100 RRD file three times in a row.
27 We run the Update several times to see the difference
28 it makes in the cache.
35 use Time::HiRes qw(time);
38 use Time::HiRes qw( usleep );
43 my $start = time; #since we loaded HiRes
44 RRDs::create ( $file.".rrd", "-b$time", qw(
51 RRA:AVERAGE:0.5:24:600
53 RRA:AVERAGE:0.5:144:600
56 my $total = time - $start;
57 my $error = RRDs::error;
68 my $ret = RRDs::updatev($file.".rrd", $time.":$in:$out");
69 # print join("",map {" $_ " . $ret->{$_}."\n" } grep /AVERAGE.\[1\]/, sort keys %$ret)."\n** $time\n\n";
70 # sync updates to disk immediately
71 # usleep(1) if (rand(3) <1 );
72 my $total = time - $start;
73 my $error = RRDs::error;
81 RRDs::tune ($file.".rrd", "-a","in:U","-a","out:U","-d","in:GAUGE","-d","out:GAUGE");
82 my $total = time - $start;
83 my $error = RRDs::error;
91 my $info = RRDs::info ($file.".rrd");
92 my $error = RRDs::error;
94 my $lasttime = $info->{last_update} - $info->{last_update} % $info->{step};
95 my $fetch = RRDs::fetch ($file.".rrd",'AVERAGE','-s',$lasttime-1,'-e',$lasttime);
96 my $total = time - $start;
97 my $error = RRDs::error;
102 sub stddev ($$$){ #http://en.wikipedia.org/wiki/Standard_deviation
104 my $squaresum = shift;
106 return sqrt( 1 / $count * ( $squaresum - $sum*$sum / $count ))
116 my $id = sprintf ("%07d",$total);
117 $id =~ s/^(.)(.)(.)(.)(.)//;
118 push @$list, "$1/$2/$3/$4/$5/$id";
119 -d "$1" or mkdir "$1";
120 -d "$1/$2" or mkdir "$1/$2";
121 -d "$1/$2/$3" or mkdir "$1/$2/$3";
122 -d "$1/$2/$3/$4" or mkdir "$1/$2/$3/$4";
123 -d "$1/$2/$3/$4/$5" or mkdir "$1/$2/$3/$4/$5";
124 push @files, $list->[$total];
125 create $list->[$total++],$time-2;
129 my $fd = new IO::File("$_.rrd","r");
134 warn "failed to sync $_\n";
142 mkdir "db-$$" or die $!;
145 my $step = 100000; # number of rrds to creat for every round
154 my %squaresum = ( cr => 0, up => 0 );
155 my %sum = ( cr => 0, up => 0 );
156 my %count =( cr => 0, up => 0 );
158 my $printtime = time;
162 $tracksize += makerrds $step,$tracksize,\@path,$time;
169 for (my $i = 0; $i<$tracksize;$i ++){
170 my $elapsed = update($path[$i],$time);
172 $squaresum += $elapsed**2;
175 # for (my $i = 0; $i<$tracksize;$i ++){
176 # my $fh = new IO::File "$path[$i].rrd","r";
181 # warn "failed to sync $path[$i]\n";
184 my $ups = $count/$sum;
185 my $sdv = stddev($sum,$squaresum,$count);
186 printf STDERR "%4d %6.0f Up/s (%6.5f sdv)\n",$count,$ups,$sdv;