Ubuntu Apache Tuning

출처 :

So I recently needed to do a little quick performance tuning at work on one of our ubuntu server installs.  I’ve been using some of the wisdom found here to refresh myself on the basics, and I wrote a quick little one line awk script to give me the total amount of memory being used by apache at any given time, and the average process size for apache at that moment as well.  I figured someone else might get some use out of it and decided to post it: (the following should all be on one line, but hey)


ps -ylC apache2 –sort:rss | awk ‘{x += $8;y += 1} END {print “Apache Memory Usage (MB): “x/1024; pr
int “Average Process Size (MB): “x/(y*1024)}’


So the command ‘PS’ is going to give us process information for any process containing the apache2 text, I’m going to sort it by the physical/resident memory that process is taking up.  I then feed that data into Awk and on Ubuntu, the 8th column in is the memory info.  I then total that up in my x variable and total the number of processes in my y variable and then print those out nicely out to the terminal.  (Incidentally you could use this in a cron job to create a sort of very ghetto/basic apache historical tracking if you wanted to see apache memory usage over time)

So as I understand it, your MaxClients setting in apache should follow this formula:

MaxClients ≈ (RAM – size_all_other_processes)/(size_apache_process)

So with my handy script you now have the size_apache_process variable, you probably know your boxes total ram, (‘free –m’ will tell you if you don’t know) and I’ve been estimating ‘size_all_other_processes’ as about 20% of total ram.  It occurs to me that I could probably write a script to total up the size of all other processes as well, but I’ll have to investigate that a little bit…  Anyhow it’s pretty quick to figure out a good MaxClients setting using this script!

1 Comment

    2014/06/17 at 00:50 · Reply

    I seriously love your blog.. Great colors &
    theme. Did you create this site yourself? Please reply back as I’m planning to create my own blog and would love to find out where you got this from
    or just what the theme is called. Many thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *