2 use strict;use warnings;
3 use OpenSRF::System qw(/openils/conf/bootstrap.conf);
4 use OpenSRF::Utils::SettingsClient;
5 use Time::HiRes qw/time/;
6 use OpenSRF::EX qw/:try/;
10 # ----------------------------------------------------------------------------------------
11 # This is a quick and dirty script to perform benchmarking against the math server.
12 # Note: 1 request performs a batch of 4 queries, one for each supported method: add, sub,
14 # Usage: $ perl math_bench.pl <num_requests>
15 # ----------------------------------------------------------------------------------------
21 print "usage: ./math_bench.pl <num_requests>\n";
27 OpenSRF::System->bootstrap_client();
28 my $session = OpenSRF::AppSession->create( "opensrf.math" );
31 my %vals = ( add => 3, sub => -1, mult => 2, div => 0.5 );
34 if( $x % 10 ) { print ".";}
41 for my $scale ( 1..$count ) {
42 for my $mname ( keys %vals ) {
50 if( ! ($session->connect()) ) { die "Connect timed out\n"; }
51 $req = $session->request( $mname, 1, 2 );
52 $resp = $req->recv( timeout => 10 );
53 push @times, time() - $starttime;
55 } catch OpenSRF::EX with {
61 die "Caught unknown error: $e";
65 if( ! $req->complete ) { warn "\nIncomplete\n"; }
67 if( UNIVERSAL::isa( $resp, "OpenSRF::EX" ) ) {
68 print "-" x 50 . "\nReceived Error " . $resp . "\n" . "-" x 50 . "\n";
72 my $ret = $resp->content();
73 if( "$ret" eq $vals{$mname} ) { print "+"; }
75 else { print "*BAD*\n" . $resp->toString(1) . "\n"; }
77 } else { print "*NADA*"; }
80 # $session->disconnect();
84 print "\n[$c] \n" unless $scale % 25;
91 $total += $_ for (@times);
93 $total /= scalar(@times);
95 print "\n\n\tAverage Round Trip Time: $total Seconds\n";