2 use strict;use warnings;
3 use OpenSRF::System qw(/pines/conf/client.conf);
4 use OpenSRF::Utils::SettingsClient;
5 use OpenSRF::DomainObject::oilsMethod;
6 use OpenSRF::DomainObject::oilsPrimitive;
7 use Time::HiRes qw/time/;
8 use OpenSRF::EX qw/:try/;
12 # ----------------------------------------------------------------------------------------
13 # This is a quick and dirty script to perform benchmarking against the math server.
14 # Note: 1 request performs a batch of 4 queries, one for each supported method: add, sub,
16 # Usage: $ perl math_bench.pl <num_requests>
17 # ----------------------------------------------------------------------------------------
23 print "usage: ./math_bench.pl <num_requests>\n";
29 OpenSRF::System::bootstrap_client();
30 my $session = OpenSRF::AppSession->create( "math" );
33 if( ! ($session->connect()) ) { die "Connect timed out\n"; }
35 } catch OpenSRF::EX with {
37 warn "Connection Failed *\n";
42 my %vals = ( add => 3, sub => -1, mult => 2, div => 0.5 );
45 if( $x % 10 ) { print ".";}
52 for my $scale ( 1..$count ) {
53 for my $mname ( keys %vals ) {
61 $req = $session->request( $mname, 1, 2 );
62 $resp = $req->recv( timeout => 10 );
63 push @times, time() - $starttime;
65 } catch OpenSRF::EX with {
71 die "Caught unknown error: $e";
75 if( ! $req->complete ) { warn "\nIncomplete\n"; }
77 if( UNIVERSAL::isa( $resp, "OpenSRF::EX" ) ) {
78 print "-" x 50 . "\nReceived Error " . $resp . "\n" . "-" x 50 . "\n";
82 my $ret = $resp->content();
83 if( "$ret" eq $vals{$mname} ) { print "+"; }
85 else { print "*BAD*\n" . $resp->toString(1) . "\n"; }
87 } else { print "*NADA*"; }
90 $session->disconnect();
94 print "\n[$c] \n" unless $scale % 25;
101 $total += $_ for (@times);
103 $total /= scalar(@times);
105 print "\n\n\tAverage Round Trip Time: $total Seconds\n";