i tried pmap pgrep apache2 |grep total on ubuntu 10.4 running Apache and the o/p was like this:

total 47768K

total 48048K

total 48048K

total 48048K

total 48048K

total 48048K

does this means that each child process is taking 48 MB of RAM.Can you help me in finding the exact memory usage of each process.Expecting a reply


This is what I use for an approximation of the average httpd (substitute apache2 if on Debian distro) process size:

ps -ylC httpd --sort:rss | awk '{sum+=$8; ++n} END {print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n/1024"MB"}'

Like symcbean said you should take about 80% of the server's memory and divide it by the average process size to determine your upper limit MaxClients.


  • That little one-liner is absolutely brilliant. Kudos! – Soleil Apr 14 '18 at 7:42

You really don't want to know how complicated it is to work out what the actual memory footprint is.

Try plotting

ps -ef | grep httpd | wc -l

(number of httpd process)

against the first number in

free | grep 'buffers/cache'

(amount of memory used).

For varying load levels.

Remember that cache is important - if your webserver does any I/O then it the less cache you have the slower it will go. As a rough rule of thumb you want to set your maxclients to a value less than where 80% of your memory is used up.


I copy an pasted guys,

<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 2
MaxSpareServers 5
MaxClients 200 #must be customized
ServerLimit 200 #must be customized
MaxRequestsPerChild 100

KeepAlive Off

Some explanations are here:

StartServers – this is how many apache instances should start at the very beginning when apache is started. I set it to 2, and it works fine for me.

MinSpareServers – minimum number of spare servers that should be running waiting for potential requests. MinSpareServers=2 worked fine for me too.

MaxSpareServers – maximum number of spare servers that should be running waiting for potential requests, obviously >= MinSpareServers. In my working example MaxSpareServers=5.

MaxClients & ServerLimit. You can use this shell script to determine an average amount of memory consumed by one Apache process. In addition to that it’ll show total amount of memory consumed by all Apache processes. Just unzip and execute as follows:

    wget http://cloudinservice.com/wp-content/uploads/2011/03/ap.sh.zip

    unzip ap.sh.zip

    sh ap.sh

The output will be something like that:

    Apache Memory Usage (MB): 1372.6
    Average Proccess Size (MB): 54.9041

Try to execute it several times to compare the numbers; good results will be shown when server is under a heavy load. Now when you know average amount of memory consumed by Apache and total amount of memory of your server, it is possible to calculate value to be used for MaxClients setting. For example, if in average one your Apache process consumes 50MB RAM and server RAM is 2GB, and you want to leave 512MB for the rest processes, then:
MaxClients = (2GB – 512MB)/50MB = 30.72 ~ 30.
ServerLimit is, as I understand, the same thing, but while MaxClient setting can be changed on the go without a need to restart Apache, for new ServerLimit value to take effect Apache restart is required. MaxClients should always be <= ServerLimit. To make it easy, I set ServerLimit = MaxClients calculated by above formula.

I thank the girl that posted that on her website. jam

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.