I'm running Perl programs in mod_perl in Apache (2.2) on RHEL.

Processes that grow too large ruin performance; I want a general way to prevent that. I don't mind letting an oversized process die, but I want to detect and log that event and provide some Web feedback to the user.

Unix usage limits seem like the solution. The bash shell's 'ulimit' reports on and sets limits. They're inherited by children through fork() and exec(). So, for example, I can start Apache with the script

#!/bin/sh ulimit -v 1024000 exec /usr/sbin/apachectl restart

and limit each process' virtual memory to 1 GB. But detecting and handling the death of a process that tries to allocate more memory seems hard. There are some hints in documentation (http://search.cpan.org/~gozer/mod_perl-1.29/mod_perl_traps.pod#Perl_Modules_and_Extensions and http://www.perl.com/doc/manual/html/pod/perlvar.html) that by

1) compiling Perl with -DPERL_EMERGENCY_SBRK (run "./Configure -DPERL_EMERGENCY_SBRK -des -Dprefix=~/localperl" before make) (It seems that the code between lines 1130 and 1279 of "malloc.c" run if PERL_EMERGENCY_SBRK is defined.)

2) and defining $SIG{__DIE__} = \&deathHandler;

one can run a little code in deathHandler before finally dying.

Does this make sense? Will it work?

Thanks

A


In reply to Monitoring the death of oversized Perl processes by arthurg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.