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