0

My website is very slow at some times of the day, and I'm on the quest of finding out why. I'm currently looking into Apache memory usage and I have 2 tools that are supposed to tell me how much RAM it is currently using:

Apache2Buddy:

curl -sL https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl | perl 

Returns:

apache2 is currently using 8849.18 MB of memory. 

Then I have this command which uses ps:

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

Returns:

Tot=9047860(258) Avg=9047860/258=34.2473MB 

So according to this one liner, Apache2 is using about 9GB of RAM which matches Apache2Buddy result.

However, when I run htop this is what I get:

enter image description here

Total memory usage seems to be only 2.7GB. Why this huge gap in results?

1 Answer 1

1

The resident size includes shared pages: this includes shared libraries, and in this instance, the apache2 binary itself. The tools you’re using count all this shared memory once per process, but they are only present once in physical memory, so they use far less than you’d expect from adding the resident sizes.

To get a better idea of your processes’ real memory use, you’d have to look at /proc/<pid>/smaps; for each section described there, compare the Rss value and the Shared_... values. The kernel attempts to help you perform the calculation you’re interested in by calculating the per-process share of RSS, given as Pss.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.