]> git.evergreen-ils.org Git - OpenSRF.git/blob - examples/multisession-test.pl
XSD from Dan Scott for validating the ~/.srfsh.xml config file.
[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 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 use JSON;
16
17 my $config = shift;
18
19 unless (-e $config) {
20         die "Gimme a config file!!!";
21 }
22 OpenSRF::System->bootstrap_client( config_file => $config );
23
24 if (!@ARGV) {
25         @ARGV = ('open-ils.storage','opensrf.system.echo');
26 }
27
28 my $app = shift;
29
30 my $count = 100;
31
32 my $overhead = time;
33
34 my $mses = OpenSRF::MultiSession->new( app => $app, cap => 10, api_level => 1 );
35
36 $mses->success_handler(
37         sub {
38                 my $ses = shift;
39                 my $req = shift;
40                 print $req->{params}->[0] . "\t: " . JSON->perl2JSON($req->{response}->[0]->content)."\n";
41         }
42 );
43
44 $mses->failure_handler(
45         sub {
46                 my $ses = shift;
47                 my $req = shift;
48                 warn "record $req->{params}->[0] failed: ".JSON->perl2JSON($req->{response});
49         }
50 );
51
52
53 $mses->connect;
54
55 my $start = time;
56 $overhead = $start - $overhead;
57
58 for (1 .. $count) {
59         $mses->request( @ARGV,$_ );
60 }
61 $mses->session_wait(1);
62 $mses->disconnect;
63
64 my $end = time;
65
66 my @c = $mses->completed;
67 my @f = $mses->failed;
68
69 my $x = 0;
70 $x += $_->{duration} for (@c);
71
72 print "\n". '-'x40 . "\n";
73 print "Startup Overhead: ".sprintf('%0.3f',$overhead)."s\n";
74 print "Completed Commands: ".@c."\n";
75 print "Failed Commands: ".@f."\n";
76 print "Serial Run Time: ".sprintf('%0.3f',$x)."s\n";
77 print "Serial Avg Time: ".sprintf('%0.3f',$x/$count)."s\n";
78 print "Total Run Time: ".sprintf('%0.3f',$end-$start)."s\n";
79 print "Total Avg Time: ".sprintf('%0.3f',($end-$start)/$count)."s\n";
80