Investigate Memory Load Issues on a Linux VPS

Investigate Memory Load Issues on a Linux VPS



At Crucial Paradigm, we host more than 1500 Linux virtual servers. I have noticed that customer faces a lot of issues when their server is running slow or having high load or low memory.

In this situation, intermediate or low-knowledge users do not know how to check and resolve this issue. Crucial provides Linux VPS Server Management for $50 per month. Under this server management, you can email technical support team and have them to look into the server side issue and resolve it for you. However some customers do not take this service on their Linux VPS and try to solve issue themselves.

I am writing this article to give you an idea that how novice or other users can investigate high load or low memory issues on their Linux server and contact our technical support to resolve it.

Note: You should be familiar with SSH commands and have root access to your Linux VPS server.

How to check load of the server

Login to your server via SSH.

Run this command in shell

# w

It will give result like this

14:58:20 up 4 days,  1:09,  6 users,  load average: 1.03, 0.94, 0.79
USER     TTY      FROM              [email protected]   IDLE   JCPU   PCPU WHAT
root     pts/0    203.110.144.225  Wed15    1:49m  0.08s  0.08s -bash
root     pts/1    182.160.135.28   12:57    1:09m  7.26s  0.02s -bash
root     pts/2    182.160.135.28   13:01    2:48   0.07s  0.07s -bash
root     pts/3    220-249-78-137.s 13:40   58:41   2.37s  2.36s top
root     pts/4    111.118.161.243  14:12   46:10   0.00s  0.00s -bash
root     pts/5    111.118.161.243  14:58    0.00s  0.00s  0.00s w

The result will tell you average load of your server and who is logged into the server from which IP address. If average load of your server is more than 2 then it is not normal.

High load can happen due to following reasons

A. There is high CPU usage, Run this command to check CPU usage and processes which are using high CPU:

# top -cd3

Then press shift +P

top – 02:49:52 up 60 days, 8:33, 3 users, load average: 0.09, 0.22, 0.30
Tasks: 164 total, 1 running, 161 sleeping, 0 stopped, 2 zombie
Cpu(s): 9.7% us, 3.3% sy, 0.0% ni, 87.0% id, 0.0% wa, 0.0% hi, 0.0% si
Mem: 2074860k total, 1495612k used, 579248k free, 423104k buffers
Swap: 4096532k total, 394288k used, 3702244k free, 470908k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
25999 sesanate 17 0 0 0 0 Z 5.3 0.0 0:00.16 [php] 26003 sesanate 18 0 0 0 0 Z 5.3 0.0 0:00.16 [php] 19526 mysql 15 0 253m 62m 2456 S 3.3 3.1 67:26.60 /usr/sbin/mysqld –basedir=/ –datadir=
23438 nobody 15 0 35400 6620 2188 S 0.7 0.3 0:00.23 /usr/local/apache/bin/httpd -k start -D
22808 nobody 15 0 35364 6532 2176 S 0.3 0.3 0:00.29 /usr/local/apache/bin/httpd -k start -D
1 root 16 0 3172 92 64 S 0.0 0.0 1:02.14 init [3] 2 root RT 0 0 0 0 S 0.0 0.0 0:08.25 [migration/0] 3 root 34 19 0 0 0 S 0.0 0.0 0:08.64 [ksoftirqd/0] 4 root RT 0 0 0 0 S 0.0 0.0 0:05.26 [migration/1] 5 root 34 19 0 0 0 S 0.0 0.0 0:10.92 [ksoftirqd/1] 6 root 5 -10 0 0 0 S 0.0 0.0 0:16.10 [events/0] 7 root 5 -10 0 0 0 S 0.0 0.0 0:08.71 [events/1] 8 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 [khelper] 9 root 5 -10 0 0 0 S 0.0 0.0 0:00.03 [kthread] 10 root 15 -10 0 0 0 S 0.0 0.0 0:00.00 [kacpid]


B.
Swap space in use:

Swap usage can be found by running this command

# free -m

Eg:
[email protected] [~]# free -m

total     used     free     shared     buffers cached
Mem:     2026     1462     564     0         413     461
-/+ buffers/cache: 586 1439
Swap: 4000         385     3615


C.
I/O wait:

I/O wait is the time spent by the CPU waiting for a I/O operations to complete. Run the following command and look for “wa”

# top

