Apache, Out of memory

apache-2.2ubuntu-9.04

I get very often the following messages:
alt text

I guess this happens because I have not enough RAM. Is this correct ?

Is there something I can do ?

thanks

update: I've MPM prefork installed

<IfModule mpm_prefork_module>
StartServers          5
MinSpareServers       5
MaxSpareServers      10
MaxClients          150
MaxRequestsPerChild   0

Best Answer

This is your problem:

MaxRequestsPerChild   0

A zero value means that the individual child processes will never exit, slowly consuming more and more RAM (it's code dependent how long it will take). Set that value to something within reason (try 5000 to start), then after a good bit and Apache is spun up to handle load you will see a point in your 'ps' of where the Apache child is topping out in resident (RSS) memory.

Using this value as your maximum child size, you then have to set MaxClients to be the memory you want to use. So if you have 256mb, you'd want to leave some for the OS so let's say 248MB for Apache (this isn't exact, depends on what else is on your system). This means you could have at most 1.5MB for each Apache child which is kind of silly - most Apache processes tend to run in the 15MB range on average (some higher).

Let's say you have an average 20MB Apache child process with 5000 requests - you could decrease that to 15MB (example) if you dropped the requests to 4000; it's something you have to play with. Whatever combination you come up with, do the math and set your MaxClients to top out (248/15 = 16, e.g.).

You have to do a little playing around with the values to narrow in on where you want each one to get the memory settings just right. With your current setting of 0 you're letting Apache run amok.