• 5
name Punditsdkoslkdosdkoskdo

Apache “httpd” process, using all my servers memory.

My small ec2 instance with 1.7 GB memory, running the Amazon AMI based off of CentOS, has an issue with Apache utilizing way too much memory than it should. If you take a look at the screenshot, the memory usage will be at 90-100% until I reboot the httpd service, where it will start over, increasing its way back up to 90+ %.

I would really appreciate some assistance on how to locate the issue. Is this perhaps "normal" apache behavior, to utilize all available memory? Or is there a possible leak I have to hunt down. At the moment I'm a bit perplexed as to what could be going on.

We are using the Apache MPM prefork, and no sql or anything similar - just apache. The website is here.

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 commands httpd -l and sudo httpd -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.

  2. Run this command to find the average memory each httpd process is using ps aux | grep 'httpd' | 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 httpd 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. Make sure to check the access logs. May be someone is trying to attack your website!

  7. I would suggest you do steps 1-5 first and see if that solves your problem!

    Good luck!


  • 2
Reply Report

linux using all your memory is normal, memory which isn't in use otherwise is re-purposed as disk cache. see: linux ate my ram

You can verify this by looking at the output of free -m and expect to see something like this:

             total       used       free     shared    buffers     cached
Mem:          7889       6887        101          0        106       2307
-/+ buffers/cache:       5373       3416
Swap:         1903         17       1886

the +/- buffers/cache line is the one you want. It adds cached ram to free to give you a better picture of how much memory is really available. In this case, You want to pay attention to the 3416 number, not 101.

  • 2
Reply Report

As HTTP500 said, you probably shouldn't worry about it unless the machine is actually choking. Take a look at Help! Linux Ate My RAM!. It's not quite an analogous situation, as you have processes rather than buffers using up the RAM, but it's not too far off: your machine's physical RAM is a resource to be used, either with kernel buffers or spare Apache worker processes to promptly handle incoming requests. If you're not using RAM, you've overpaid for the size of your box.

Anyway, if you want to play with MPM settings, the Apache documentation is

You can perhaps reduce the MinSpareServers, StartServers, etc., as you've stated that the site is low traffic. You will then have more free RAM to be consumed by kernel buffers for their nefarious purposes.

  • 4
Reply Report