I have an rails 3 application with 100-200 daily unique visitors. The total memory consumed on the server(Ubuntu) is around 1.5-2 GB. I want to know how much memory is used by each process. What are the best tools to track memory used by different processes?
2 Answers
You could just fire up top and press M to sort processes by memory usage.
You could run ps vax | sort -k8n to show processes sorted by the resident stack usage (ps v switches to a memory-centric view).
You could enable snmp and configure mrtg to periodically poll the system, generating a graph of how much memory is used by the processes you care about.
You could resign yourself to the knowledge that Ruby, for all its benefits, is terrible at managing memory in long-running processes. :)
You could combine a more complicated ps command line (look at the man page, and read about the -o option) and rrdtool with a shell script to generate historical statistics on the processes you care about.
Etc.
- 15,219
- 496
Memory management is very difficult, but you can use top, htop or, as dannysauer suggests, something like ps vax | sort -k8n. If you want to get an overview/summary, then free -m is nice.
But it is common for processes to consume less memory than they use. For instance, if you have ten processes using 10MB each, that does not mean those processes will consume 100MB. The reason for this is that Linux will recognize identical memory portions between processes so you don't need to have many identical copies. In other words, your system can always use more memory than you have. So you really need to separate between memory consumption and memory usage.
It's not always easy.
- 29,687