Linux vmstat Command Actual combat detailed analysis _c language

Source: Internet
Author: User
Tags memory usage switches time interval cpu usage high cpu usage

The Vmstat command is the most common Linux/unix monitoring tool that shows the state value of a server at a given time interval, including CPU utilization, memory usage, virtual memory exchange, and IO reading and writing. This command is my favorite command to check Linux/unix, one is Linux/unix, and the second is that I can see the CPU, memory, IO usage of the entire machine, compared to top, instead of just seeing CPU usage and memory usage of each process (using different scenarios).

The use of general vmstat Tools is done with two numeric parameters, the first parameter is the number of time intervals sampled, the unit is seconds, and the second parameter is the number of times sampled, such as:

Copy Code code as follows:

root@ubuntu:~# Vmstat 2 1procs-----------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 indicates that the server state is collected once per two seconds, and 1 is collected only once.

In fact, in the application process, we will be monitoring for a period of time, do not want to monitor the direct end of the vmstat, such as:

Copy Code code as follows:

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
0 0 3499840 315836, 3819660 0 0 0 1 2 0 0 0 100 0
0 0 3499584 315836, 3819660 0 0 0 0 88 158 0 0 100 0
0 0 3499708 315836, 3819660 0 0 0 2 86 162 0 0 100 0
0 0 3499708 315836, 3819660 0 0 0 10 81 151 0 0 100 0
0 0 3499732 315836, 3819660 0 0 0 2 83 154 0 0 100 0

This means that vmstat every 2 seconds to collect data, has been collected until I end the program, where 5 of the data collected I ended the program.

Well, the command is complete, now start to explain the meaning of each parameter.

R indicates that the running queue (that is, how many processes are actually allocated to the CPU), I tested the server currently CPU is more idle, there is no program running, when this value exceeds the number of CPUs, there will be CPU bottlenecks. This also and top of the load is related to the general load more than 3 higher, more than 5 on the high, more than 10 is not normal, the state of the server is very dangerous. The top load is similar to the run queue per second. If the running queue is too large, which means your CPU is busy, it will generally cause high CPU usage.

b is blocking the process, this is not much to say, process blocking, we understand.

swpd Virtual memory has been used in size, if greater than 0, indicates that your machine physical memory is not enough, if not the reason for the program memory leak, then you should upgrade the memory or the memory of the task to migrate to other machines.

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

Buff Linux/unix system is used to store, the directory contains what content, permissions, etc. cache, I this machine probably occupy more than 300 m

Cache Cache is directly used to memorize the files we open, to buffer the file, I am about 300 m this machine (here is the wisdom of Linux/unix, the spare part of the physical memory to do file and directory cache, is to improve the performance of program execution, When the program is using memory, the buffer/cached will be used very quickly. )

si per second the size of the virtual memory from disk, if this value is greater than 0, indicates that the physical memory is not enough or memory leaks, to find the memory process to solve the loss. My machine has plenty of memory and everything is fine.

so per second virtual memory is written to disk size, if this value is greater than 0, ditto.

The number of blocks received by the BI block device per second, where the block device refers to all the disks and other block devices on the system, the default block size is 1024byte, I do not have IO operation on this machine, so it has been 0, but I have been working on copying large amounts of data (2-3T) Machine can reach 140000/s, disk write speed is almost 140M per second

The number of blocks sent by the Bo block device per second, for example, when we read the file, Bo must be greater than 0. Bi and Bo are generally close to 0, or IO is too frequent and need to be adjusted.

The number of CPU interrupts per second, including time outages

CS The number of context switches per second, for example, we call the system function, we need to do context switching, thread switching, also process context switch, this value to the smaller the better, too big, to consider the number of threads or processes, such as in Apache and nginx such a Web server , we generally do performance testing will be thousands of concurrent or even tens of thousands of concurrent testing, the process of selecting a Web server can be a process or thread peak has been reduced, pressure, until the CS to a relatively small value, the process and the number of threads is the more appropriate value. System call is also, each call system functions, our code will enter the kernel space, resulting in context switching, this is very resource-intensive, but also try to avoid frequent call system functions. Too many context switches means that most of your CPU waste in context switching, resulting in less CPU time to do serious things, the CPU is not fully utilized, is not desirable.

US user CPU time, I used to do encryption decryption very frequently on the server, you can see us close to the 100,r run queue reached 80 (the machine is doing stress testing, poor performance).

sy System CPU time, if too high, indicates a long system call time, such as IO operations frequently.

ID Free CPU time, in general, ID + US + sy = 100, generally I think ID is idle CPU usage, US is the user CPU utilization, SY is the system CPU utilization rate.

wt waits for IO CPU time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.