3 use HTTPD::Bench::ApacheBench;
7 # 1st, find some maximal values
8 my $dbh=C4::Context->dbh();
9 my $sth = $dbh->prepare("select max(borrowernumber) from borrowers");
11 my ($borrowernumber_max) = $sth->fetchrow;
13 $sth = $dbh->prepare("select max(biblionumber) from biblio");
15 my ($biblionumber_max) = $sth->fetchrow;
17 $sth = $dbh->prepare("select max(itemnumber) from items");
19 my ($itemnumber_max) = $sth->fetchrow;
21 my $baseurl= "http://i17.bureau.paulpoulain.com/cgi-bin/koha";
27 # the global benchmark we do at the end...
29 my $b = HTTPD::Bench::ApacheBench->new;
30 $b->concurrency( $concurrency );
32 # mainpage : (very) low mySQL dependancy
34 my $b0 = HTTPD::Bench::ApacheBench->new;
35 $b0->concurrency( $concurrency );
38 print "--------------\n";
39 print "Koha benchmark\n";
40 print "--------------\n";
41 print "benchmarking with $max_tries occurences of each operation\n";
42 print "mainpage (no mySQL) ";
43 for (my $i=1;$i<=$max_tries;$i++) {
44 push @mainpage,"$baseurl/mainpage.pl";
46 my $run0 = HTTPD::Bench::ApacheBench::Run->new
47 ({ urls => \@mainpage,
52 # send HTTP request sequences to server and time responses
53 my $ro = $b0->execute;
55 print ("\t".$b0->total_time."ms\t".(1000*$b0->total_requests/$b0->total_time)." pages/sec\n");
56 print "ALERT : ".$b0->total_responses_failed." failures\n" if $b0->total_responses_failed;
61 my $b1 = HTTPD::Bench::ApacheBench->new;
62 $b1->concurrency( $concurrency );
65 print "biblio (MARC detail)";
66 for (my $i=1;$i<=$max_tries;$i++) {
67 my $rand_biblionumber = int(rand($biblionumber_max)+1);
68 push @biblios,"$baseurl/catalogue/MARCdetail.pl?biblionumber=$rand_biblionumber";
70 my $run1 = HTTPD::Bench::ApacheBench::Run->new
76 # send HTTP request sequences to server and time responses
77 my $ro = $b1->execute;
79 print ("\t".$b1->total_time."ms\t".(1000*$b1->total_requests/$b1->total_time)." biblios/sec\n");
80 print "ALERT : ".$b1->total_responses_failed." failures\n" if $b1->total_responses_failed;
85 my $b2 = HTTPD::Bench::ApacheBench->new;
86 $b2->concurrency( $concurrency );
89 print "borrower detail ";
90 for (my $i=1;$i<=$max_tries;$i++) {
91 my $rand_borrowernumber = int(rand($borrowernumber_max)+1);
92 # print "$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber\n";
93 push @borrowers,"$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber";
95 my $run2 = HTTPD::Bench::ApacheBench::Run->new
96 ({ urls => \@borrowers,
101 # send HTTP request sequences to server and time responses
102 my $ro = $b2->execute;
104 print ("\t".$b2->total_time."ms\t".(1000*$b2->total_requests/$b2->total_time)." borrowers/sec\n");
108 # issue (& then return) books
110 my $b3 = HTTPD::Bench::ApacheBench->new;
111 $b3->concurrency( $concurrency );
112 my $b4 = HTTPD::Bench::ApacheBench->new;
113 $b4->concurrency( $concurrency );
117 print "Issues detail ";
118 my $sth = $dbh->prepare("SELECT barcode FROM items WHERE itemnumber=?");
119 my $sth2 = $dbh->prepare("SELECT borrowernumber FROM borrowers WHERE borrowernumber=?");
120 for (my $i=1;$i<=$max_tries;$i++) {
121 my $rand_borrowernumber;
122 # check that the borrowernumber exist
123 until ($rand_borrowernumber) {
124 $rand_borrowernumber = int(rand($borrowernumber_max)+1);
125 $sth2->execute($rand_borrowernumber);
126 ($rand_borrowernumber) = $sth2->fetchrow;
128 # find a barcode & check it exists
130 until ($rand_barcode) {
131 my $rand_itemnumber = int(rand($itemnumber_max)+1);
132 $sth->execute($rand_itemnumber);
133 ($rand_barcode) = $sth->fetchrow();
134 # print "$baseurl/circ/circulation.pl?borrowernumber=$rand_borrowernumber&barcode=$rand_barcode&issueconfirmed=1&year=2010&month=01&day=01\n";
136 push @issues,"$baseurl/circ/circulation.pl?borrowernumber=$rand_borrowernumber&barcode=$rand_barcode&issueconfirmed=1";
137 push @returns,"$baseurl/circ/returns.pl?barcode=$rand_barcode";
139 my $run3 = HTTPD::Bench::ApacheBench::Run->new
145 # send HTTP request sequences to server and time responses
146 my $ro = $b3->execute;
148 print ("\t".$b3->total_time."ms\t".(1000*$b3->total_requests/$b3->total_time)." issues/sec\n");
150 print "Returns detail ";
151 my $run4 = HTTPD::Bench::ApacheBench::Run->new
152 ({ urls => \@returns,
157 # send HTTP request sequences to server and time responses
158 my $ro = $b4->execute;
160 print ("\t".$b4->total_time."ms\t".(1000*$b4->total_requests/$b4->total_time)." returns/sec\n");
162 print "Benchmarking everything";
163 my $ro = $b->execute;
164 print ("\t".$b->total_time."ms\t".(1000*$b->total_requests/$b->total_time)." operations/sec\n");