Recently on this list the idea of 'pinning' or locking the root apache process 
in memory has been discussed with some interest. The reason being was that some
users have experienced the situtaion where a server becomes loaded, and the root
apache process gets swapped out, and in the process loses some of its shared 
memory. Future child processes that are forked also share in the loss of shared
memory, so methods like using GtopLimit to 'recyle' child processes when their
shared memory becomes too low cease to work because when they come up, they are
already too low on shared memory. 

In our systems we had attempted this but it always came down to the same problem
--the root process would lose its shared memory, to the point that any child 
process would come up, serve a request, find that it was beyond the threshold 
for shared memory and die. The only help was to restart Apache altogether.

So in scouring the list I found someone mentioning using the mlockall C function
to lock the pages of the core apache process in memory. Some handy .xs code was
provided, so I built a module, Sys::Mman, which wraps mlockall, and makes it 
available to Perl.

We installed this on our servers, and call mlockall right at the end of our
preload stuff, i.e., the end of the 'startup.pl'-style script called from 
httpd.conf. The result has been very encouraging. The core apache process is
able then to maintain all its shared memory, and child processes that are forked
are able to start with high amounts of shared memory, all making for a much
happier system.

Now I also read that probably better than this would be to ensure that you
never swap by tuning MaxClients, as well as examining our Perl code to make it
less prone to lose shared memory. We're working on that sort of tuning, but
in volatile environments like ours, where we serve a very large amount of data,
and new code is coming out almost daily here and there, locking the core
httpd in memory has been very helpful. I just thought I would let others know
on the list that it is feasible, and works well in our environment.

If there's enough interest I might put the module up on CPAN, but it's really
very simple. h2xs did most of the work for me. And thanks to Doug MacEachern for
posting the .xs code. It worked like a charm.

FWIW,

-- Dan Hanks
========================================================================
   Daniel Hanks - Systems/Database Administrator
   About Inc., Web Services Division
========================================================================

Reply via email to