2 # This script implements a basic benchmarking and regression testing
8 # find Koha's Perl modules
9 # test carefully before changing this
11 eval { require "$FindBin::Bin/kohalib.pl" };
14 use HTTPD::Bench::ApacheBench;
21 my $baseurl= $ARGV[0] || "http://am123/cgi-bin/koha/";
24 my $user = $ARGV[1] ||'hdl';
25 my $password = $ARGV[2] || 'hdl';
27 # Authenticate via our handy dandy RESTful services
29 my $ua = LWP::UserAgent->new();
30 my $cookie_jar = HTTP::Cookies->new();
32 $ua->cookie_jar($cookie_jar);
33 my $resp = $ua->post( "$baseurl"."/svc/authentication" , {userid =>$user, password => $password} );
34 if( $resp->is_success ) {
35 $cookie_jar->extract_cookies( $resp );
36 $cookie = $cookie_jar->as_string;
37 print "Authentication successful\n";
38 print "Auth:\n $resp->content" if $debug;
41 # remove some unnecessary garbage from the cookie
42 $cookie =~ s/ path_spec; discard; version=0//;
43 $cookie =~ s/Set-Cookie3: //;
45 # Get some data to work with
46 my $dbh=C4::Context->dbh();
47 my $sth = $dbh->prepare("select max(borrowernumber) from borrowers");
49 my ($borrowernumber_max) = $sth->fetchrow;
51 $sth = $dbh->prepare("select max(biblionumber) from biblio");
53 my ($biblionumber_max) = $sth->fetchrow;
55 $sth = $dbh->prepare("select max(itemnumber) from items");
57 my ($itemnumber_max) = $sth->fetchrow;
61 # the global benchmark we do at the end...
63 my $b = HTTPD::Bench::ApacheBench->new;
64 $b->concurrency( $concurrency );
66 # mainpage : (very) low RDBMS dependency
68 my $b0 = HTTPD::Bench::ApacheBench->new;
69 $b0->concurrency( $concurrency );
72 print "--------------\n";
73 print "Koha circulation benchmarking utility\n";
74 print "--------------\n";
75 print "Benchmarking with $max_tries occurences of each operation and $concurrency concurrent sessions \n";
76 print "Load testing staff client dashboard page";
77 for (my $i=1;$i<=$max_tries;$i++) {
78 push @mainpage,"$baseurl/mainpage.pl";
80 my $run0 = HTTPD::Bench::ApacheBench::Run->new
81 ({ urls => \@mainpage,
87 # send HTTP request sequences to server and time responses
88 my $ro = $b0->execute;
90 print ("\t".$b0->total_time."ms\t".(1000*$b0->total_requests/$b0->total_time)." pages/sec\n");
91 print "ALERT : ".$b0->total_responses_failed." failures\n" if $b0->total_responses_failed;
96 my $b1 = HTTPD::Bench::ApacheBench->new;
97 $b1->concurrency( $concurrency );
100 print "Load testing catalog detail page";
101 for (my $i=1;$i<=$max_tries;$i++) {
102 my $rand_biblionumber = int(rand($biblionumber_max)+1);
103 push @biblios,"$baseurl/catalogue/detail.pl?biblionumber=$rand_biblionumber";
105 my $run1 = HTTPD::Bench::ApacheBench::Run->new
106 ({ urls => \@biblios,
111 # send HTTP request sequences to server and time responses
114 print ("\t".$b1->total_time."ms\t".(1000*$b1->total_requests/$b1->total_time)." biblios/sec\n");
115 print "ALERT : ".$b1->total_responses_failed." failures\n" if $b1->total_responses_failed;
120 my $b2 = HTTPD::Bench::ApacheBench->new;
121 $b2->concurrency( $concurrency );
124 print "Load testing patron detail page";
125 for (my $i=1;$i<=$max_tries;$i++) {
126 my $rand_borrowernumber = int(rand($borrowernumber_max)+1);
127 # print "$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber\n";
128 push @borrowers,"$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber";
130 my $run2 = HTTPD::Bench::ApacheBench::Run->new
131 ({ urls => \@borrowers,
132 cookies => [$cookie],
137 # send HTTP request sequences to server and time responses
140 print ("\t".$b2->total_time."ms\t".(1000*$b2->total_requests/$b2->total_time)." borrowers/sec\n");
142 my $b2 = HTTPD::Bench::ApacheBench->new;
143 $b2->concurrency( $concurrency );
144 print "Load testing patron search page";
145 for (my $i=1;$i<=$max_tries;$i++) {
146 # print "$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber\n";
147 push @borrowers,"$baseurl/members/member.pl?member=jean";
152 # send HTTP request sequences to server and time responses
155 print ("\t".$b2->total_time."ms\t".(1000*$b2->total_requests/$b2->total_time)." borrowers/sec\n");
157 my $b2 = HTTPD::Bench::ApacheBench->new;
158 $b2->concurrency( $concurrency );
160 print "Load testing patron search page";
161 for (my $i=1;$i<=$max_tries;$i++) {
162 # print "$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber\n";
163 push @borrowers,"$baseurl/members/member.pl?quicksearch=1&surname=A";
168 # send HTTP request sequences to server and time responses
170 print ("\t".$b2->total_time."ms\t".(1000*$b2->total_requests/$b2->total_time)." borrowers/sec\n");
172 # issue (& then return) books
174 my $b3 = HTTPD::Bench::ApacheBench->new;
175 $b3->concurrency( $concurrency );
176 my $b4 = HTTPD::Bench::ApacheBench->new;
177 $b4->concurrency( $concurrency );
181 print "Load testing circulation transaction (checkouts)";
182 $sth = $dbh->prepare("SELECT barcode FROM items WHERE itemnumber=?");
183 my $sth2 = $dbh->prepare("SELECT borrowernumber FROM borrowers WHERE borrowernumber=?");
184 for (my $i=1;$i<=$max_tries;$i++) {
185 my $rand_borrowernumber;
186 # check that the borrowernumber exist
187 until ($rand_borrowernumber) {
188 $rand_borrowernumber = int(rand($borrowernumber_max)+1);
189 $sth2->execute($rand_borrowernumber);
190 ($rand_borrowernumber) = $sth2->fetchrow;
192 # find a barcode & check it exists
194 until ($rand_barcode) {
195 my $rand_itemnumber = int(rand($itemnumber_max)+1);
196 $sth->execute($rand_itemnumber);
197 ($rand_barcode) = $sth->fetchrow();
199 print "borrowernumber=$rand_borrowernumber&barcode=$rand_barcode\n";
200 push @issues,"$baseurl/circ/circulation.pl?borrowernumber=$rand_borrowernumber&barcode=$rand_barcode&issueconfirmed=1";
201 push @returns,"$baseurl/circ/returns.pl?barcode=$rand_barcode";
203 my $run3 = HTTPD::Bench::ApacheBench::Run->new
205 cookies => [$cookie],
210 # send HTTP request sequences to server and time responses
213 print ("\t".$b3->total_time."ms\t".(1000*$b3->total_requests/$b3->total_time)." checkouts/sec\n");
215 print "Load testing circulation transaction (checkins)";
216 my $run4 = HTTPD::Bench::ApacheBench::Run->new
217 ({ urls => \@returns,
218 cookies => [$cookie],
223 # send HTTP request sequences to server and time responses
226 print ("\t".$b4->total_time."ms\t".(1000*$b4->total_requests/$b4->total_time)." checkins/sec\n");
228 print "Load testing all transactions at once";
230 print ("\t".$b->total_time."ms\t".(1000*$b->total_requests/$b->total_time)." operations/sec\n");