Obtaining a more detailed breakdown of RAM usage?
My server keeps running out of RAM, leading to swap usage and often an a need for a reboot.
In 'top' I see a bunch of httpd processes using up about 1% of memory each, but no further breakdown of what account, script, path etc. is responsible. How could one obtain more thorough details about what specifically is causing the shortage? |
Quote:
http://www.cyberciti.biz/tips/top-li....html#comments |
Quote:
Quote:
Quote:
Quote:
Quote:
Code:
cat /proc/meminfo Probably someone will then explain why there isn't actually any shortage. But if there is a shortage, we will then know enough to tell you more about diagnosing or correcting it. |
Quote:
This is a web server (although all content on the server is my own), and the only info I can find is that apache/httpd and perhaps mysql are to blame. That's not enough info for me to debug with though. Clearly I have a RAM leak in some script, but I haven't been able to locate it at all yet. Ideally what I'd like to know is what specific URL(s) are responsible for the most RAM use. Is that possible? Quote:
Quote:
Quote:
At the moment there isn't a shortage, top says there's about 1.2 gigs free. But here's the meminfo results: Code:
MemTotal: 6097676 kB |
In your meminfo listing your free RAM is actually closer to 4GB.
Your "cached" value represents file cache which will be dropped by the kernel if RAM becomes exhausted. Also, that 1% of memory that httpd is using as reported by top may not be entirely accurate. This is because (if memory serves), shared memory can be double counted. When the server gets close to a point of needing a reboot, try the following and past the output: `ps ax -o pid,comm,%mem,rss` |
Are you running 32bit with PAE or 64bit?
|
Quote:
But you should add more swap space (another swap partition or a swap file or increase the current swap partition size). That will let the system slow down more gracefully as it becomes overloaded, so you have more opportunity to diagnose what went wrong (and so your work is less at risk to badly timed reboots). Quote:
You may be hitting the commit limit, meaning your system would run OK with more swap space or maybe just with different commit parameters. Quote:
You can hit a commit limit without actually using that much memory. Quote:
Code:
MemFree: 1223860 kB Code:
AnonPages: 1857160 kB Code:
CommitLimit: 7153432 kB Quote:
Code:
VmallocChunk: 34359470875 kB |
Quote:
Quote:
Quote:
|
Quote:
In Windows, I have seen a behavior in which nearly all available time is spent soft faulting pages between a process's working set and the page cache. So the kernel CPU time is nearly 100% and no significant work gets done. I have no idea how Windows decides the working set size for each process. This sick behavior occurs when the working set size needs to be large, but isn't. The process could run just fine with available physical ram if its working set size were larger. I have never seen any similar behavior from Linux. But I can't say for sure that it never happens. But if a shortage of memory causes high CPU use, it is hard to imagine an underlying mechanism other than excess soft faults. I'm not sure in Linux how you measure the rate of soft faults. Are you sure the high CPU load was not normal under the workload? Maybe the swapping was normal and doing no harm and the CPU was fully used because the system was given that much work to do. Quote:
Because of the large amount of virtual memory (demand zero, etc.) that isn't any form of real memory nor mapping, the OS must work with an estimate of the total level of ram+swap that it needs. It may reject memory allocation requests even when there is plenty of memory if it over estimates the fraction of demand zero et. that will become real memory use. In Windows that problem is more common and often requires that you have significantly more swap space than you will ever actually use. So far as I know there is no work around other than allocating excess swap space. In Linux, the problem is less common and excess swap space is not the only work around. But excess swap space is still the simplest work around (requires a less detailed understanding of the local characteristics of the problem than tweaking the commit parameters requires). |
Good stuff from johnsfine.
@OP: if the new mem is holding up that's good. You could also look at tweaking the num of processes that Apache uses. See http://httpd.apache.org/docs/2.2/mod/directives.html and checkout the directives mentioning servers/child/threads/requests. |
Quote:
Quote:
Regardless, that is all symptom, not (strictly) the underlying problem. As you said, you need to fix the leak. To track process memory consumption over time, look at pidstat in the sysstat package - needs a reasonably recent kernel/sysstat environment. Collectl also offers similar, but is not widely installed by default. Else try the following based on the link above "ps -aux | sort -nr -k 4 | head -n 15" If you like the result, maybe kick off a background loop to record it Code:
while true ; do ps -aux | sort -nr -k 4 | head -n 15 >> memhogs.txt ; echo -e "\n-----------------\n" >> memhogs.txt ; sleep 300 ; done & |
Thanks a lot for the help guys :) If the issue recurs I'll post more info. I'm also going to be increasing swap space from 4GB to 8GB.
Quote:
Quote:
Quote:
Quote:
|
That doesn't sound right. You can run a very fast web server even with 128MB of memory and no swap. It may not be memory at all. You may have network congestion. Have you tried running netstat to see if you are maxing out on established connections. Ideally you can get up to 65,356 simultaneous established connections but it's really much lower than that. You may be getting 30,000. In that case you can add 1TB of memory and your bottleneck will still be your network established connections. When that occurs then it's time to divide the load using two or more load balancing servers - divide and conquer!
|
All times are GMT -5. The time now is 01:59 AM. |