line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FCGI::ProcManager::MaxRequests; |
2
|
6
|
|
|
6
|
|
150227
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
239
|
|
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
33
|
use base 'FCGI::ProcManager'; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
8834
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
6
|
|
|
6
|
1
|
6316
|
my $proto = shift; |
10
|
6
|
|
|
|
|
501
|
my $self = $proto->SUPER::new(@_); |
11
|
6
|
100
|
100
|
|
|
1259
|
$self->{max_requests} = $ENV{PM_MAX_REQUESTS} || 0 unless defined $self->{max_requests}; |
12
|
6
|
|
|
|
|
41
|
return $self; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
13
|
|
|
13
|
1
|
689
|
sub max_requests { shift->pm_parameter('max_requests', @_); } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub handling_init { |
18
|
3
|
|
|
3
|
1
|
748238
|
my $self = shift; |
19
|
3
|
|
|
|
|
607
|
$self->SUPER::handling_init(); |
20
|
3
|
|
|
|
|
414
|
$self->{_request_counter} = $self->max_requests; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub pm_post_dispatch { |
24
|
5
|
|
|
5
|
1
|
4826
|
my $self = shift; |
25
|
5
|
100
|
66
|
|
|
29
|
if ($self->max_requests > 0 && --$self->{_request_counter} == 0) { |
26
|
2
|
|
|
|
|
74
|
$self->pm_exit("safe exit after max_requests"); |
27
|
|
|
|
|
|
|
} |
28
|
3
|
|
|
|
|
508
|
$self->SUPER::pm_post_dispatch(); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
FCGI::ProcManager::MaxRequests - restrict max number of requests by each child |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Usage same as FCGI::ProcManager: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use CGI::Fast; |
40
|
|
|
|
|
|
|
use FCGI::ProcManager::MaxRequests; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $m = FCGI::ProcManager::MaxRequests->new({ |
43
|
|
|
|
|
|
|
n_processes => 10, |
44
|
|
|
|
|
|
|
max_requests => 100, |
45
|
|
|
|
|
|
|
}); |
46
|
|
|
|
|
|
|
$m->manage; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
while( my $cgi = CGI::Fast->new() ) { |
49
|
|
|
|
|
|
|
$m->pm_pre_dispatch(); |
50
|
|
|
|
|
|
|
... |
51
|
|
|
|
|
|
|
$m->pm_post_dispatch(); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
FCGI-ProcManager-MaxRequests is a extension of FCGI-ProcManager that allow |
57
|
|
|
|
|
|
|
restrict fastcgi processes to process only limiting number of requests. |
58
|
|
|
|
|
|
|
This may help avoid growing memory usage and compensate memory leaks. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This module subclass L. After server process max_requests |
61
|
|
|
|
|
|
|
number of requests, it simple exit, and manager starts another server process. |
62
|
|
|
|
|
|
|
Maximum number of requests can be set from PM_MAX_REQUESTS environment variable, |
63
|
|
|
|
|
|
|
max_requests - constructor argument and max_requests accessor. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 OVERLOADED METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 new |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $pm = FCGI::ProcManager::MaxRequests->new(\%args); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Constructs new proc manager object. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 max_requests |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$pm->max_requests($max_requests); |
76
|
|
|
|
|
|
|
my $max_requests = $pm->max_requests; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Set/get current max_requests value. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 handling_init |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Initialize requests counter after new worker process forks. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 pm_post_dispatch |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Do all work. Decrements requests counter after each request and exit worker when needed. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 USING WITH CATALYST |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
At this time, L do not allow set any args to FCGI::ProcManager subclass constructor. |
91
|
|
|
|
|
|
|
Because of this we should use environment PM_MAX_REQUESTS ;-) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
PM_MAX_REQUESTS=100 ./script/myapp_fastcgi.pl -n 10 -l : -d -M FCGI::ProcManager::MaxRequests |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SEE ALSO |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
You can also see L, but it don't support TCP sockets and try use CGI::Fast... |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Vladimir Timofeev, C<< >> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 BUGS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
107
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
108
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SUPPORT |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
perldoc FCGI::ProcManager::MaxRequests |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
You can also look for information at: |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * CPAN Ratings |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * Search CPAN |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * Source code repository |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Copyright 2008 Vladimir Timofeev. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
149
|
|
|
|
|
|
|
under the same terms as Perl itself. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |