-2

I'm reading this article about Apache mpm configuration tuning. And the author shows how to get the amount of Virtual Memory apache is using like this:

ps -A | grep apache

But this command shows me multiple apache processes:

11188 ?        00:01:36 apache2
17821 ?        00:00:02 apache2
23682 ?        00:00:00 apache2
23720 ?        00:00:00 apache2
23790 ?        00:00:01 apache2
23800 ?        00:00:00 apache2
23803 ?        00:00:00 apache2
23805 ?        00:00:01 apache2
23881 ?        00:00:00 apache2
23884 ?        00:00:00 apache2
23900 ?        00:00:00 apache2

Do I need to know how much memory single process uses or all of them to put in this formula:

Generally number of MaxClients=(Total RAM memory – RAM memory used for other process except Apache process) / (Memory used by Single Apache process)

It looks like I need to know the memory usage for a single process, but for which one out of the list?

2

Use the top command, and look at the RES colum.

Optionally, you can also use this command to get just that column for all Apache processes:

top -n 1 | grep apache2 | awk '{print $6}'

To get the average memory for all Apache processes, you can do the maths.

This Bash one-liner will get your average memory usage:

PROC_COUNT=0;MEM_TOTAL=0;for MEM_NUM in $(top -n 1 | grep apache2 | awk '{print $6}' | sed 's/m//'); do let PROC_COUNT++;echo $MEM_NUM;let MEM_TOTAL=$MEM_TOTAL+$MEM_NUM; done; let MEMAVG=$MEM_TOTAL/$PROC_COUNT; echo "----"; echo $MEMAVG;
  • What will it give me then? – Max Koretskyi aka Wizard Jul 17 '15 at 10:44
  • Read the answer and you will find out. – Craig Watson Jul 17 '15 at 10:45
  • thanks, but top -n 1 | grep apache2 | awk '{print $6}' shows no output – Max Koretskyi aka Wizard Jul 17 '15 at 10:53
  • Run top and verify you have Apache running. – Craig Watson Jul 17 '15 at 10:55
  • this top -b -n 1 | grep apache shows a list of apache processes, but this top -n 1 | grep apache2 | awk '{print $6}' shows nothing – Max Koretskyi aka Wizard Jul 17 '15 at 11:19

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.