2 use strict;use warnings;
4 use OpenSRF::DOM::Element::userAuth;
5 use OpenSRF::Utils::Config;
6 use OpenSRF::DomainObject::oilsMethod;
7 use OpenSRF::DomainObject::oilsPrimitive;
8 use Time::HiRes qw/time/;
9 use OpenSRF::EX qw/:try/;
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,
17 # Usage: $ perl math_bench.pl <num_requests>
18 # ----------------------------------------------------------------------------------------
24 print "usage: ./math_bench.pl <num_requests>\n";
30 my $config = OpenSRF::Utils::Config->current;
31 OpenSRF::System::bootstrap_client();
33 my $session = OpenSRF::AppSession->create(
34 "math", username => 'math_bench', secret => '12345' );
37 if( ! ($session->connect()) ) { die "Connect timed out\n"; }
39 } catch OpenSRF::EX with {
41 warn "Connection Failed *\n";
46 my %vals = ( add => 3, sub => -1, mult => 2, div => 0.5 );
49 if( $x % 10 ) { print ".";}
56 for my $scale ( 1..$count ) {
57 for my $mname ( keys %vals ) {
59 my $method = OpenSRF::DomainObject::oilsMethod->new( method => $mname );
60 $method->params( 1,2 );
68 $req = $session->request( $method );
69 $resp = $req->recv( timeout => 10 );
70 push @times, time() - $starttime;
72 } catch OpenSRF::EX with {
78 die "Caught unknown error: $e";
82 if( ! $req->complete ) { warn "\nIncomplete\n"; }
84 if( UNIVERSAL::isa( $resp, "OpenSRF::EX" ) ) {
85 print "-" x 50 . "\nReceived Error " . $resp . "\n" . "-" x 50 . "\n";
89 my $ret = $resp->content();
90 if( "$ret" eq $vals{$mname} ) { print "+"; }
92 else { print "*BAD*\n" . $resp->toString(1) . "\n"; }
94 } else { print "*NADA*"; }
97 $session->disconnect();
101 print "\n[$c] \n" unless $scale % 25;
108 $total += $_ for (@times);
110 $total /= scalar(@times);
112 print "\n\n\tAverage Round Trip Time: $total Seconds\n";