I have server which runs liquidsoap+icecast bundle and simple website (httpd+mysqld). Nothing special. Visitors around 2000+ per day, with around 50 being online simultaneously on average.
Server has 8GB RAM. As the time goes by, amount of free memory constantly decreases, although nothing new is started on server and there are no new users. At some point it starts to swap, load on server goes up and it becomes unresponsive. Usually what I do is just restart the server...
What can be done to detect what exactly leaks memory? I use top to monitor usage of resources, but as far as I see it shows nothing helpful:
Is there any way to find out what uses that much memory? or what starts to swap to disk heavily? Any way to free up memory without rebooting the server?
Running
top
in batch mode to report memory sizes periodically can be used to see who is using the memory when things go south. Runingsar
in batch mode should give some good diagnostics on memory use, and related I/O. Runningmunin
to monitor the system should give you a graph with good detail on what memory is being used for. This may help a lot.You can use limits.conf to limit the maximum core size of programs. Properly set, this should kill any programs which are leaking memory. This works with the pam_limits module. Limits can also be set with the
ulimits
command.You are running a few programs which could use large amounts of memory. Some things you could look at include.
apache2
can leak memory. You should see the memory size increase when this happens. You can tune apache2 to recycle children after a certain number of uses by settingMaxRequestsPerChild
to 100 or so. If this resolves the problem, then you need to resolve the leak. I would watch this first.tmpfs
file system mounted, then you may leak memory if files are not deleted when used. Large long lived files can also be a problem.Normal memory usage: Free memory is not something you want a lot of. If your system has been up for a long time and has a lot of free memory something is wrong. Every time you read or write a file, the blocks will go into the buffer cache. This will reduce your free memory, and is a good thing. The system will keep enough free space to start a few programs without looking elsewhere for memory. As many programs run quickly, their memory will be returned to the free pool when they stop running.
When you read a file that is in buffer cache, no disk access is required and the read is resolved from the buffer cache. Writes use a similar mechanism. If your system needs memory, the buffer cache is one of the first places that is used. Most buffers can be released immediately.
If you have a memory leak, you will see free memory and buffers both begin to shrink. This is still not a severe problem, as the leaked memory should eventually be moved to swap space. Your system will still run fine until you fill the swap space, and draw down the remaining free space to the point programs can't be started. It is typical that a small amount of swap space may be used.
You can use this command to see the top 10 applications regarding RAM usage:
Sometimes this command helps you if many sub processes have been generated:
This way you can see which processes belong together.
Nothing is really using that memory in terms of applications.
You need to deduct the 'cached' value which represents the page cache to get a better idea as to what your actual memory usage is in terms of program usage.
Basically this is good memory management and this is ideally what you want.
See the link here for more infomation: http://www.linuxatemyram.com/
I am not a pro at this really, but liquid soap+icecast is multimedia related. When the system is free, it caches and/or occupies memory for future use. And if the traffic increases at a certain time of the day/ over a period of time, then it will start swapping. At this point, if the requests ( users viewing content) increases, then the resources needed will be more than 8GB of ram.