1

My situation is following: We run Magento Professional on a 15Gb ram instance, rackspace.

When running htop, we could see that 'apache2 -k start' keeps spawning more child processes, some of them eats ~900Mb of memory.

When memory is almost used up, all sites time out or become very slow. When memory is all used up, it seems that some of these processes got killed to free memory.

Then the same procedures happen.

My question is, could we setup ubuntu / apache to kill off child processes and free memory when memory usage reaches 85-90% ?

ALAN VO
  • 19
  • 3
  • 5
    Why not simply limit the number of child processes Apache can spawn (MaxClients parameter), and also the MaxRequestsPerChild directive to fix memory leakage ? – davidgo Jan 10 '14 at 04:07
  • you could set up some cgroups to limit the total memory apache can use. – Rooster Jan 10 '14 at 20:43

1 Answers1

1

From what I found about OOM OOM:

when a parent task is selected, the oom killer will sacrifice any first generation children with separate address spaces instead, if possible. This avoids servers and important system daemons from being killed and loses the minimal amount of work.

How are you determining that Apache child processes are not getting killed first? Its possible that OOM kills the child process but the system is still not out of the woods and it needs to kill another child process (depending on how many are spawned)(I am not a heavy apache user so I dont know in detail how apache address space is handled amongst its child processes)

Secondly, this is from Apache Docs tuning section Apache Tuning:

You can, and should, control the MaxRequestWorkers setting so that your server does not spawn so many children it starts swapping. I would look in to what davidgo suggested.

I hope this helps.

APZ
  • 954
  • 2
  • 12
  • 24
  • It does kill off the child processes when it's very much used up with all memory (100% used). When it was about to reach that stage, the whole system became very slow. I wanted to know if we could detect when it was reaching 90%, and start the killing off so the system does not slow down. – ALAN VO Jan 13 '14 at 01:02
  • IIUC brk() or mmap() is called when a process needs memory, which'll call vm_enough_memory(), if non-overcommit is set then it won't let the process have any if the system is out (-ENOMEM). Otherwise the system gets virtual memory, which isn't necessarily mapped yet. In case mapping fails then the kernel calls out_of_memory() and this lead to OOM kick in. Hence I am not sure if we can make OOM kick in early. I suggest you look in to overcommit ratio, you might want to set it to 2 (https://www.kernel.org/doc/Documentation/vm/overcommit-accounting). Continued in the next comment. – APZ Jan 13 '14 at 07:40
  • continued.. in case you don't want to disable over commit and we know that apache is your problem you can try ulimit. You probably want "ulimit -v" for limiting virtual memory usage. 2) Simply have your application (or a wrapper script that execs it) write some value in /proc//oom_score_adj. Positive values increase the chance it'll be killed. Docs here: https://www.kernel.org/doc/Documentation/filesystems/proc.txt. I hope some of this would be helpful. – APZ Jan 13 '14 at 07:47