Just to expound on what perrin said... Take all of your frequently used perl modules and "preload" them. That is, add a line in your apache conf file to
PerlModule <module-name>
The basic idea is that the root apache process's perl interpretter reads in and compiles those perl modules before it forks off children for handling http-requests. The way that fork() works means that all the compiled representations of all of these perl modules end up residing in shared memory, rather than a process's individual memory.

Say you've got 15M worth of modules that your processes typically use... you end up spending that 15M only once, in total, rather than once per apache process.

The trade-off is that apache takes slightly longer to start up initially, because it has to compile all of your perl code before the server starts answering requests. Also, if you are developing against a server that preloads modules, bear in mind that for your changes to take affect in the server, you need to stop apache and then start apache (rather than simply being able to HUP it).

Anyway, another thing you can do hear is to use the MaxRequestsPerChild apache config directive to tell your mod_perl processes to die-off and respawn every so-many requests. The point of this is that if your mod_perl processes steadly accumulate compiled perl modules over time, then every so-many requests, you just reset the process's memory. Of course, this is done by wiping the process and starting over from scratch, rather than by selectively unloading modules. But still, it's better than nothing.

The trade-off here is that you'll be wasting a certain amount of processor resources (not a whole ton) on exiting, re-forking, and re-compiling. However, if done in conjunction with preloading modules, the fork of the child process is fairly cheap (because it doesn't have to compile your comonly used perl modules).

Overall, I'd recomend a combination of both: preload comonly used modules, and have your processes suicide after many requests (find an appropriate number for yourself... I'd suggest 100 to start with) so that infrequently used modules don't stay around forever.


------------
:Wq
Not an editor command: Wq

In reply to Re: Re: mod_perl memory issues... by etcshadow
in thread mod_perl memory issues... by cLive ;-)

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.