5 # Created By Tobi Oetiker <tobi@oetiker.ch>
8 #makes programm work AFTER install
10 my $Chunk = shift @ARGV || 10000;
12 use lib qw( ../bindings/perl-shared/blib/lib ../bindings/perl-shared/blib/arch @prefix@/lib/perl );
16 RRDtool Performance Tester
17 --------------------------
18 Running on $RRDs::VERSION;
20 RRDtool update performance is ultimately disk-bound. Since very little data
21 does actually get written to disk in a single update, the performance
22 is highly dependent on the cache situation of your machine.
24 This test tries to cater for this. It works like this:
26 1) Create $Chunk RRD files in a tree
28 2) For $Chunk -> Update RRD file, Sync
32 The numbers at the start of the row, show which
33 RRA is being updated. So if several RRAs are being updated,
34 you should see a slowdown as data has to be read from disk.
36 The growning number in the second column shows how many RRD have been
37 updated ... If everything is in cache, the number will Jump to $Chunk almost
38 immediately. Then the system will seem to hang as 'sync' runs, to make sure
39 all data has been written to disk prior to the next perftest run. This may
40 not be 100% real-life, so you may want to remove the sync just for fun
41 (then it is even less real-life, but different)
46 use Time::HiRes qw(time);
49 use Time::HiRes qw( usleep );
54 my $start = time; #since we loaded HiRes
55 RRDs::create ( $file.".rrd", "-b$time", qw(
62 RRA:AVERAGE:0.5:24:600
64 RRA:AVERAGE:0.5:144:600
67 my $total = time - $start;
68 my $error = RRDs::error;
79 my $ret = RRDs::updatev($file.".rrd", $time.":$in:$out");
80 my $total = time - $start;
81 my $error = RRDs::error;
89 RRDs::tune ($file.".rrd", "-a","in:U","-a","out:U","-d","in:GAUGE","-d","out:GAUGE");
90 my $total = time - $start;
91 my $error = RRDs::error;
99 my $info = RRDs::info ($file.".rrd");
100 my $error = RRDs::error;
101 die $error if $error;
102 my $lasttime = $info->{last_update} - $info->{last_update} % $info->{step};
103 my $fetch = RRDs::fetch ($file.".rrd",'AVERAGE','-s',$lasttime-1,'-e',$lasttime);
104 my $total = time - $start;
105 my $error = RRDs::error;
106 die $error if $error;
110 sub stddev ($$$){ #http://en.wikipedia.org/wiki/Standard_deviation
112 my $squaresum = shift;
114 return sqrt( 1 / $count * ( $squaresum - $sum*$sum / $count ))
125 my $id = sprintf ("%07d",$total);
126 $id =~ s/^(.)(.)(.)(.)(.)//;
127 push @$list, "$1/$2/$3/$4/$5/$id";
128 -d "$1" or mkdir "$1";
129 -d "$1/$2" or mkdir "$1/$2";
130 -d "$1/$2/$3" or mkdir "$1/$2/$3";
131 -d "$1/$2/$3/$4" or mkdir "$1/$2/$3/$4";
132 -d "$1/$2/$3/$4/$5" or mkdir "$1/$2/$3/$4/$5";
133 push @files, $list->[$total];
134 create $list->[$total++],$time-2;
135 if ($now < int(time)){
137 print STDERR "Creating RRDs: ", $count - $_," rrds to go. \r";
144 mkdir "db-$$" or die $!;
147 my $step = $Chunk; # number of rrds to creat for every round
156 my %squaresum = ( cr => 0, up => 0 );
157 my %sum = ( cr => 0, up => 0 );
158 my %count =( cr => 0, up => 0 );
160 my $printtime = time;
162 for (qw(1 6 24 144)){
163 $step{$_} = int($time / 300 / $_);
169 $tracksize += makerrds $step,$tracksize,\@path,$time;
178 for (qw(1 6 24 144)){
179 if (int($time / 300 / $_) > $step{$_}) {
181 $step{$_} = int($time / 300 / $_);
184 $prefix .= (" " x length("$_")) . " ";
188 for (my $i = 0; $i<$tracksize;$i ++){
189 my $ntime = int(time);
190 if ($now < $ntime or $i == $tracksize){
191 printf STDERR "$prefix %7d \r",$i;
194 my $elapsed = update($path[$i],$time);
196 $squaresum += $elapsed**2;
199 my $startsync = time;
203 my $synctime = time-$startsync;
205 $squaresum += $synctime**2;
206 my $ups = $count/$sum;
207 my $sdv = stddev($sum,$squaresum,$count);
208 printf STDERR "$prefix %7d %6.0f Up/s (%6.5f sdv)\n",$count,$ups,$sdv;