3

I have installed Ubuntu 14.10 on a server. The server main task is running a MongoDB installation along with several NodeJS applications. The NodeJS applications will run continuously and will accept requests from outside.

Every now and then large requests will come in causing some NodeJS application to use a lot of RAM for a short amount of time. I have been trying to monitor this but am not sure what to make of my findings.

So far I have used two commands to get insights in the RAM usage. These are

free -m

and

sudo htop

The first shows this:

                        total       used       free     shared    buffers     cached                                           
Mem:                     3442       3158       283          6        111       1203                                           
-/+ buffers/cache:                  1842       1599                                                                         
Swap:                    0          0          0    

When I look at this I would say that about 280MB of RAM is free. Which does not seem like a lot.

htop tells me the following:

  1  [|||                                         0.8%]     Tasks: 61, 129 thr; 2 running
  2  [|||                                         1.0%]     Load average: 1.16 1.15 0.93
  Mem[|||||||||||||||||||||||||||||||||||||1979/3442MB]     Uptime: 29 days, 00:23:31
  Swp[                                           0/0MB]   

I don't really now how to read this. Can anyone help me out here?

I guess my question in the end boils down to these:

  • How can I get some insight in how much RAM is available?
  • When is the RAM memory too little? Is 300MB considered very little? Dangerously so?
3
  • Just use System Monitor. It comes with Ubuntu. – TheWanderer May 1 '15 at 11:46
  • @Zacharee1 the OP said this is server, so I'm guessing he doesn't have GUI , and therefore no System Monitor, so that might be complicated – Sergiy Kolodyazhnyy May 1 '15 at 14:59
  • Yes Serg, you are correct. This is a server installation. – Mathyn May 1 '15 at 16:08
4

TL;DR: You don't have to worry as long as the -/+ buffers/cache row shows enough free memory. If it shows low free memory and you are continuously being swapped to disk then you need to be concerned.

Explanation:

You are good with your current RAM usage scenario. Lets take the output of free -m to break it down:

All columns of free -m is self explanatory. The important thing to note that you don't need to be alarmed when the memory usage is high without seeing the amount of memory cached and buffered.

From the output, you have used 3158 MB of your 3442 MB RAM, a plain subtraction would say that you have only 283 MB free to be allocated to new programs. This is not right, you need to look at the cached and buffers columns too, cached will show the a mount of disk data cached by RAM for faster access to the commonly used files and buffered shows the amount of data to be written to the disk.

As you know, disk access is much slower that RAM, so to improve performance its a good thing to store some of disks data into RAM. You have 1203 MB of cached and 111 MB of buffered data. This is a good thing that your memory is caching this amount without just keeping this amount of RAM idle. It will improve your performance greatly.

To get the actual amount of RAM that is being used without caching/buffering, look at the -/+ buffers/cache: row. This result is shown subtracting the cached/buffered amount. As you can see you have 1599 MB free, so everything seems Ok at this state. If you see the values in this row is low, then you need to be concerned and take a look at the RAM usage.

Also note that, when a new program is to be started and there is not sufficient memory after caching, the older caches will be cleared automatically to make space for the new program. So, as long as the actual memory usage is not high and your are continuously being swapped to disk, it's a good thing to have substantial amount at cache as it is "using" your memory efficiently.

3
  • good explanation, +1 . I'd add a TL;DR part through – Sergiy Kolodyazhnyy May 1 '15 at 15:13
  • @Serg Yeah.. i will.. – heemayl May 1 '15 at 15:16
  • Thank you for your very clear explanation! This makes me a lot less stressed :) – Mathyn May 1 '15 at 16:07
0

heemayl already has covered good portion of info about the actual available memory. My post here is merely couple oneliner that you can add to your .bashrc as an alias to use as quick overview of actual usage:

free -h | awk '/free/ {getline; x=$2; getline; print "Used "$3 " Out of " x }'

And sample output:

$ free -h | awk '/free/ {getline; x=$2; getline; print "Used "$3 " Out of " x  }'                                                                 
Used 1.2G Out of 5.6G

If you interested in more in-depth investigation of memory, use cat /proc/meminfo, which lists whole lot of info, and this blog will help you understand how free command calculates stuff from that file.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.