Server requires Memory upgrade?

Discuss Networking
Post Reply
agent007
administrator
administrator
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Server requires Memory upgrade?

Post by agent007 » Fri Dec 17, 2004 11:39 am

My website is hosted by a service provider [virtual hosting]. I SSH'd & found the following info on available memory. Out of 1gig, only 8MB is free. Is this normal for a system hosting a high demand website? Have noticed this for the last couple of days and sometimes the site runs pretty slow. Could this be the reason? Do they need to double the memory?

TIA

sh-2.05a$ cat meminfo
total: used: free: shared: buffers: cached:
Mem: 1056018432 1047146496 8871936 0 199118848 704438272
Swap: 2146754560 118714368 2028040192
MemTotal: 1031268 kB
MemFree: 8664 kB
MemShared: 0 kB
Buffers: 194452 kB
Cached: 604204 kB
SwapCached: 83724 kB
Active: 767400 kB
ActiveAnon: 138488 kB
ActiveCache: 628912 kB
Inact_dirty: 124 kB
Inact_laundry: 150924 kB
Inact_clean: 22116 kB
Inact_target: 188112 kB
HighTotal: 131072 kB
HighFree: 1168 kB
LowTotal: 900196 kB
LowFree: 7496 kB
SwapTotal: 2096440 kB
SwapFree: 1980508 kB
sh-2.05a$ free -m
total used free shared buffers cached
Mem: 1007 998 8 0 189 590
-/+ buffers/cache: 218 788
Swap: 2047 113 1934

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Fri Dec 17, 2004 12:11 pm

Having free memory does not make a system run faster. A system will run the fastest if all real memory is in use. Let me explain.. Say you have 1GB of RAM and 2GB of swap. Say you have a set of services (httpd/ftpd/sshd/etc) that run on your system that in total initially allocate 200MB of RAM. When you first boot your system you would probably see the "MemFree:" at around 800MB. Of course when these services open/read/write/close files they allocate more memory to work with the data. After a typical program is finished working with this newly allocated area it unallocates it so some other program (or the system) can use that area for something else. In Linux this will not get put back into the "MemFree" area but it will be cached so that if that program (or another program) wants to access that same file/data then it doesn't have to go back to the slow disk drive to get it, it can pull it straight out of fast RAM. That's why on a good running Linux system you will usually see very little in the "MemFree:" section of /proc/meminfo, you will also see very little swap used, and a good chunk in the "Cached" (and related) columns.

What kills Linux and UNIX systems is when programs have to allocate more RAM than you actually have and have to page memory in and out to swap in order to do their work. It's that paging (swapping) that will bring your system to a crawl because you are using slow disk in place of fast real memory. Now, one time swaps also usually aren't a big deal, it's when you get into "thrashing" that it becomes painful. This is where you will see continual paging going on. You need to use tools like "iostat" and "vmstat" (see si and so columns in vmstat). For instance:

# vmstat 5

You want to see "0" in the si and so columns. The bigger the numbers get the more swapping is going on. Of course memory is not the only bottleneck that can cause a system to be slow. Disk I/O, disk bandwidth, properly partitioned for speed. CPU speed and number of CPUs, poorly tuned applications, network interfaces, internal/external network issues, etc. This can all be figured out using the available system tools like top, vmstat, iostat, free, sar, netstat, snmp graphing tools, etc. I personally like to graph all of these variables so I can spot trends which makes it easier to pinpoint a problem when it occurs. Here is an example of a custom graph that I create:

http://voidmain.is-a-geek.net/i/memgraph.png

In the above graph I have it set up so everything less than 0 is swap and everything greater than 0 is real memory. The black lines are the total (total swap space and total real memory). The white area just below the top black line represents what programs have allocated the white area just above the bottom black line represents swap in use. The very light green just above 0 represents "MemFree:" from /proc/meminfo. This particular server was rebooted near the beginning of the graph (left side) and you can see right after it came up there was the most light green MemFree. As the system was used you can see the MemFree slowly is replaced by Cached but the amount of memory that programs needed stays constant throughout the graph. Toward the right side you can see some swap is being used but it's not a state where the system in constantly swapping in and out (you can't really see that on a memory graph like this and have to use a tool like vmstat to see).

To be honest I can't really explain why any swap at all was allocated when there is plenty of cached memory available that could have been given up rather than swapping. The only thing I can think of is that the system detected areas of allocated memory that never see any action and swapped them to disk so more memory would be available for cache, something that does get used. That is just speculation on my part though.

agent007
administrator
administrator
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Post by agent007 » Fri Dec 17, 2004 12:52 pm

Excellent info Void! I ran vmstat and looks like so has some high numbers. Btw, can the graph be installed by a normal user? Btw, alterpoint is a commercial product?

Code: Select all

sh-2.05a$ vmstat 5 -n1
   procs                      memory    swap          io     system         cpu
 r  b  w  swpd  free   buff  cache  si  so  bi  bo  in cs  us sy id
 0  0  0 122664  13980 243644 531132   5  19    27    72   52    70   8   2  90
 1  0  0 122664   8728 243404 527896   0   6    10   140  294   200  14   5  82

 0  0  0 122820   9908 242536 526824   0  38     7   181  270   145   8   2  90
 0  0  0 122820   9852 241968 527468   0   3     0    46  269   154   5   1  95
 0  0  0 122820   9760 241988 527564   0   0     3   138  331   193   6   2  92
 1  0  0 122820   9468 242000 527420   2   0    12    77  345   191   7   3  90
 0  0  0 122952   8868 241752 527068   0  54     6   156  343   218   5   2  93
 0  0  0 123544   9092 241500 526096   0 172     4   238  214    79   1   2  97
 1  0  0 123540   8432 241516 526536   0  79    75   142  403   201   6   2  92
 0  0  0 123524   8932 241532 525948   0  26     6   157  364   213   3   2  95
 0  0  0 123720  13392 241528 526056   0  39     3   133  314   161   7   2  91
 1  0  0 123720  13096 241540 526136   0   0     2    80  388   128   1   1  97
 0  0  0 123720  13076 241556 526204   0   0     4    67  262   128   2   1  97
 0  0  0 124112   8644 241308 523712   2 106     7   189  321   173  12   3  86
 2  1  1 124308   8756 240520 523732   0 119     1   242  350   224   5   2  93
 0  0  0 124320   9392 240048 524396   0  30    18   156  228   110   5   2  93

sh-2.05a$

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Fri Dec 17, 2004 2:37 pm

alterpoint is the name of the server that I am graphing. rrdtool is what generated the graph (you probably have it installed). A great interface for creating these graphs that I use is called "Cacti" which is also Free (GPL) software:

http://www.cacti.net/

I even have an example (very poor example) of Cacti up and running on this server:

http://voidmain.is-a-geek.net/cacti/gra ... first=true

Most of the graphing I do is via SNMP (you have to have an SNMP server running (snmpd)). You don't have to use SNMP as your source of data though, you can also write your own scripts to gather the data for the graphs for anything you want to graph. I do a lot of graphing at work using custom scripts.

Post Reply