Eg:
top – 02:49:52 up 60 days, 8:33, 3 users, load average: 0.09, 0.22, 0.30
Tasks: 164 total, 1 running, 161 sleeping, 0 stopped, 2 zombie
Cpu(s): 9.7% us, 3.3% sy, 0.0% ni, 87.0% id, 0.4% wa, 0.0% hi, 0.0% si
Mem: 2074860k total, 1495612k used, 579248k free, 423104k buffers
Swap: 4096532k total, 394288k used, 3702244k free, 470908k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
25999 sesanate 17 0 0 0 0 Z 5.3 0.0 0:00.16 [php] 26003 sesanate 18 0 0 0 0 Z 5.3 0.0 0:00.16 [php] 19526 mysql 15 0 253m 62m 2456 S 3.3 3.1 67:26.60 /usr/sbin/mysqld –basedir=/ –datadir=
23438 nobody 15 0 35400 6620 2188 S 0.7 0.3 0:00.23 /usr/local/apache/bin/httpd -k start -D
22808 nobody 15 0 35364 6532 2176 S 0.3 0.3 0:00.29 /usr/local/apache/bin/httpd -k start -D
1 root 16 0 3172 92 64 S 0.0 0.0 1:02.14 init [3] 2 root RT 0 0 0 0 S 0.0 0.0 0:08.25 [migration/0] 3 root 34 19 0 0 0 S 0.0 0.0 0:08.64 [ksoftirqd/0]


D.
Memory:

Sometime application running in the server might consume a lot of memory in the server. Check the available memory by using the command

#free -m

total       used       free     shared    buffers     cached
Mem:          4096       2247       1848          0        134       1329
-/+ buffers/cache:        783       3312
Swap:         2047          0       2047

Process that is consuming high memory can be found from the process id.

For example: Consider an application is consuming high memory usage.

Run the following command. This will show you the memory usage in decreasing order.

# nice top -c

Then press SHIFT +M

Find the path of the process as given below. The process ID is 1056

~~~~
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
28849 www-data  15   0  184m  27m 9356 S   22  8.7   2:56.15 /usr/bin/php-cgi
~~~~

then run this commmand to get the path of CWD(current working directory).

# ls -l /proc/28849

total 0
dr-xr-xr-x 2 www-data www-data 0 2012-08-02 16:37 attr
-r——– 1 www-data www-data 0 2012-08-02 16:37 auxv
-r–r–r– 1 www-data www-data 0 2012-08-02 16:07 cmdline
-rw-r–r– 1 www-data www-data 0 2012-08-02 16:37 coredump_filter
-r–r–r– 1 www-data www-data 0 2012-08-02 16:37 cpuset
lrwxrwxrwx 1 www-data www-data 0 2012-08-02 16:37 cwd -> /var/www/clients/client1/web1/web
-r——– 1 www-data www-data 0 2012-08-02 16:37 environ
lrwxrwxrwx 1 www-data www-data 0 2012-08-02 16:07 exe -> /usr/bin/php5-cgi
dr-x—— 2 www-data www-data 0 2012-08-02 16:10 fd
-r–r–r– 1 www-data www-data 0 2012-08-02 16:37 io
-r——– 1 www-data www-data 0 2012-08-02 16:37 limits
-rw-r–r– 1 www-data www-data 0 2012-08-02 16:37 loginuid
-r–r–r– 1 www-data www-data 0 2012-08-02 16:37 maps
-rw——- 1 www-data www-data 0 2012-08-02 16:37 mem
-r–r–r– 1 www-data www-data 0 2012-08-02 16:37 mounts
-r——– 1 www-data www-data 0 2012-08-02 16:37 mountstats
-rw-r–r– 1 www-data www-data 0 2012-08-02 16:37 oom_adj
-r–r–r– 1 www-data www-data 0 2012-08-02 16:37 oom_score
lrwxrwxrwx 1 www-data www-data 0 2012-08-02 16:37 root -> /
-r–r–r– 1 www-data www-data 0 2012-08-02 16:37 schedstat
-r–r–r– 1 www-data www-data 0 2012-08-02 16:37 smaps
-r–r–r– 1 www-data www-data 0 2012-08-02 16:07 stat
-r–r–r– 1 www-data www-data 0 2012-08-02 16:07 statm
-r–r–r– 1 www-data www-data 0 2012-08-02 16:10 status
dr-xr-xr-x 3 www-data www-data 0 2012-08-02 16:37 task
-r–r–r– 1 www-data www-data 0 2012-08-02 16:37 wchan

The path is cwd -> /var/www/clients/client1/web1/web where this script is running. You can get it checked by a programmer.

Please check these URLs for more information

http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html

http://raj2796.wordpress.com/2009/11/09/reducing-cached-memory-usage-linux-high-memory-usage-diagnosing-and-troubleshooting-on-vmware-and-out-of-memory-oom-killer-problem-and-solution/

http://serverfault.com/questions/288319/linux-not-freeing-large-disk-cache-when-memory-demand-goes-up

Good Luck!


 


Categories