Apache using all 16 GB Memory, how to limit its processes and memory usage? Apache using all 16 GB Memory, how to limit its processes and memory usage? apache apache

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:

  1. If you are using prefork, make sure that the module is loaded by typing these two commandsapache2 -l and sudo apache2 -MIf 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.

  2. 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 value x

  3. 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 extra 200MB-500MB cushion from that free memory to be used later. Call that value y

  4. Divide the value of free memory y over the amount of memory used per process x and that would be the value of MaxRequestWorkers = y/x

  5. 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 between 4000 and 10000.

  6. 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!