]> git.evergreen-ils.org Git - OpenSRF.git/blob - examples/math_bench.pl
Initial revision
[OpenSRF.git] / examples / math_bench.pl
1 #!/usr/bin/perl -w
2 use strict;use warnings;
3 use OpenILS::System;
4 use OpenILS::DOM::Element::userAuth;
5 use OpenILS::Utils::Config;
6 use OpenILS::DomainObject::oilsMethod;
7 use OpenILS::DomainObject::oilsPrimitive;
8 use Time::HiRes qw/time/;
9 use OpenILS::EX qw/:try/;
10
11 $| = 1;
12
13 # ----------------------------------------------------------------------------------------
14 # This is a quick and dirty script to perform benchmarking against the math server.
15 # Note: 1 request performs a batch of 4 queries, one for each supported method: add, sub,
16 # mult, div.
17 # Usage: $ perl math_bench.pl <num_requests>
18 # ----------------------------------------------------------------------------------------
19
20
21 my $count = $ARGV[0];
22
23 unless( $count ) {
24         print "usage: ./math_bench.pl <num_requests>\n";
25         exit;
26 }
27
28 warn "PID: $$\n";
29
30 my $config = OpenILS::Utils::Config->current;
31 OpenILS::System->bootstrap_client();
32
33 my $session = OpenILS::AppSession->create( 
34                 "math", username => 'math_bench', secret => '12345' );
35
36 try {
37         if( ! ($session->connect()) ) { die "Connect timed out\n"; }
38
39 } catch OpenILS::EX with {
40         my $e = shift;
41         warn "Connection Failed *\n";
42         die $e;
43 }
44
45 my @times;
46 my %vals = ( add => 3, sub => -1, mult => 2, div => 0.5 );
47
48 for my $x (1..100) {
49         if( $x % 10 ) { print ".";}
50         else{ print $x/10; };
51 }
52 print "\n";
53
54 my $c = 0;
55
56 for my $scale ( 1..$count ) {
57         for my $mname ( keys %vals ) {
58
59                 my $method = OpenILS::DomainObject::oilsMethod->new( method => $mname );
60                 $method->params( 1,2 );
61
62                 my $req;
63                 my $resp;
64                 my $starttime;
65                 try {
66
67                         $starttime = time();
68                         $req = $session->request( $method );
69                         $resp = $req->recv( timeout => 10 );
70                         push @times, time() - $starttime;
71
72                 } catch OpenILS::EX with {
73                         my $e = shift;
74                         die "ERROR\n $e";
75
76                 } catch Error with {
77                         my $e = shift;
78                         die "Caught unknown error: $e";
79                 };
80
81
82                 if( ! $req->complete ) { warn "\nIncomplete\n"; }
83
84
85                 if ( $resp ) {
86
87                         my $ret = $resp->content();
88                         if( "$ret" eq $vals{$mname} ) { print "+"; }
89
90                         else { print "*BAD*\n" . $resp->toString(1) . "\n"; }
91
92                 } else { print "*NADA*";        }
93
94                 $req->finish();
95                 $c++;
96
97         }
98         print "\n[$c] \n" unless $scale % 25;
99 }
100
101 $session->kill_me();
102
103 my $total = 0;
104
105 $total += $_ for (@times);
106
107 $total /= scalar(@times);
108
109 print "\n\n\tAverage Round Trip Time: $total Seconds\n";
110