5 # find Koha's Perl modules
6 # test carefully before changing this
8 eval { require "$FindBin::Bin/kohalib.pl" };
10 use HTTPD::Bench::ApacheBench;
13 # 1st, find some maximal values
14 my $dbh=C4::Context->dbh();
15 my $sth = $dbh->prepare("select max(borrowernumber) from borrowers");
17 my ($borrowernumber_max) = $sth->fetchrow;
19 $sth = $dbh->prepare("select max(biblionumber) from biblio");
21 my ($biblionumber_max) = $sth->fetchrow;
23 $sth = $dbh->prepare("select max(itemnumber) from items");
25 my ($itemnumber_max) = $sth->fetchrow;
27 my $baseurl= "http://i17.bureau.paulpoulain.com/cgi-bin/koha";
33 # the global benchmark we do at the end...
35 my $b = HTTPD::Bench::ApacheBench->new;
36 $b->concurrency( $concurrency );
38 # mainpage : (very) low mySQL dependancy
40 my $b0 = HTTPD::Bench::ApacheBench->new;
41 $b0->concurrency( $concurrency );
44 print "--------------\n";
45 print "Koha benchmark\n";
46 print "--------------\n";
47 print "benchmarking with $max_tries occurences of each operation\n";
48 print "mainpage (no mySQL) ";
49 for (my $i=1;$i<=$max_tries;$i++) {
50 push @mainpage,"$baseurl/mainpage.pl";
52 my $run0 = HTTPD::Bench::ApacheBench::Run->new
53 ({ urls => \@mainpage,
58 # send HTTP request sequences to server and time responses
59 my $ro = $b0->execute;
61 print ("\t".$b0->total_time."ms\t".(1000*$b0->total_requests/$b0->total_time)." pages/sec\n");
62 print "ALERT : ".$b0->total_responses_failed." failures\n" if $b0->total_responses_failed;
67 my $b1 = HTTPD::Bench::ApacheBench->new;
68 $b1->concurrency( $concurrency );
71 print "biblio (MARC detail)";
72 for (my $i=1;$i<=$max_tries;$i++) {
73 my $rand_biblionumber = int(rand($biblionumber_max)+1);
74 push @biblios,"$baseurl/catalogue/MARCdetail.pl?biblionumber=$rand_biblionumber";
76 my $run1 = HTTPD::Bench::ApacheBench::Run->new
82 # send HTTP request sequences to server and time responses
83 my $ro = $b1->execute;
85 print ("\t".$b1->total_time."ms\t".(1000*$b1->total_requests/$b1->total_time)." biblios/sec\n");
86 print "ALERT : ".$b1->total_responses_failed." failures\n" if $b1->total_responses_failed;
91 my $b2 = HTTPD::Bench::ApacheBench->new;
92 $b2->concurrency( $concurrency );
95 print "borrower detail ";
96 for (my $i=1;$i<=$max_tries;$i++) {
97 my $rand_borrowernumber = int(rand($borrowernumber_max)+1);
98 # print "$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber\n";
99 push @borrowers,"$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber";
101 my $run2 = HTTPD::Bench::ApacheBench::Run->new
102 ({ urls => \@borrowers,
107 # send HTTP request sequences to server and time responses
108 my $ro = $b2->execute;
110 print ("\t".$b2->total_time."ms\t".(1000*$b2->total_requests/$b2->total_time)." borrowers/sec\n");
114 # issue (& then return) books
116 my $b3 = HTTPD::Bench::ApacheBench->new;
117 $b3->concurrency( $concurrency );
118 my $b4 = HTTPD::Bench::ApacheBench->new;
119 $b4->concurrency( $concurrency );
123 print "Issues detail ";
124 my $sth = $dbh->prepare("SELECT barcode FROM items WHERE itemnumber=?");
125 my $sth2 = $dbh->prepare("SELECT borrowernumber FROM borrowers WHERE borrowernumber=?");
126 for (my $i=1;$i<=$max_tries;$i++) {
127 my $rand_borrowernumber;
128 # check that the borrowernumber exist
129 until ($rand_borrowernumber) {
130 $rand_borrowernumber = int(rand($borrowernumber_max)+1);
131 $sth2->execute($rand_borrowernumber);
132 ($rand_borrowernumber) = $sth2->fetchrow;
134 # find a barcode & check it exists
136 until ($rand_barcode) {
137 my $rand_itemnumber = int(rand($itemnumber_max)+1);
138 $sth->execute($rand_itemnumber);
139 ($rand_barcode) = $sth->fetchrow();
140 # print "$baseurl/circ/circulation.pl?borrowernumber=$rand_borrowernumber&barcode=$rand_barcode&issueconfirmed=1&year=2010&month=01&day=01\n";
142 push @issues,"$baseurl/circ/circulation.pl?borrowernumber=$rand_borrowernumber&barcode=$rand_barcode&issueconfirmed=1";
143 push @returns,"$baseurl/circ/returns.pl?barcode=$rand_barcode";
145 my $run3 = HTTPD::Bench::ApacheBench::Run->new
151 # send HTTP request sequences to server and time responses
152 my $ro = $b3->execute;
154 print ("\t".$b3->total_time."ms\t".(1000*$b3->total_requests/$b3->total_time)." issues/sec\n");
156 print "Returns detail ";
157 my $run4 = HTTPD::Bench::ApacheBench::Run->new
158 ({ urls => \@returns,
163 # send HTTP request sequences to server and time responses
164 my $ro = $b4->execute;
166 print ("\t".$b4->total_time."ms\t".(1000*$b4->total_requests/$b4->total_time)." returns/sec\n");
168 print "Benchmarking everything";
169 my $ro = $b->execute;
170 print ("\t".$b->total_time."ms\t".(1000*$b->total_requests/$b->total_time)." operations/sec\n");