Apache using all 16 GB Memory, how to limit its processes and memory usage?
I had a similar problem with an instance in EC2 and here's what I did and would suggest:
If you are using prefork, make sure that the module is loaded by typing these two commands
apache2 -l
andsudo apache2 -M
If you can see the prefork module loaded in the results of either of these two commands then up to the next step. Otherwise, make sure to load it first or else you would be changing the configurations for nothing.Run this command to find the average memory each apache2 process is using
ps aux | grep 'apache2' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'
Call that valuex
Restart your apache server by using
sudo service apache2 restart
and take a note of how much free memory you have. What I did was subtract an extra200MB-500MB
cushion from that free memory to be used later. Call that valuey
Divide the value of free memory
y
over the amount of memory used per processx
and that would be the value ofMaxRequestWorkers = y/x
As for the value of
MaxConnectionsPerChild
then you can tweak it till you get the right configuration. It you make it too big, then the process will keep using more and more memory before being killed. If you make it too small, then the processes will die too quickly and that will present an overhead on your system. I usually keep it somewhere between4000
and10000
.Some of these steps have been taken from the accepted answer in the following link: StackExchange: httpd memory usage where one solution also suggested disabling some of the modules if you don't need them.
I would suggest you do steps 1-5 first and see if that solves your problem!
Good luck!