|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# This script implements a basic benchmarking and regression testing |
| 3 |
# utility for Koha |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
BEGIN { |
| 8 |
# find Koha's Perl modules |
| 9 |
# test carefully before changing this |
| 10 |
use FindBin; |
| 11 |
eval { require "$FindBin::Bin/kohalib.pl" }; |
| 12 |
} |
| 13 |
|
| 14 |
use HTTPD::Bench::ApacheBench; |
| 15 |
use LWP::UserAgent; |
| 16 |
use Data::Dumper; |
| 17 |
use HTTP::Cookies; |
| 18 |
use C4::Context; |
| 19 |
use C4::Debug; |
| 20 |
|
| 21 |
my $baseurl= $ARGV[0] || "http://am123/cgi-bin/koha/"; |
| 22 |
my $max_tries = 200; |
| 23 |
my $concurrency = 30; |
| 24 |
my $user = $ARGV[1] ||'hdl'; |
| 25 |
my $password = $ARGV[2] || 'hdl'; |
| 26 |
|
| 27 |
# Authenticate via our handy dandy RESTful services |
| 28 |
# and grab a cookie |
| 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"); |
| 33 |
$sth->execute; |
| 34 |
my ($borrowernumber_max) = $sth->fetchrow; |
| 35 |
|
| 36 |
$sth = $dbh->prepare("select max(biblionumber) from biblio"); |
| 37 |
$sth->execute; |
| 38 |
my ($biblionumber_max) = $sth->fetchrow; |
| 39 |
|
| 40 |
$sth = $dbh->prepare("select max(itemnumber) from items"); |
| 41 |
$sth->execute; |
| 42 |
my ($itemnumber_max) = $sth->fetchrow; |
| 43 |
|
| 44 |
$|=1; |
| 45 |
# |
| 46 |
# the global benchmark we do at the end... |
| 47 |
# |
| 48 |
my $b = HTTPD::Bench::ApacheBench->new; |
| 49 |
$b->concurrency( $concurrency ); |
| 50 |
# |
| 51 |
# mainpage : (very) low RDBMS dependency |
| 52 |
# |
| 53 |
my $b0 = HTTPD::Bench::ApacheBench->new; |
| 54 |
$b0->concurrency( $concurrency ); |
| 55 |
|
| 56 |
my @mainpage; |
| 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"; |
| 64 |
} |
| 65 |
my $run0 = HTTPD::Bench::ApacheBench::Run->new |
| 66 |
({ urls => \@mainpage, |
| 67 |
}); |
| 68 |
$b0->add_run($run0); |
| 69 |
$b->add_run($run0); |
| 70 |
|
| 71 |
# send HTTP request sequences to server and time responses |
| 72 |
my $ro = $b0->execute; |
| 73 |
# calculate hits/sec |
| 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; |
| 76 |
|
| 77 |
# |
| 78 |
# biblios |
| 79 |
# |
| 80 |
my $b1 = HTTPD::Bench::ApacheBench->new; |
| 81 |
$b1->concurrency( $concurrency ); |
| 82 |
|
| 83 |
my @biblios; |
| 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"; |
| 88 |
} |
| 89 |
my $run1 = HTTPD::Bench::ApacheBench::Run->new |
| 90 |
({ urls => \@biblios, |
| 91 |
}); |
| 92 |
$b1->add_run($run1); |
| 93 |
$b->add_run($run1); |
| 94 |
|
| 95 |
# send HTTP request sequences to server and time responses |
| 96 |
$ro = $b1->execute; |
| 97 |
# calculate hits/sec |
| 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; |
| 100 |
|
| 101 |
# |
| 102 |
# borrowers |
| 103 |
# |
| 104 |
my $b2 = HTTPD::Bench::ApacheBench->new; |
| 105 |
$b2->concurrency( $concurrency ); |
| 106 |
|
| 107 |
my @borrowers; |
| 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"; |
| 114 |
} |
| 115 |
my $run2 = HTTPD::Bench::ApacheBench::Run->new |
| 116 |
({ urls => \@borrowers, |
| 117 |
}); |
| 118 |
$b2->add_run($run2); |
| 119 |
$b->add_run($run2); |
| 120 |
|
| 121 |
# send HTTP request sequences to server and time responses |
| 122 |
$ro = $b2->execute; |
| 123 |
# calculate hits/sec |
| 124 |
print ("\t".$b2->total_time."ms\t".(1000*$b2->total_requests/$b2->total_time)." searches/sec\n"); |
| 125 |
|
| 126 |
print "Load testing all transactions at once"; |
| 127 |
$ro = $b->execute; |
| 128 |
print ("\t".$b->total_time."ms\t".(1000*$b->total_requests/$b->total_time)." operations/sec\n"); |