11 sub _parse_number_with_unit {
14 return undef unless defined $number;
15 return $number unless $number =~ m{^ \s* (\d+) \s* ([kmg])b \s* $}xi;
17 my %factors = (K => 1024, M => 1024 * 1024, G => 1024 * 1024 * 1024);
19 return $1 * $factors{uc $2};
22 sub _memory_usage_is_too_high {
23 return undef unless $::lx_office_conf{system};
26 rss => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_rss}),
27 size => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_vsz}),
30 # $::lxdebug->dump(0, "limits", \%limits);
32 return undef unless $limits{rss} || $limits{vsz};
36 my $in = IO::File->new("/proc/$$/status", "r") or return undef;
40 $usage{lc $1} = _parse_number_with_unit($2) if m{^ vm(rss|size): \s* (\d+ \s* [kmg]b) \s* $}ix;
45 # $::lxdebug->dump(0, "usage", \%usage);
47 foreach my $type (keys %limits) {
48 next if !$limits{$type};
49 next if $limits{$type} >= ($usage{$type} // 0);
51 $::lxdebug->message(LXDebug::WARN(), "Exiting due to memory size limit reached for type '${type}': limit " . $limits{$type} . " bytes, usage " . $usage{$type} . " bytes");
59 our $dispatcher = SL::Dispatcher->new('FastCGI');
60 $dispatcher->pre_startup_setup;
61 SL::FCGIFixes::apply_fixes();
62 $dispatcher->pre_startup_checks;
64 my $request = FCGI::Request();
65 while ($request->Accept() >= 0) {
66 $dispatcher->handle_request($request);
67 exit if _memory_usage_is_too_high();