Capacity planning - memory (Debian)
@cout:
Linux uses copy-on-write, so different instances of the same program can share memory.
I've just been looking into this myself, and it's frustrating me: I want to monitor Apache's and mysql's memory usage so I can do capacity planning. But I haven't found any way to figure out what is really being taken up, based on a report like this:
ps aux | grep apache
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1066 0.0 6.3 142304 3760 ? S Nov06 0:03 /usr/sbin/apache
www-data 16560 0.0 8.9 144104 5308 ? S 06:38 0:00 /usr/sbin/apache
www-data 16561 0.0 9.2 144672 5536 ? S 06:38 0:00 /usr/sbin/apache
www-data 16562 0.0 9.4 144320 5628 ? S 06:38 0:00 /usr/sbin/apache
www-data 16563 0.0 8.7 144108 5188 ? S 06:38 0:00 /usr/sbin/apache
www-data 16564 0.0 8.8 144112 5292 ? S 06:38 0:00 /usr/sbin/apache
www-data 16599 0.0 12.3 145868 7372 ? S 06:38 0:00 /usr/sbin/apache
www-data 16600 0.0 9.8 144372 5872 ? S 06:38 0:00 /usr/sbin/apache
www-data 16601 0.0 9.2 144020 5508 ? S 06:38 0:00 /usr/sbin/apache
www-data 16602 0.0 9.0 144068 5372 ? S 06:38 0:00 /usr/sbin/apache
(At least with mysql on my box, all of the processes report the same memory usage.)
I have no idea how much of all these figures is shared memory.
Should I really care? I'm thinking maybe I should just take an average of the memory stats for each thread, just to have something to look at over time (knowing it's not a real number). Then just monitor total system memory usage and make sure the linode isn't thrashing.
But that's not really a good way to predict when I'll need to get more RAM, or move mysql to another server to free up memory for Apache…
Anyone know a more exact method for doing this kind of planning? I've been all over google and usenet, and haven't found anything helpful. Is there another tool I should be using?
Thanks,
ged
9 Replies
On my gentoo, with only modssl, modauth_pgsql :
> ps aux
[...]
root 1543 0.0 5.4 6500 3268 ? Ss 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1549 0.0 6.3 14932 3780 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1550 0.0 6.4 15012 3836 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1551 0.0 6.4 15012 3836 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1559 0.0 6.3 14932 3780 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1561 0.0 6.4 15012 3836 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1562 0.0 6.4 15012 3836 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1563 0.0 6.4 15012 3836 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1565 0.0 6.3 14932 3780 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1566 0.0 6.3 14932 3780 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
apache 1567 0.0 6.3 14932 3780 ? S 02:36 0:00 /usr/sbin/apache2 -k start -D SSL -D AUTH_PGSQL
[...]
The only LoadModule statements in my main apache2.conf are :
LoadModule access_module modules/mod_access.so
LoadModule auth_module modules/mod_auth.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
One method you could use is to use free, check the 'xxxx' value
in "-/+ buffers/cache: xxxx"
before launching apache2 and after (let it handle some requests).
In any case, you can then translate the PID to a name (if it's still running) by doing something like "ps aux | grep
There's probably some better means of doing it than this but that's all I know.
The ipcs command is really interesting (and an education in itself). I wish the numbers lined up better with top or ps, but at least I have a better idea of what's going on with memory.
Thanks!
The amount of memory used by an app is difficult to determine because of the memory saving mechanisms buit in Unix :
copy on write for forked processes,
shared libraries.
I believe the most practical way is to substract the free output values giving free memory (couting buffers and cache in free memory) before and after an application is launched.
@gyver:
The amount of memory used by an app is difficult to determine because of the memory saving mechanisms buit in Unix
That's certainly been proven to me over the last couple of days.:?
> I believe the most practical way is to substract the free output values giving free memory (couting buffers and cache in free memory) before and after an application is launched.
That seems to be the only way. My concern though is that on my box where Apache lives with mysql, I can't measure how much both of them grow with use over hours or days.
Since you can't tell how much either is using, it will be hard to tell, in a memory crunch, which is the culprit.
What I really need to do, I think, is keep an eye on CPU utilization and swap stats - at least I'll know if I need to get more memory or move a service to a different box.
That's the price I guess for keeping all of your services on one box (not really a good idea).
Thanks again!
ged
I.e. am I any better or worse off in trying to calculate memory or CPU usage?
There is, of course, a man page for vmstat that will give you much more info than I can.
I hope this was at least somewhat useful.
--James
PS -> If you don't yet have a favorite graphing tool, Cacti is very powerful and not too hard to set up. I steer away from MRTG now because the new systems (most of which are based on the RRD tools) are much easier to configure. The linux administration world, IMHO, owes a great debt of gratitude to the author of MRTG/RRDTools.
http://procps.sourceforge.net/
I think that's already a part of the default Debian Sarge (and probably Woody) releases?
For instance, you can use pmap like this:
# pmap -x `ps -C apache -o ppid|tail -1`
Keep in mind that some are shared libs which is loaded once, made available to multiple processes automatically through some virtual memory address mapping… and some of memory usage could be deleted stuff that's still charged against the total memory size of the process.
But pmap -x generally breaks it down such that you can see exactly what is using how much.
-Dan