Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 253d7562

Von Sven Schöling vor mehr als 5 Jahren hinzugefügt

  • ID 253d756269c58fc019073c2d8da597f9f9b65e48
  • Vorgänger bc2b5fe6
  • Nachfolger afdd12ed

memory_usage_is_too_high von Dispatcher nach System::Process verschoben

(cherry picked from commit c0e3364a21b2da1c61564ddb8d9afa5ab6489f9c)

Unterschiede anzeigen:

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
}

Auch abrufbar als: Unified diff