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
;
20 my $baseurl= C4
::Context
->preference("staffClientBaseURL")."/cgi-bin/koha/";
25 my $password = 'kados';
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;
40 # remove some unnecessary garbage from the cookie
41 $cookie =~ s/ path_spec; discard; version=0//;
42 $cookie =~ s/Set-Cookie3: //;
44 # Get some data to work with
45 my $dbh=C4
::Context
->dbh();
46 my $sth = $dbh->prepare("select max(borrowernumber) from borrowers");
48 my ($borrowernumber_max) = $sth->fetchrow;
50 $sth = $dbh->prepare("select max(biblionumber) from biblio");
52 my ($biblionumber_max) = $sth->fetchrow;
54 $sth = $dbh->prepare("select max(itemnumber) from items");
56 my ($itemnumber_max) = $sth->fetchrow;
60 # the global benchmark we do at the end...
62 my $b = HTTPD
::Bench
::ApacheBench
->new;
63 $b->concurrency( $concurrency );
65 # mainpage : (very) low RDBMS dependency
67 my $b0 = HTTPD
::Bench
::ApacheBench
->new;
68 $b0->concurrency( $concurrency );
71 print "--------------\n";
72 print "Koha circulation benchmarking utility\n";
73 print "--------------\n";
74 print "Benchmarking with $max_tries occurrences of each operation and $concurrency concurrent sessions \n";
75 print "Load testing staff client dashboard page";
76 for (my $i=1;$i<=$max_tries;$i++) {
77 push @mainpage,"$baseurl/mainpage.pl";
79 my $run0 = HTTPD
::Bench
::ApacheBench
::Run
->new
80 ({ urls
=> \
@mainpage,
86 # send HTTP request sequences to server and time responses
87 my $ro = $b0->execute;
89 print ("\t".$b0->total_time."ms\t".(1000*$b0->total_requests/$b0->total_time)." pages/sec
\n");
90 print "ALERT
: ".$b0->total_responses_failed." failures
\n" if $b0->total_responses_failed;
95 my $b1 = HTTPD::Bench::ApacheBench->new;
96 $b1->concurrency( $concurrency );
99 print "Load testing catalog detail page
";
100 for (my $i=1;$i<=$max_tries;$i++) {
101 my $rand_biblionumber = int(rand($biblionumber_max)+1);
102 push @biblios,"$baseurl/catalogue/detail
.pl?biblionumber
=$rand_biblionumber";
104 my $run1 = HTTPD::Bench::ApacheBench::Run->new
105 ({ urls => \@biblios,
110 # send HTTP request sequences to server and time responses
113 print ("\t".$b1->total_time."ms
\t".(1000*$b1->total_requests/$b1->total_time)." biblios
/sec
\n");
114 print "ALERT
: ".$b1->total_responses_failed." failures
\n" if $b1->total_responses_failed;
119 my $b2 = HTTPD::Bench::ApacheBench->new;
120 $b2->concurrency( $concurrency );
123 print "Load testing patron detail page
";
124 for (my $i=1;$i<=$max_tries;$i++) {
125 my $rand_borrowernumber = int(rand($borrowernumber_max)+1);
126 # print "$baseurl/members/moremember
.pl?borrowernumber
=$rand_borrowernumber\n";
127 push @borrowers,"$baseurl/members/moremember
.pl?borrowernumber
=$rand_borrowernumber";
129 my $run2 = HTTPD::Bench::ApacheBench::Run->new
130 ({ urls => \@borrowers,
131 cookies => [$cookie],
136 # send HTTP request sequences to server and time responses
139 print ("\t".$b2->total_time."ms
\t".(1000*$b2->total_requests/$b2->total_time)." borrowers
/sec
\n");
143 # issue (& then return) books
145 my $b3 = HTTPD::Bench::ApacheBench->new;
146 $b3->concurrency( $concurrency );
147 my $b4 = HTTPD::Bench::ApacheBench->new;
148 $b4->concurrency( $concurrency );
152 print "Load testing circulation transaction
(checkouts
)";
153 $sth = $dbh->prepare("SELECT barcode FROM items WHERE itemnumber
=?
");
154 my $sth2 = $dbh->prepare("SELECT borrowernumber FROM borrowers WHERE borrowernumber
=?
");
155 for (my $i=1;$i<=$max_tries;$i++) {
156 my $rand_borrowernumber;
157 # check that the borrowernumber exist
158 until ($rand_borrowernumber) {
159 $rand_borrowernumber = int(rand($borrowernumber_max)+1);
160 $sth2->execute($rand_borrowernumber);
161 ($rand_borrowernumber) = $sth2->fetchrow;
163 # find a barcode & check it exists
165 until ($rand_barcode) {
166 my $rand_itemnumber = int(rand($itemnumber_max)+1);
167 $sth->execute($rand_itemnumber);
168 ($rand_barcode) = $sth->fetchrow();
170 print "borrowernumber
=$rand_borrowernumber&barcode
=$rand_barcode\n";
171 push @issues,"$baseurl/circ/circulation
.pl?borrowernumber
=$rand_borrowernumber&barcode
=$rand_barcode&issueconfirmed
=1";
172 push @returns,"$baseurl/circ/returns
.pl?barcode
=$rand_barcode";
174 my $run3 = HTTPD::Bench::ApacheBench::Run->new
176 cookies => [$cookie],
181 # send HTTP request sequences to server and time responses
184 print ("\t".$b3->total_time."ms
\t".(1000*$b3->total_requests/$b3->total_time)." checkouts
/sec
\n");
186 print "Load testing circulation transaction
(checkins
)";
187 my $run4 = HTTPD::Bench::ApacheBench::Run->new
188 ({ urls => \@returns,
189 cookies => [$cookie],
194 # send HTTP request sequences to server and time responses
197 print ("\t".$b4->total_time."ms
\t".(1000*$b4->total_requests/$b4->total_time)." checkins
/sec
\n");
199 print "Load testing all transactions at once
";
201 print ("\t".$b->total_time."ms
\t".(1000*$b->total_requests/$b->total_time)." operations
/sec
\n");