Apache/Resource Limits

From Devpit
Jump to: navigation, search

Apache supports resource limits on CGIs. See Apache's Manual for details on that. However, these only apply to processes that Apache starts, not Apache itself. When using mod_perl, it may be desirable to limit Apache itself. (Remember, mod_perl programs don't fork. mod_perl loads the Perl interpreter directly into Apache.) If you have mod_perl installed, an easy way to limit Apache is to add the following to startup.pl:

# Set limits Apache, and along with it, mod_perl programs.
use BSD::Resource;
my $prio = getpriority(PRIO_PROCESS, 0);
setpriority(PRIO_PROCESS, 0, ((PRIO_MAX - $prio) / 4) + $prio);  # lower priority
setrlimit(RLIMIT_VMEM, 419430400, 419430400);  # virtual memory, bytes
setrlimit(RLIMIT_CPU, 30, 30);  # CPU seconds