2 use strict; use warnings;
4 use Time::HiRes qw/time/;
6 # Test script which runs queries agains the opensrf.math service and reports on
7 # the average round trip time of the requests.
9 # how many batches of 4 requests do we send
11 print "usage: $0 <num_requests>\n" and exit unless $count;
13 # * connect to the Jabber network
14 OpenSRF::System->bootstrap_client( config_file => "/openils/conf/bootstrap.conf" );
16 # * create a new application session for the opensrf.math service
17 my $session = OpenSRF::AppSession->create( "opensrf.math" );
19 my @times; # "delta" times for each round trip
21 # we're gonna call methods "add", "sub", "mult", and "div" with
22 # params 1, 2. The hash below maps the method name to the
23 # expected response value
24 my %vals = ( add => 3, sub => -1, mult => 2, div => 0.5 );
26 # print the counter grid
28 if( $x % 10 ) { print ".";}
35 for my $scale ( 1..$count ) {
36 for my $mname ( keys %vals ) { # cycle through add, sub, mult, and div
38 my $starttime = time();
40 # * Fires the request and gathers the response object, which in this case
42 my $resp = $session->request( $mname, 1, 2 )->gather(1);
43 push @times, time() - $starttime;
46 if( "$resp" eq $vals{$mname} ) {
47 # we got the response we expected
51 # we got some other response
52 print "\n* BAD Data: $resp\n";
56 print "Received nothing\n";
63 print " [$c] \n" unless $scale % 25;
68 $total += $_ for (@times);
70 $total /= scalar(@times);
72 print "\n\n\tAverage Round Trip Time: $total Seconds\n";