0

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

aneuryzm
  • 1,614
  • 5
  • 25
  • 40

5 Answers5

2

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.

  • Thanks! That was useful. This part was not clear to me.. "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." Could you elaborate it ? – aneuryzm Sep 26 '10 at 15:10
  • Also, should I add the ServerLimit parameter ? – aneuryzm Sep 26 '10 at 15:11
  • One more thing: my issue is that after a sequence of requests the server stops to work. For example I have a slideshow and I retrieve images with ajax. After 5 clicks the images stop to load. What should I change ? – aneuryzm Sep 26 '10 at 15:20
0

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

System kill Apache processes because it needs more memory

Is there something I can do ?

Add memory, swap or tune mpm settings(/etc/apache2/apache2.conf, search MPM specific)

bindbn
  • 5,153
  • 2
  • 26
  • 23
  • what are good parameters for a server with only 256MB of memory ? You can see in my question my current values. I've read they are for 1GB instead.. – aneuryzm Sep 26 '10 at 14:31
0

The biggest thing you can do is trim all daemons to only use the memory that they need in order to get the job done. Reduce your database memory cache, reduce the number of httpd children, disable unused httpd modules, etc. Obviously this will affect performance, so you'll have to monitor the system for a while after and tweak as necessary.

Resist the temptation to patch the problem by adding swap space. This is actually a non-solution, since system performance will be driven into the ground.

Ignacio Vazquez-Abrams
  • 45,019
  • 5
  • 78
  • 84
  • ok, anyway, I've just installed apache + php + mysql on a Ubuntu 9.04 and I'm an absolute beginner, so could you give me some more specific sequence of commands ? Otherwise i have to ask your points one by one.. – aneuryzm Sep 26 '10 at 14:06
0

I'm assuming you're using the preform MPM (which you can check by running apache2 -V and looking for forked: yes in the output).

First, try editing /etc/apache2/apache2.conf and lowering the MaxClients value. This value determines how many concurrent clients apache can serve. Obviously you'll need to restart/reload apache for the change to take effect.

Alternatively, if you don't have to use the prefork MPM (the most likely reason you might have to would be that you're running PHP), you can switch to the worker MPM. This uses threads rather than processes for concurrency and is therefore a lot more memory efficient.

To do this, run:

aptitude install apache2-mpm-worker
npad
  • 101
  • 2
  • uhm I actually have prefork working. (see uptated question). Isn't prefork already good ? – aneuryzm Sep 26 '10 at 14:21
  • Also, I've updated my question with my current values. The default are for 1GB memory, I only have 256MB, so could you advice me what values to use instead ? – aneuryzm Sep 26 '10 at 14:32
0

you probably have a buggy application running inside apache, for example a badly written php extension or custom apache module or just a runaway script. your maxrequestsperchild is set to zero so apache's fork()ed children will be kept alive "forever" to serve requests (where forever is relatively defined to the universe of your apache main process). while doing that your buggy application requests memory without ever freeing it so the children will keep sucking memory. OS marks these processes as good candidates for the next outofmem bloodshed. if you want to hide the bug and pretend nothing happened go and set maxrequestsperchild to something like 500 (this value really depends on how many requests per second your service handles, e.g. if you serve 500reqps then 5000 would be a good starting point so you will not cause fork thundering herds). don't use mpm worker, that will totally kill entire thread pools when OS decides to forcibly free some memory, plus most of php extensions arent exactly threadsafe (supposing you're using php). best thing to do is to start debugging. if not with gdb then i believe you can find some apache modules written for debugging and profiling running applications.

user237419
  • 1,663
  • 8
  • 8
  • uhm ok, well I've just installed apache and php on Ubuntu (standard installation and nothing more...). I've now set the MPM parameters is much better, but for example after a sequence of AJAX calls the server stops to work. I need to know the optimal values for a VPS with 256MB ram – aneuryzm Sep 26 '10 at 15:25
  • you can try switching off keepalive. i assume now it's on (the default on most distros). with keepalive on you will have a one-to-one server_process-client mapping and with your ajax image loading application this can be bad ("on" is already bad when used with a preforking mpm, without ajax keeping connections alive. with ajax should be worst) – user237419 Sep 26 '10 at 16:09
  • I believe I didn't make myself exactly clear with my previous comment. so, setting maxrequestsperchild to something like 500 or 1000 and keepalive to off will be a good combination for an apache serving ajax clients. keepalives are bad in 99% of all web scenarios and shouldn't come set to on by default but they keep doing it :) – user237419 Sep 26 '10 at 16:18