Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My apache server has been gobbling up the memory recently.

I've been automatically restarting it when the free + cached memory gets below 50M, and that's started to occur quite often. I use a dual apache setup, where one handles all the perl and the other handles static pages, and it's the perl one that's bloating, so I'm assuming that it's due to my perl code.

But which one of my many perl scripts is the problem? Any advice on figuring out which script is misbehaving?

Replies are listed 'Best First'.
Re: Where is my cgi memory leak?
by dws (Chancellor) on Nov 20, 2002 at 07:37 UTC
    My apache server has been gobbling up the memory recently. ... Any advice on figuring out which script is misbehaving?

    Backtrack. Look over diffs of what you changed most recently. Here's where the effort of putting everything under source-code control (e.g., with CVS) pays off.

Re: Where is my cgi memory leak?
by AcidHawk (Vicar) on Nov 20, 2002 at 07:39 UTC

    Is this a production system or developement? The only reason I ask is that you could tackle this by process of elimination where you remove all scripts and only add them one at a time until the issue of leaking memory starts again. But then if this is a production system and you can't remove the cgi scripts... hmmm... then what.. ?

    I think we kinda need more info..?

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
Re: Where is my cgi memory leak?
by shotgunefx (Parson) on Nov 20, 2002 at 08:09 UTC
    Is this running under mod_perl (Apache::Registry,etc)?

    You say CGI, but I thought I'd ask anyway. In my experience, it's odd to leak a lot of memory under CGI (maybe I'm just lucky). Under mod_perl, if your not careful it's likely. You could always try setting MaxRequestsPerChild lower to try and contain the problem in the meanwhile.

    -Lee

    "To be civilized is to deny one's nature."
      Also persistant data storage such as caching of database handles in Apache::DBI, Statements using DBIs prepare_chached and cached templates in HTML::Template

      Hope this helps
      UnderMine

Re: Where is my cgi memory leak?
by Anonymous Monk on Nov 21, 2002 at 03:46 UTC
    It is a production setup and it is not mod_perl, just plain ol' cgi.

    One thing I was thinking about was putting some code at the beginning and end of each script (or rather putting it into a module and calling at the beginning and end) to check memory usage and write to the log if memory usage has increased. But then, I'd need to check memory usage for just that apache thread.

    An alternative to taking scripts offline, is to proxy to yet another local apache server process, and move different scripts to the proxy server.