2 use strict; use warnings;
4 use Time::HiRes qw/time/;
5 use OpenSRF::Utils::Logger;
6 my $log = "OpenSRF::Utils::Logger";
8 # Test script which runs queries agains the opensrf.math service and reports on
9 # the average round trip time of the requests.
11 # how many batches of 4 requests do we send
13 print "usage: $0 <num_requests>\n" and exit unless $count;
15 # * connect to the Jabber network
16 OpenSRF::System->bootstrap_client( config_file => "/openils/conf/opensrf_core.xml" );
17 $log->set_service('math_bench');
19 # * create a new application session for the opensrf.math service
20 my $session = OpenSRF::AppSession->create( "opensrf.math" );
22 my @times; # "delta" times for each round trip
24 # we're gonna call methods "add", "sub", "mult", and "div" with
25 # params 1, 2. The hash below maps the method name to the
26 # expected response value
27 my %vals = ( add => 3, sub => -1, mult => 2, div => 0.5 );
29 # print the counter grid
31 if( $x % 10 ) { print ".";}
38 for my $scale ( 1..$count ) {
39 for my $mname ( keys %vals ) { # cycle through add, sub, mult, and div
41 my $starttime = time();
43 # * Fires the request and gathers the response object, which in this case
45 my $resp = $session->request( $mname, 1, 2 )->gather(1);
46 push @times, time() - $starttime;
49 if( "$resp" eq $vals{$mname} ) {
50 # we got the response we expected
54 # we got some other response
55 print "\n* BAD Data: $resp\n";
59 print "Received nothing\n";
66 print " [$c] \n" unless $scale % 25;
71 $total += $_ for (@times);
73 $total /= scalar(@times);
75 print "\n\n\tAverage Round Trip Time: $total Seconds\n";