2 # This is an example script for how to benchmark various
3 # parts of your Koha system. It's useful for measuring the
4 # impact of mod_perl on performance.
7 # find Koha's Perl modules
8 # test carefully before changing this
10 eval { require "$FindBin::Bin/kohalib.pl" };
12 use HTTPD
::Bench
::ApacheBench
;
15 # 1st, find some max values
16 my $dbh=C4
::Context
->dbh();
17 my $sth = $dbh->prepare("select max(borrowernumber) from borrowers");
19 my ($borrowernumber_max) = $sth->fetchrow;
21 $sth = $dbh->prepare("select max(biblionumber) from biblio");
23 my ($biblionumber_max) = $sth->fetchrow;
25 $sth = $dbh->prepare("select max(itemnumber) from items");
27 my ($itemnumber_max) = $sth->fetchrow;
29 my $baseurl= C4
::Context
->preference("staffClientBaseURL")."/cgi-bin/koha/";
35 # the global benchmark we do at the end...
37 my $b = HTTPD
::Bench
::ApacheBench
->new;
38 $b->concurrency( $concurrency );
40 # mainpage : (very) low RDBMS dependency
42 my $b0 = HTTPD
::Bench
::ApacheBench
->new;
43 $b0->concurrency( $concurrency );
46 print "--------------\n";
47 print "Koha benchmark\n";
48 print "--------------\n";
49 print "benchmarking with $max_tries occurences of each operation\n";
50 print "mainpage (low RDBMS dependency) ";
51 for (my $i=1;$i<=$max_tries;$i++) {
52 push @mainpage,"$baseurl/mainpage.pl";
54 my $run0 = HTTPD
::Bench
::ApacheBench
::Run
->new
55 ({ urls
=> \
@mainpage,
60 # send HTTP request sequences to server and time responses
61 my $ro = $b0->execute;
63 print ("\t".$b0->total_time."ms\t".(1000*$b0->total_requests/$b0->total_time)." pages/sec
\n");
64 print "ALERT
: ".$b0->total_responses_failed." failures
\n" if $b0->total_responses_failed;
69 my $b1 = HTTPD::Bench::ApacheBench->new;
70 $b1->concurrency( $concurrency );
73 print "biblio
(MARC detail
)";
74 for (my $i=1;$i<=$max_tries;$i++) {
75 my $rand_biblionumber = int(rand($biblionumber_max)+1);
76 push @biblios,"$baseurl/catalogue/MARCdetail
.pl?biblionumber
=$rand_biblionumber";
78 my $run1 = HTTPD::Bench::ApacheBench::Run->new
84 # send HTTP request sequences to server and time responses
87 print ("\t".$b1->total_time."ms
\t".(1000*$b1->total_requests/$b1->total_time)." biblios
/sec
\n");
88 print "ALERT
: ".$b1->total_responses_failed." failures
\n" if $b1->total_responses_failed;
93 my $b2 = HTTPD::Bench::ApacheBench->new;
94 $b2->concurrency( $concurrency );
97 print "borrower detail
";
98 for (my $i=1;$i<=$max_tries;$i++) {
99 my $rand_borrowernumber = int(rand($borrowernumber_max)+1);
100 # print "$baseurl/members/moremember
.pl?borrowernumber
=$rand_borrowernumber\n";
101 push @borrowers,"$baseurl/members/moremember
.pl?borrowernumber
=$rand_borrowernumber";
103 my $run2 = HTTPD::Bench::ApacheBench::Run->new
104 ({ urls => \@borrowers,
109 # send HTTP request sequences to server and time responses
112 print ("\t".$b2->total_time."ms
\t".(1000*$b2->total_requests/$b2->total_time)." borrowers
/sec
\n");
116 # issue (& then return) books
118 my $b3 = HTTPD::Bench::ApacheBench->new;
119 $b3->concurrency( $concurrency );
120 my $b4 = HTTPD::Bench::ApacheBench->new;
121 $b4->concurrency( $concurrency );
125 print "Issues detail
";
126 $sth = $dbh->prepare("SELECT barcode FROM items WHERE itemnumber
=?
");
127 my $sth2 = $dbh->prepare("SELECT borrowernumber FROM borrowers WHERE borrowernumber
=?
");
128 for (my $i=1;$i<=$max_tries;$i++) {
129 my $rand_borrowernumber;
130 # check that the borrowernumber exist
131 until ($rand_borrowernumber) {
132 $rand_borrowernumber = int(rand($borrowernumber_max)+1);
133 $sth2->execute($rand_borrowernumber);
134 ($rand_borrowernumber) = $sth2->fetchrow;
136 # find a barcode & check it exists
138 until ($rand_barcode) {
139 my $rand_itemnumber = int(rand($itemnumber_max)+1);
140 $sth->execute($rand_itemnumber);
141 ($rand_barcode) = $sth->fetchrow();
142 # print "$baseurl/circ/circulation
.pl?borrowernumber
=$rand_borrowernumber&barcode
=$rand_barcode&issueconfirmed
=1&year
=2010&month
=01&day
=01\n";
144 push @issues,"$baseurl/circ/circulation
.pl?borrowernumber
=$rand_borrowernumber&barcode
=$rand_barcode&issueconfirmed
=1";
145 push @returns,"$baseurl/circ/returns
.pl?barcode
=$rand_barcode";
147 my $run3 = HTTPD::Bench::ApacheBench::Run->new
153 # send HTTP request sequences to server and time responses
156 print ("\t".$b3->total_time."ms
\t".(1000*$b3->total_requests/$b3->total_time)." issues
/sec
\n");
158 print "Returns detail
";
159 my $run4 = HTTPD::Bench::ApacheBench::Run->new
160 ({ urls => \@returns,
165 # send HTTP request sequences to server and time responses
168 print ("\t".$b4->total_time."ms
\t".(1000*$b4->total_requests/$b4->total_time)." returns
/sec
\n");
170 print "Benchmarking everything
";
172 print ("\t".$b->total_time."ms
\t".(1000*$b->total_requests/$b->total_time)." operations
/sec
\n");