This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9822|Reply: 1

Linux vmstat command detailed explanation in practice

[Copy link]
Posted on 10/19/2014 7:36:48 PM | | |

The vmstat command is the most common Linux/Unix monitoring tool that displays the state values of a server at a given time interval, including the server'sCPU usage, memory usage, virtual memory swap, IO read and write. This command is my favorite command to check Linux/Unix, one is that Linux/Unix is supported, and the other is that compared to the top, I can see the CPU, memory, and IO usage of the entire machine, instead of just seeing the CPU usage and memory usage of each process (different usage scenarios).

Generally, the use of the vmstat tool is done through two numerical parameters, the first parameter is the number of time intervals sampled, the unit is seconds, and the second parameter is the number of samples, such as:


root@ubuntu:~# vmstat 2 1
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
1  0      0 3498472 315836 3819540    0    0     0     1    2    0  0  0 100  0

2 means that the server state is collected once every two seconds, and 1 means that the server state is collected only once.

In fact, during the application process, we will monitor for a period of time, and if we don't want to monitor it, we can just end the vmstat directly, for example:


root@ubuntu:~# vmstat 2  
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
1  0      0 3499840 315836 3819660    0    0     0     1    2    0  0  0 100  0
0  0      0 3499584 315836 3819660    0    0     0     0   88  158  0  0 100  0
0  0      0 3499708 315836 3819660    0    0     0     2   86  162  0  0 100  0
0  0      0 3499708 315836 3819660    0    0     0    10   81  151  0  0 100  0
1  0      0 3499732 315836 3819660    0    0     0     2   83  154  0  0 100  0

This means that vmstat collects data every 2 seconds and continues until I end the program, and I end the program after collecting data 5 times here.

Okay, the command is introduced, now let's start explaining the meaning of each parameter.

rIt means running the queue (that is, how many processes are really allocated to the CPU), the server I tested is currently relatively idle, there are no programs running, when this value exceeds the number of CPUs, there will be a CPU bottleneck. This is also related to the load of the top, generally the load is higher if it exceeds 3, it is higher if it exceeds 5, and if it exceeds 10, it is not normal, and the state of the server is very dangerous. The load of the top is similar to that of a running queue per second. If the running queue is too large, it means that your CPU is busy, which usually causes high CPU usage.

bIt means the blocked process, this is not much to say, the process is blocked, everyone understands.

swpdIf the size of the virtual memory used is greater than 0, it means that your machine has insufficient physical memory, and if it is not the cause of the program memory leakage, then it is time to upgrade the memory or migrate the memory-consuming tasks to another machine.

free   The size of the free physical memory, my machine memory is 8G in total, and the remaining 3415M.

buff   Linux/Unix system is used to store, what content in the directory, permissions, etc. cache, I probably occupy more than 300M on this machine

cachecache is directly used to remember the files we open, buffer the files, I take up more than 300M on my own machine (here is the clever thing of Linux/Unix, take part of the free physical memory to cache files and directories, in order to improve the performance of program execution, when the program uses memory, buffer/cached will be used quickly.) )

si  If this value is greater than 0, it means that the physical memory is not enough or the memory is leaked. My machine has plenty of memory and everything is fine.

so  The size of the disk written to virtual memory per second, if this value is greater than 0, the same as above.

bi  block equipmentThe number of blocks received per second, here the block device refers to all disks and other block devices on the system, the default block size is 1024byte, I don't have any IO operation on the machine, so it has always been 0, but I have seen it on machines that handle large amounts of data (2-3T) can reach 140000/s, and the disk write speed is almost 140M per second

boThe number of blocks sent per second by a block device, for example, when we read a file, bo is greater than 0. bi and bo are generally close to 0, otherwise the IO is too frequent and needs to be adjusted.

inThe number of interrupts per second of CPU, including time interrupts

csThe number of context switches per second, for example, when we call a system function, we need to switch contexts, and thread switchingProcess contextFor example, in web servers such as Apache and nginx, we generally do performance tests with thousands or even tens of thousands of concurrency, and the process of choosing a web server can be lowered by the peak of the process or thread, stress test, until cs to a relatively small value, the number of processes and threads is a more appropriate value. System calls are also the same, every time a system function is called, our code will enter the kernel space, resulting in context switching, which is very resource-consuming, and we should try to avoid frequent calls to system functions. Too many context switches mean that most of your CPU is wasted on context switching, resulting in less time for the CPU to do serious things, and the CPU is not fully utilized, which is not advisable.

ususerCPU timeI once saw that the us was close to 100 and the r running queue reached 80 on a server that did encryption and decryption very frequently (the machine was stress tested, and the performance was not good).

syIf the system CPU time is too high, it means that the system calls are long, such as frequent IO operations.

id  Idle CPU time, generally speaking, id + us + sy = 100, generally I think id is idle CPU usage, us is user CPU usage, sy is system CPU usage.

wtWait for IO CPU time.







Previous:Cute
Next:The seaside is nice
Posted on 10/19/2014 7:40:57 PM |
I can't understand
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com