Revision 253d7562
Von Sven Schöling vor mehr als 5 Jahren hinzugefügt
SL/Dispatcher.pm | ||
---|---|---|
231 | 231 |
while ($request->Accept() >= 0) { |
232 | 232 |
$self->handle_request($request); |
233 | 233 |
|
234 |
$self->restart_after_request(1) if $self->_interface_is_fcgi && $self->_memory_usage_is_too_high;
|
|
234 |
$self->restart_after_request(1) if $self->_interface_is_fcgi && SL::System::Process::memory_usage_is_too_high();
|
|
235 | 235 |
$request->LastCall if $self->restart_after_request; |
236 | 236 |
} |
237 | 237 |
|
... | ... | |
497 | 497 |
end_request(); |
498 | 498 |
} |
499 | 499 |
|
500 |
sub _parse_number_with_unit { |
|
501 |
my ($number) = @_; |
|
502 |
|
|
503 |
return undef unless defined $number; |
|
504 |
return $number unless $number =~ m{^ \s* (\d+) \s* ([kmg])b \s* $}xi; |
|
505 |
|
|
506 |
my %factors = (K => 1024, M => 1024 * 1024, G => 1024 * 1024 * 1024); |
|
507 |
|
|
508 |
return $1 * $factors{uc $2}; |
|
509 |
} |
|
510 |
|
|
511 |
sub _memory_usage_is_too_high { |
|
512 |
return undef unless $::lx_office_conf{system}; |
|
513 |
|
|
514 |
my %limits = ( |
|
515 |
rss => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_rss}), |
|
516 |
size => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_vsz}), |
|
517 |
); |
|
518 |
|
|
519 |
# $::lxdebug->dump(0, "limits", \%limits); |
|
520 |
|
|
521 |
return undef unless $limits{rss} || $limits{vsz}; |
|
522 |
|
|
523 |
my %usage; |
|
524 |
|
|
525 |
my $in = IO::File->new("/proc/$$/status", "r") or return undef; |
|
526 |
|
|
527 |
while (<$in>) { |
|
528 |
chomp; |
|
529 |
$usage{lc $1} = _parse_number_with_unit($2) if m{^ vm(rss|size): \s* (\d+ \s* [kmg]b) \s* $}ix; |
|
530 |
} |
|
531 |
|
|
532 |
$in->close; |
|
533 |
|
|
534 |
# $::lxdebug->dump(0, "usage", \%usage); |
|
535 |
|
|
536 |
foreach my $type (keys %limits) { |
|
537 |
next if !$limits{$type}; |
|
538 |
next if $limits{$type} >= ($usage{$type} // 0); |
|
539 |
|
|
540 |
$::lxdebug->message(LXDebug::WARN(), "Exiting due to memory size limit reached for type '${type}': limit " . $limits{$type} . " bytes, usage " . $usage{$type} . " bytes"); |
|
541 |
|
|
542 |
return 1; |
|
543 |
} |
|
544 |
|
|
545 |
return 0; |
|
546 |
} |
|
547 |
|
|
548 | 500 |
sub end_request { |
549 | 501 |
die SL::Dispatcher->END_OF_REQUEST; |
550 | 502 |
} |
SL/System/Process.pm | ||
---|---|---|
25 | 25 |
return $cached_exe_dir; |
26 | 26 |
} |
27 | 27 |
|
28 |
sub _parse_number_with_unit { |
|
29 |
my ($number) = @_; |
|
30 |
|
|
31 |
return undef unless defined $number; |
|
32 |
return $number unless $number =~ m{^ \s* (\d+) \s* ([kmg])b \s* $}xi; |
|
33 |
|
|
34 |
my %factors = (K => 1024, M => 1024 * 1024, G => 1024 * 1024 * 1024); |
|
35 |
|
|
36 |
return $1 * $factors{uc $2}; |
|
37 |
} |
|
38 |
|
|
39 |
sub memory_usage_is_too_high { |
|
40 |
return undef unless $::lx_office_conf{system}; |
|
41 |
|
|
42 |
my %limits = ( |
|
43 |
rss => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_rss}), |
|
44 |
size => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_vsz}), |
|
45 |
); |
|
46 |
|
|
47 |
# $::lxdebug->dump(0, "limits", \%limits); |
|
48 |
|
|
49 |
return undef unless $limits{rss} || $limits{vsz}; |
|
50 |
|
|
51 |
my %usage; |
|
52 |
|
|
53 |
my $in = IO::File->new("/proc/$$/status", "r") or return undef; |
|
54 |
|
|
55 |
while (<$in>) { |
|
56 |
chomp; |
|
57 |
$usage{lc $1} = _parse_number_with_unit($2) if m{^ vm(rss|size): \s* (\d+ \s* [kmg]b) \s* $}ix; |
|
58 |
} |
|
59 |
|
|
60 |
$in->close; |
|
61 |
|
|
62 |
# $::lxdebug->dump(0, "usage", \%usage); |
|
63 |
|
|
64 |
foreach my $type (keys %limits) { |
|
65 |
next if !$limits{$type}; |
|
66 |
next if $limits{$type} >= ($usage{$type} // 0); |
|
67 |
|
|
68 |
{ |
|
69 |
no warnings 'once'; |
|
70 |
$::lxdebug->message(LXDebug::WARN(), "Exiting due to memory size limit reached for type '${type}': limit " . $limits{$type} . " bytes, usage " . $usage{$type} . " bytes"); |
|
71 |
} |
|
72 |
|
|
73 |
return 1; |
|
74 |
} |
|
75 |
|
|
76 |
return 0; |
|
77 |
} |
|
78 |
|
|
28 | 79 |
1; |
29 | 80 |
__END__ |
30 | 81 |
|
... | ... | |
51 | 102 |
(C<login.pl> etc.) and modules (sub-directory C<SL/> etc.) are located |
52 | 103 |
in. |
53 | 104 |
|
105 |
=item C<memory_usage_is_too_high> |
|
106 |
|
|
107 |
Returns true if the current process uses more memory than the configured |
|
108 |
limits. |
|
109 |
|
|
54 | 110 |
=back |
55 | 111 |
|
56 | 112 |
=head1 BUGS |
scripts/task_server.pl | ||
---|---|---|
25 | 25 |
use SL::DBUpgrade2; |
26 | 26 |
use SL::DB::AuthClient; |
27 | 27 |
use SL::DB::BackgroundJob; |
28 |
use SL::Dispatcher;
|
|
28 |
use SL::System::Process;
|
|
29 | 29 |
use SL::BackgroundJob::ALL; |
30 | 30 |
use SL::Form; |
31 | 31 |
use SL::Helper::DateTime; |
... | ... | |
332 | 332 |
|
333 | 333 |
clean_before_sleeping(); |
334 | 334 |
|
335 |
if (SL::Dispatcher::_memory_usage_is_too_high()) {
|
|
335 |
if (SL::System::Process::memory_usage_is_too_high()) {
|
|
336 | 336 |
return; |
337 | 337 |
} |
338 | 338 |
|
Auch abrufbar als: Unified diff
memory_usage_is_too_high von Dispatcher nach System::Process verschoben
(cherry picked from commit c0e3364a21b2da1c61564ddb8d9afa5ab6489f9c)