add rrdcached examples -- kevin
[rrdtool.git] / examples / rrdcached / rrdcached-size.pl
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 rrdcached-size.pl - estimate the IO and memory requirements for rrdcached
6
7 =head1 SYNOPSIS
8
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>]
18
19 =head1 OPTIONS
20
21 =over 4
22
23 =item B<-rrds> I<file_count>
24
25 Specify the number of RRDs in the working set.
26
27 =item B<-step> I<seconds>
28
29 Specify the RRD step value for each file.
30
31 =item B<-update> I<length>
32
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> :
36
37   1226936851:0:0:101113914:0:0:0:25814373:0:0
38
39 =item B<-file> I<length>
40
41 Specify the average file name length.  For this calculation, use the full
42 path of the file.
43
44 =item B<-io> I<files/sec>
45
46 Specify the number of RRD files that your system can write per second.
47
48 =item B<-w> I<timer>
49
50 Specifies the B<-w> timer used with rrdcached.  For more information, see
51 the B<rrdcached> documentation.
52
53 =item B<-f> I<timer>
54
55 Specifies the B<-f> timer used with rrdcached.  For more information, see
56 the B<rrdcached> documentation.
57
58 =item B<-pagesize> I<bytes>
59
60 Manually specify the system page size, in case it is not detected
61 properly.
62
63 =back
64
65 =cut
66
67 use strict;
68 use warnings;
69
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;
78
79 #################################################################
80
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";
93
94 @ARGV and die "Extra args: @ARGV\n";
95
96 #################################################################
97
98 my $MEG = 1024*1024;
99
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;
103
104 my $max_ram
105     = $rrds
106     * ($filename_len
107            + ( $rrdc_write / $step ) * $update_len)
108     / $MEG;
109
110 my $journal_size
111     = $rrds
112     * (length("update") + $filename_len + $update_len + 3)
113     * ($rrdc_flush/$step)
114     * 2  # 2 logs
115     / $MEG;
116
117 my $journal_rate = (($journal_size*$MEG/2))/$rrdc_flush;
118 my $journal_page_rate = $journal_rate / $pagesize;
119
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      );
129
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 -----------------------------------------------------------------
138
139 Time to write all RRDs: $write_time sec ($write_busy\% busy)
140
141 $buffered_pdp PDPs will be buffered per file
142
143 RAM usage: $max_ram MB
144
145 Journal size: $journal_size MB (total size for two journals)
146
147 Journal write rate: $journal_page_rate page/sec ($journal_rate byte/sec)
148 EOF
149
150 sub usage {
151     system("perldoc $0");
152     exit(1);
153 }