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