System too slow

10,516

Troubleshooting performance issues on Linux is not simple and I won't cover all possibilities. However most issues falls into 3 categories usually : high CPU usage, high memory usage or I/O usage . NOTE: they are all inter-connected.

First type : top -b -n 1 | head -15

This will give you the following output :

top - 15:32:09 up 19 days,  2:32,  2 users,  load average: 0.61, 0.46, 0.42
Tasks: 208 total,   1 running, 207 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.9%us,  3.6%sy,  0.0%ni, 95.2%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  16430432k total, 15188864k used,  1241568k free,   304624k buffers
Swap:  2097148k total,      112k used,  2097036k free,  7342636k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
16106 user   20   0 4070m 2.1g 2.1g S   30 13.5   4678:57 VirtualBox
26070 user  20   0 6113m 749m 697m S    6  4.7 628:55.93 VirtualBox
14863 user   9 -11  272m 3192 1804 S    2  0.0   5:57.19 pulseaudio
    1 root      20   0 24724 2548 1276 S    0  0.0   0:05.32 init
    2 root      20   0     0    0    0 S    0  0.0   0:00.15 kthreadd
    3 root      20   0     0    0    0 S    0  0.0   0:33.45 ksoftirqd/0
    6 root      RT   0     0    0    0 S    0  0.0   0:03.74 migration/0
    7 root      RT   0     0    0    0 S    0  0.0   0:02.51 watchdog/0

First have a look at the load average. Check here to understand what it means( it is very important to understand this concept).

IMPORTANT : Here below I assume that you have a single core ( 1 CPU, no dual-core,...)

If the load avg is less than 1 after 5mins then CPU load is OK. At this point I'm not sure what it could be. Continue to troubleshoot like if it was NOT OK.

If the load avg is more than 1 after 5mins then CPU load is high. To understand why the CPU load is high, check the following entries in the output given by top :

In the output above, you can see a list of processes. Look at column %CPU and check if you see processes using 100%. The fact that they use 100% of CPU may or may not be a problem but as a test, it would be good to stop them.

To stop a process in top, press "k" and enter the value found under PID for the given process.

IMPORTANT: Write down the name of the process. Before killing any, try to understand what they do ( search in google). You can only stop the process that you own (check under USER column) as normal user (you need to be root otherwise but be careful of what you kill, in doubt don't). Also have a look at %us and %sy values, us stands for user and sy for system. Basically they respectively represent the CPU usage in user space and kernel space.

If the system speed up then it is probably the process that you killed which was causing the problem. If not, continue

Read value in %wa. Is it high ? ( over 50%), if it is high, it means that the Inputs/Outputs (I/O) to the disk are high and the CPU is waiting. Use the command iostat to determine which drive is slow.

You can also check mem usage.

Type free -m in command line. You should see something like this:

                 total       used       free     shared    buffers     cached
Mem:         16045      14835       1209          0        298       7172
-/+ buffers/cache:       7365       8679
Swap:         2047          0       2047

Check the value in buffers/cache under used. If it is using too much mem, the value should be close from total.

Check also the used value in Swap ( if you have a swap partition). If it is high, meaning close from the maximum value seen under total ( for Swap), then it means that your system is swapping a lot and which means that it is paging to disk ( which is much slower than RAM).

Again, this might not solve your problem, but it is a good start.

Share:
10,516

Related videos on Youtube

Bingo
Author by

Bingo

Updated on September 18, 2022

Comments

  • Bingo
    Bingo over 1 year

    My linux system is responding very slowly.I should wait to get the result of my command.

    How can i investigate to know the problem of his behavior?

    • Rahul Dhobi
      Rahul Dhobi about 10 years
      Run top command and find which process is taking high cpu
    • goldilocks
      goldilocks about 10 years
      Run a CPU monitor on your desktop to see if it is a process hogging the CPU.
    • Ouki
      Ouki about 10 years
      Use the top command. If your system is really not responsive you can go for a shorter top -n 1 |head -15 for a quick look at the system load and which processes are using a lot of CPU.
    • Alen Milakovic
      Alen Milakovic about 10 years
      Try also iotop for I/O and there are similar utilities out there.
  • UnX
    UnX about 10 years
    To determine the number of cores, you can type : grep "^processor" /proc/cpuinfo | wc -l
  • m13r
    m13r about 7 years
    What about IO and using iotop (disk IO) and e.g. nethog (net IO) ?