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 # Get some data to work with
31 my $dbh=C4::Context->dbh();
32 my $sth = $dbh->prepare("select max(borrowernumber) from borrowers");
34 my ($borrowernumber_max) = $sth->fetchrow;
36 $sth = $dbh->prepare("select max(biblionumber) from biblio");
38 my ($biblionumber_max) = $sth->fetchrow;
40 $sth = $dbh->prepare("select max(itemnumber) from items");
42 my ($itemnumber_max) = $sth->fetchrow;
46 # the global benchmark we do at the end...
48 my $b = HTTPD::Bench::ApacheBench->new;
49 $b->concurrency( $concurrency );
51 # mainpage : (very) low RDBMS dependency
53 my $b0 = HTTPD::Bench::ApacheBench->new;
54 $b0->concurrency( $concurrency );
57 print "--------------\n";
58 print "Koha circulation benchmarking utility\n";
59 print "--------------\n";
60 print "Benchmarking with $max_tries occurences of each operation and $concurrency concurrent sessions \n";
61 print "Load testing opac client main page";
62 for (my $i=1;$i<=$max_tries;$i++) {
63 push @mainpage,"$baseurl/opac-main.pl";
65 my $run0 = HTTPD::Bench::ApacheBench::Run->new
66 ({ urls => \@mainpage,
71 # send HTTP request sequences to server and time responses
72 my $ro = $b0->execute;
74 print ("\t".$b0->total_time."ms\t".(1000*$b0->total_requests/$b0->total_time)." pages/sec\n");
75 print "ALERT : ".$b0->total_responses_failed." failures\n" if $b0->total_responses_failed;
80 my $b1 = HTTPD::Bench::ApacheBench->new;
81 $b1->concurrency( $concurrency );
84 print "Load testing catalog detail page";
85 for (my $i=1;$i<=$max_tries;$i++) {
86 my $rand_biblionumber = int(rand($biblionumber_max)+1);
87 push @biblios,"$baseurl/opac-detail.pl?biblionumber=$rand_biblionumber";
89 my $run1 = HTTPD::Bench::ApacheBench::Run->new
95 # send HTTP request sequences to server and time responses
98 print ("\t".$b1->total_time."ms\t".(1000*$b1->total_requests/$b1->total_time)." biblios/sec\n");
99 print "ALERT : ".$b1->total_responses_failed." failures\n" if $b1->total_responses_failed;
104 my $b2 = HTTPD::Bench::ApacheBench->new;
105 $b2->concurrency( $concurrency );
108 print "Load testing search page";
109 for (my $i=1;$i<=$max_tries;$i++) {
110 # print "$baseurl/members/moremember.pl?borrowernumber=$rand_borrowernumber\n";
111 push @borrowers,"$baseurl/opac-search.pl?idx=ti&q=Code";
112 push @borrowers,"$baseurl/opac-search.pl?idx=au&q=Jean";
113 push @borrowers,"$baseurl/opac-search.pl?idx=su&q=Droit";
115 my $run2 = HTTPD::Bench::ApacheBench::Run->new
116 ({ urls => \@borrowers,
121 # send HTTP request sequences to server and time responses
124 print ("\t".$b2->total_time."ms\t".(1000*$b2->total_requests/$b2->total_time)." searches/sec\n");
126 print "Load testing all transactions at once";
128 print ("\t".$b->total_time."ms\t".(1000*$b->total_requests/$b->total_time)." operations/sec\n");