Perlbal/Plugin/Queues.pm

filter: Statementstmt 29.4% 10 / 34 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 4 totaltotal 22.8% 13 / 57 CC 5 SCAR 26.0
CC
5
Cov
23%
__ANON__
30.0
register
2.0
unregister
2.0
CRAP 13.4
« Perlbal/Plugin/FlvStreaming.pm ↑ Summary Perlbal/Plugin/Cgilike.pm »
1 ###########################################################################
2 # simple queue length header inclusion plugin
3 ###########################################################################
4  
5 package Perlbal::Plugin::Queues;
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶no warnings qw(deprecated);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # called when we're being added to a service
12 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my ($class, $svc) = @_;
14  
15 # more complicated statistics
16 0 ▶ $svc->register_hook('Queues', 'backend_client_assigned', sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
17 0 my Perlbal::BackendHTTP $obj = shift;
18 0 my Perlbal::HTTPHeaders $hds = $obj->{req_headers};
19 0 my Perlbal::Service $svc = $obj->{service};
20 0 ▶ return 0 unless defined $hds && defined $svc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hds and defined $svc 0 0 0
Condition0%0/3
defined $hds and defined $svc
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hds and defined $svc
defined $hds defined $svc
Truth table0%0/3
A and B
A= defined $hdsB= defined $svc
ABresult
0X0
100
111
21  
22 # determine age of oldest (first in line)
23 0 my $now = time;
24 0 my Perlbal::ClientProxy $cp = $svc->{waiting_clients}->[0];
25 0 ▶ my $age = defined $cp ? ($now - $cp->{last_request_time}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $cp ? : 0 0 0
26  
27 # now do the age of the high priority queue
28 0 $cp = $svc->{waiting_clients_highpri}->[0];
29 0 ▶ my $hpage = defined $cp ? ($now - $cp->{last_request_time}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $cp ? : 0 0 0
30  
31 # setup the queue length headers
32 0 $hds->header('X-Queue-Count', scalar(@{$svc->{waiting_clients}}));
33 0 $hds->header('X-Queue-Age', $age);
34 0 $hds->header('X-HP-Queue-Count', scalar(@{$svc->{waiting_clients_highpri}}));
35 0 $hds->header('X-HP-Queue-Age', $hpage);
36 0 return 0;
37 0 });
38  
39 0 return 1;
40 }
41  
42 # called when we're no longer active on a service
43 0 ▶sub unregister {
Subroutine unregister: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my ($class, $svc) = @_;
45  
46 # clean up time
47 0 $svc->unregister_hooks('Queues');
48 0 return 1;
49 }
50  
51 # we don't do anything in here
52 0 ▶sub load { return 1; }
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
53 0 ▶sub unload { return 1; }
Subroutine unload: not called CC=1 SCAR=6.9
Pod undocumented
54  
55 1 1;
« Perlbal/Plugin/FlvStreaming.pm ↑ Summary Perlbal/Plugin/Cgilike.pm »