No less important than maximizing shared memory is restricting the absolute size of the processes. If the processes grow after each request, and if nothing restricts them from growing, you can easily run out of memory.
Again you can set the MaxRequestsPerChild directive to kill the processes after a few requests have been served. But as we explained in the previous section, this solution is not as good as one that monitors the process size and kills it only when some limit is reached.
If you have Apache::GTopLimit (described in the previous section), you can limit a process's memory usage by setting the $Apache::GTopLimit::MAX_PROCESS_SIZE directive. For example, if you want processes to be killed when they reach 10 MB, you should put the following in your startup.pl file:
$Apache::GTopLimit::MAX_PROCESS_SIZE = 10240;
Just as when limiting shared memory, you can set a limit for the current process using the set_max_size( ) method in your code:
use Apache::GTopLimit; Apache::GTopLimit->set_max_size(10000);
For Apache::SizeLimit, the equivalents are:
use Apache::SizeLimit; $Apache::SizeLimit::MAX_PROCESS_SIZE = 10240;
use Apache::SizeLimit; Apache::SizeLimit->setmax(10240);