Simple trick to get more copy-on-write goodness

jjore on 2009-08-23T23:45:26

I've got a preforking Apache server at work that's not sharing enough memory among the many children. This snippet helped identify post-fork module loading. I put an @INC hook at the end of my httpd.conf and it writes a warning to my log whenever the forked child loads something.

# httpd.conf
...

  # This fragment goes at the end, when I think I'm ready to let Apache start forking
  $main::PARENT_PID = $$;
  unshift @INC, sub {
    print STDERR "LATE LOAD: $_[1]\n" if $$ != $main::PARENT_PID;
    return undef;
  };



I just found 233 modules I was loading post-fork. Oops! It's now trivial to make sure my httpd.conf has the proper lines to load the stuff I was forgetting to:

# httpd.conf
LoadModule XML::LibXML
LoadModule LWP::UserAgent
...


What we did instead...

Alias on 2009-08-24T05:37:59

Rather than stuff everything into the Apache config, we ended up making an ::All package for our application.

package Foo::All;

use Apache::Constant ();
use XML::LibXML ();
etc...
etc...

mod_perl required?

robinsmidsrod on 2009-08-24T14:55:41

Does this only work with mod_perl-based software (I would think so), or can you use it with CGI-based dispatch?

Re:mod_perl required?

jjore on 2009-08-24T20:04:12

Probably applies to FCGI but not generalized CGI.