]> git.evergreen-ils.org Git - OpenSRF.git/blob - examples/multisession-test.pl
implemented onerror, onmethoderror and ontransporterror. moved the callbacks into...
[OpenSRF.git] / examples / multisession-test.pl
1 #!/usr/bin/perl
2 use lib '/openils/lib/perl5/';
3 use OpenSRF::System;
4 use OpenILS::Application::AppUtils;
5 use OpenILS::Event;
6 use OpenSRF::EX qw/:try/;
7 use OpenSRF::Utils::JSON;
8 use Data::Dumper;
9 use OpenILS::Utils::Fieldmapper;
10 use Digest::MD5 qw/md5_hex/;
11 use OpenSRF::Utils qw/:daemon/;
12 use OpenSRF::MultiSession;
13 use OpenSRF::AppSession;
14 use Time::HiRes qw/time/;
15
16 my $config = shift;
17
18 unless (-e $config) {
19         die "Gimme a config file!!!";
20 }
21 OpenSRF::System->bootstrap_client( config_file => $config );
22
23 if (!@ARGV) {
24         @ARGV = ('open-ils.storage','opensrf.system.echo');
25 }
26
27 my $app = shift;
28
29 my $count = 100;
30
31 my $overhead = time;
32
33 my $mses = OpenSRF::MultiSession->new( app => $app, cap => 10, api_level => 1 );
34
35 $mses->success_handler(
36         sub {
37                 my $ses = shift;
38                 my $req = shift;
39                 print $req->{params}->[0] . "\t: " . OpenSRF::Utils::JSON->perl2JSON($req->{response}->[0]->content)."\n";
40         }
41 );
42
43 $mses->failure_handler(
44         sub {
45                 my $ses = shift;
46                 my $req = shift;
47                 warn "record $req->{params}->[0] failed: " . OpenSRF::Utils::JSON->perl2JSON($req->{response});
48         }
49 );
50
51
52 $mses->connect;
53
54 my $start = time;
55 $overhead = $start - $overhead;
56
57 for (1 .. $count) {
58         $mses->request( @ARGV,$_ );
59 }
60 $mses->session_wait(1);
61 $mses->disconnect;
62
63 my $end = time;
64
65 my @c = $mses->completed;
66 my @f = $mses->failed;
67
68 my $x = 0;
69 $x += $_->{duration} for (@c);
70
71 print "\n". '-'x40 . "\n";
72 print "Startup Overhead: ".sprintf('%0.3f',$overhead)."s\n";
73 print "Completed Commands: ".@c."\n";
74 print "Failed Commands: ".@f."\n";
75 print "Serial Run Time: ".sprintf('%0.3f',$x)."s\n";
76 print "Serial Avg Time: ".sprintf('%0.3f',$x/$count)."s\n";
77 print "Total Run Time: ".sprintf('%0.3f',$end-$start)."s\n";
78 print "Total Avg Time: ".sprintf('%0.3f',($end-$start)/$count)."s\n";
79