Code

Imported upstream version 1.4~rc2.
[pkg-rrdtool.git] / examples / rrdcached / rrdcached-size.pl
1 #!/usr/bin/perl
3 =head1 NAME
5 rrdcached-size.pl - estimate the IO and memory requirements for rrdcached
7 =head1 SYNOPSIS
9 B<rrdcached-size.pl>
10 [B<-rrds>E<nbsp>I<file_count>]
11 [B<-step>E<nbsp>I<seconds>]
12 [B<-update>E<nbsp>I<length>]
13 [B<-file>E<nbsp>I<length>]
14 [B<-io>E<nbsp>I<files/sec>]
15 [B<-w>E<nbsp>I<seconds>]
16 [B<-f>E<nbsp>I<seconds>]
17 [B<-pagesize>E<nbsp>I<bytes>]
19 =head1 OPTIONS
21 =over 4
23 =item B<-rrds> I<file_count>
25 Specify the number of RRDs in the working set.
27 =item B<-step> I<seconds>
29 Specify the RRD step value for each file.
31 =item B<-update> I<length>
33 Average update string length.  For this calculation, the time value must
34 be specified as a C<time_t>, not C<N>.  For example, this update string
35 would lead to B<-update>E<nbsp>I<43> :
37   1226936851:0:0:101113914:0:0:0:25814373:0:0
39 =item B<-file> I<length>
41 Specify the average file name length.  For this calculation, use the full
42 path of the file.
44 =item B<-io> I<files/sec>
46 Specify the number of RRD files that your system can write per second.
48 =item B<-w> I<timer>
50 Specifies the B<-w> timer used with rrdcached.  For more information, see
51 the B<rrdcached> documentation.
53 =item B<-f> I<timer>
55 Specifies the B<-f> timer used with rrdcached.  For more information, see
56 the B<rrdcached> documentation.
58 =item B<-pagesize> I<bytes>
60 Manually specify the system page size, in case it is not detected
61 properly.
63 =back
65 =cut
67 use strict;
68 use warnings;
70 my $filename_len = 60;
71 my $update_len = 128;
72 my $rrds = 100;
73 my $step = 300;
74 my $rrd_per_sec = 200;
75 my $rrdc_write = 300;
76 my $rrdc_flush = 3600;
77 my $pagesize = `pagesize` || 4096;
79 #################################################################
81 use Getopt::Long;
82 GetOptions('rrds=i' => \$rrds,
83            'step=i' => \$step,
84            'update=i' => \$update_len,
85            'file=i' => \$filename_len,
86            'io=i' => \$rrd_per_sec,
87            'w=i'    => \$rrdc_write,
88            'f=i'    => \$rrdc_flush,
89            'pagesize=i' => \$pagesize,
90            'h' => \&usage,
91            )
92     or die "Options failure";
94 @ARGV and die "Extra args: @ARGV\n";
96 #################################################################
98 my $MEG = 1024*1024;
100 my $write_time = int($rrds / $rrd_per_sec);
101 my $write_busy = int(100 * $write_time / $rrdc_write);
102 my $buffered_pdp = $rrdc_write / $step;
104 my $max_ram
105     = $rrds
106     * ($filename_len
107            + ( $rrdc_write / $step ) * $update_len)
108     / $MEG;
110 my $journal_size
111     = $rrds
112     * (length("update") + $filename_len + $update_len + 3)
113     * ($rrdc_flush/$step)
114     * 2  # 2 logs
115     / $MEG;
117 my $journal_rate = (($journal_size*$MEG/2))/$rrdc_flush;
118 my $journal_page_rate = $journal_rate / $pagesize;
120 $_ = sprintf("%.1f", $_)
121     for ($write_time,
122          $write_busy,
123          $buffered_pdp,
124          $max_ram,
125          $journal_size,
126          $journal_rate,
127          $journal_page_rate,
128      );
130 print <<"EOF";
131 RRD files     : $rrds files
132 RRD step      : $step seconds
133 Update length : $update_len bytes
134 IO writes/sec : $rrd_per_sec rrd/sec
135 write timer   : $rrdc_write seconds
136 flush timer   : $rrdc_flush seconds
137 -----------------------------------------------------------------
139 Time to write all RRDs: $write_time sec ($write_busy\% busy)
141 $buffered_pdp PDPs will be buffered per file
143 RAM usage: $max_ram MB
145 Journal size: $journal_size MB (total size for two journals)
147 Journal write rate: $journal_page_rate page/sec ($journal_rate byte/sec)
148 EOF
150 sub usage {
151     system("perldoc $0");
152     exit(1);