]> git.evergreen-ils.org Git - OpenSRF.git/blob - examples/math_bench.pl.in
Miscellaneous minor changes. mostly for clarity:
[OpenSRF.git] / examples / math_bench.pl.in
1 #!/usr/bin/perl
2 use strict; use warnings;
3 use OpenSRF::System;
4 use Time::HiRes qw/time/;
5 use OpenSRF::Utils::Logger;
6 my $log = "OpenSRF::Utils::Logger";
7
8 # Test script which runs queries agains the opensrf.math service and reports on
9 # the average round trip time of the requests.
10
11 # how many batches of 4 requests do we send
12 my $count = $ARGV[0];
13 print "usage: $0 <num_requests>\n" and exit unless $count;
14
15 # * connect to the Jabber network
16 OpenSRF::System->bootstrap_client( config_file => "@CONF_DIR@/opensrf_core.xml" );
17 $log->set_service('math_bench');
18
19 # * create a new application session for the opensrf.math service
20 my $session = OpenSRF::AppSession->create( "opensrf.math" );
21
22 my @times; # "delta" times for each round trip
23
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 );
28
29 # print the counter grid 
30 for my $x (1..100) {
31         if( $x % 10 ) { print ".";}
32         else{ print $x/10; };
33 }
34 print "\n";
35
36 my $c = 0;
37
38 for my $scale ( 1..$count ) {
39         for my $mname ( keys %vals ) { # cycle through add, sub, mult, and div
40
41                 my $starttime = time();
42
43                 # * Fires the request and gathers the response object, which in this case
44                 # is just a string
45                 my $resp = $session->request( $mname, 1, 2 )->gather(1);
46                 push @times, time() - $starttime;
47
48
49                 if( "$resp" eq $vals{$mname} ) { 
50                         # we got the response we expected
51                         print "+"; 
52
53                 } elsif($resp) { 
54                         # we got some other response     
55                         print "\n* BAD Data:  $resp\n";
56
57                 } else { 
58                         # we got no data
59                         print "Received nothing\n";     
60                 }
61
62                 $c++;
63
64         }
65
66         print " [$c] \n" unless $scale % 25;
67 }
68
69 my $total = 0;
70
71 $total += $_ for (@times);
72
73 $total /= scalar(@times);
74
75 print "\n\n\tAverage Round Trip Time: $total Seconds\n";
76
77