vmstat command helps us to determine if a server is running short of CPU resources.
First, let us determine the number of CPUs available
Linux:
$ grep -i processor /proc/cpuinfo | wc -l
FreeBSD:
$ sysctl -a ‘hw.ncpu’
Run vmstat command 10 times with an interval of 5 seconds
$ vmstat 5 10
procs ———–memory———- —swap– —–io—- –system– —–cpu—–
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 186044 123220 1006872 0 0 182 103 509 1194 13 5 78 4 0
2 0 0 185812 123236 1006728 0 0 0 26 350 1046 6 2 83 9 0
2 0 0 185812 123244 1006788 0 0 0 13 410 1111 9 2 87 2 0
1 0 0 185508 123252 1007452 0 0 0 12 358 909 6 2 91 2 0
1 0 0 185656 123260 1006784 0 0 0 27 340 784 5 1 92 2 0
0 0 0 185656 123276 1006784 0 0 0 28 323 660 4 2 93 2 0
1 0 0 185656 123284 1006784 0 0 0 11 289 610 3 1 95 2 0
1 0 0 185656 123284 1006784 0 0 0 0 296 629 3 1 96 0 0
2 0 0 185688 123292 1006784 0 0 0 5 371 905 5 2 84 9 0
1 0 0 185532 123308 1006784 0 0 0 16 403 870 8 2 88 3 0
In the above command, under the heading procs, there is a column named r, which stands for runqueue
As per the man page of vmstat, “r” stands for the number of processes waiting for run time. If the value of the runqueue, r, exceeds the number of CPUs on the server, then the tasks are forced to wait for execution.
So, in this case we need to figure out the process hogging the CPU time and either suspend it or limit it’s access to CPU by changing it’s “nice” value.