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 20k RRD files (and sync them to disk)
26 2) Update the RRD files several times in a row.
27 We run the Update several times to see the difference
28 it makes in the cache.
33 use Time::HiRes qw(time);
36 use Time::HiRes qw( usleep );
41 my $start = time; #since we loaded HiRes
42 RRDs::create ( $file.".rrd", "-b$time", qw(
49 RRA:AVERAGE:0.5:24:600
51 RRA:AVERAGE:0.5:144:600
54 my $total = time - $start;
55 my $error = RRDs::error;
66 my $ret = RRDs::updatev($file.".rrd", $time.":$in:$out");
67 # print join("",map {" $_ " . $ret->{$_}."\n" } grep /AVERAGE.\[1\]/, sort keys %$ret)."\n** $time\n\n";
68 # sync updates to disk immediately
69 # usleep(1) if (rand(3) <1 );
70 my $total = time - $start;
71 my $error = RRDs::error;
79 RRDs::tune ($file.".rrd", "-a","in:U","-a","out:U","-d","in:GAUGE","-d","out:GAUGE");
80 my $total = time - $start;
81 my $error = RRDs::error;
89 my $info = RRDs::info ($file.".rrd");
90 my $error = RRDs::error;
92 my $lasttime = $info->{last_update} - $info->{last_update} % $info->{step};
93 my $fetch = RRDs::fetch ($file.".rrd",'AVERAGE','-s',$lasttime-1,'-e',$lasttime);
94 my $total = time - $start;
95 my $error = RRDs::error;
100 sub stddev ($$$){ #http://en.wikipedia.org/wiki/Standard_deviation
102 my $squaresum = shift;
104 return sqrt( 1 / $count * ( $squaresum - $sum*$sum / $count ))
114 my $id = sprintf ("%07d",$total);
115 $id =~ s/^(.)(.)(.)(.)(.)//;
116 push @$list, "$1/$2/$3/$4/$5/$id";
117 -d "$1" or mkdir "$1";
118 -d "$1/$2" or mkdir "$1/$2";
119 -d "$1/$2/$3" or mkdir "$1/$2/$3";
120 -d "$1/$2/$3/$4" or mkdir "$1/$2/$3/$4";
121 -d "$1/$2/$3/$4/$5" or mkdir "$1/$2/$3/$4/$5";
122 push @files, $list->[$total];
123 create $list->[$total++],$time-2;
127 my $fd = new IO::File("$_.rrd","r");
132 warn "failed to sync $_\n";
140 mkdir "db-$$" or die $!;
143 my $step = 100000; # number of rrds to creat for every round
152 my %squaresum = ( cr => 0, up => 0 );
153 my %sum = ( cr => 0, up => 0 );
154 my %count =( cr => 0, up => 0 );
156 my $printtime = time;
160 $tracksize += makerrds $step,$tracksize,\@path,$time;
167 for (my $i = 0; $i<$tracksize;$i ++){
168 my $elapsed = update($path[$i],$time);
170 $squaresum += $elapsed**2;
173 # for (my $i = 0; $i<$tracksize;$i ++){
174 # my $fh = new IO::File "$path[$i].rrd","r";
179 # warn "failed to sync $path[$i]\n";
182 my $ups = $count/$sum;
183 my $sdv = stddev($sum,$squaresum,$count);
184 printf STDERR "%4d %6.0f Up/s (%6.5f sdv)\n",$count,$ups,$sdv;