Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Performance Analysis of vmstat Host

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

First, vmstat introduction and detailed explanation (this blog is reproduced from the blog park blogger in the wind, the blogger's URL: http://www.cnblogs.com/beginner-boy/, thank you again for your careful accumulation

)

Syntax format: vmstat [- V] [- n] [- S unit] [delay [count]]

-V prints version.

-n causes the headers not to be reprinted regularly.

-a print inactive/active page stats.

-d prints disk statistics

-D prints disk table

-p prints disk partition statistics

-s prints vm table

-m prints slabinfo

-t add timestamp to output

-S unit size

Delay is the delay between updates in seconds.

Unit size KRV 1000 KRV 1024 mRO 1000000 MRO 1048576 (default is K)

Count is the number of updates.

Parameter explanation:

-V: displays vmstat version information

-n: displays each field name only once at the beginning

-a: displays active and inactive memory

-d: displays statistics about each disk

-D: displays the overall information of the disk

-p: displays the specified disk partition statistics

-s: displays memory-related statistics and multiple system activity

-m: display slabinfo

-t: when the information is output, the time is also output.

-S: displays in the specified units. The parameters are k, K, m, M, which represent 1000, 1024, 1000000, and 1048576 bytes (byte), respectively. The default unit is K (1024bytes)

Delay: refresh interval. If not specified, only one result is displayed

Count: number of refreshes. If the number of refreshes is not specified, but the refresh interval is specified, the number of refreshes is infinite.

2. Description of each field in vmstat

1 、 procs

R: indicates the number of processes running and waiting for CPU time slices (that is, how many processes are really allocated to CPU). If this value is longer than the number of system CPU, it means that CPU is insufficient and CPU needs to be added.

B: indicates the number of processes waiting for resources, such as waiting for IGM O or memory swapping, etc.

2 、 memory

Swpd: indicates the amount of memory switched to the memory swap area, that is, the amount of virtual memory used (in KB). If it is greater than 0, your machine is out of physical memory. If it is not the cause of the program memory leak, then you should upgrade the memory or migrate the memory-consuming tasks to other machines.

Free: indicates the currently free physical memory

Buff: indicates the baffers cached memory size, that is, the buffer size, which is generally required for reading and writing to block devices.

Cache: indicates the memory size of the page cached, that is, the cache size. It is generally buffered as a file system, and frequently accessed files will be cached. If the cache value is very large, there are more cache files. If the bi in the io is relatively small, the file system efficiency is better.

3 、 swap

Si: indicates that a disk is transferred to memory, that is, the amount of memory that goes into the memory swap area; generally speaking, the size of virtual memory is read from disk every second. If this value is greater than 0, physical memory is insufficient or memory is leaked. Find the memory-consuming process to solve it.

So: indicates the amount of memory entering the disk from memory, that is, the amount of memory that enters memory from the memory swap.

Note: in general, the values of si and so are 0. If the values of si and so are not 0 for a long time, the system memory is insufficient and the system memory needs to be increased.

4 、 io

Bi: indicates the total amount of data read by the block device, that is, read disk (in kb/s)

Bo: indicates the total amount of data written to the block device, that is, the write disk (in kb/s)

Note: if the value of bi+bo is too large and the value of wa is large, it indicates the bottleneck of system disk IO

5 、 system

In: indicates the number of device terminals per second observed during a time interval

Cs: indicates the number of context switches per second. For example, when we call a system function, we need to switch context, thread switching, and process context switching. This value should be as small as possible, too large. We should consider reducing the number of threads or processes. For example, in web servers such as apache and nginx, we usually do thousands or even tens of thousands of concurrent tests when doing performance tests. The process that selects the web server can be downgraded by the peak of the process or thread, and the pressure test will be carried out until the cs reaches a relatively small value, which is the appropriate value for the number of processes and threads. The same is true of system calls. 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 our best to avoid frequent calls to system functions. Too many context switching times means that most of your CPU is wasted on context switching, resulting in less time for CPU to do serious things, and CPU is not fully utilized, which is not advisable.

Note:

The higher these two values, the more CPU is consumed by the kernel

6 、 CPU

Us: indicates the percentage of CPU time consumed by the user process. The higher the us value, the more CPU time the user process consumes. If the long-term consumption is more than 50%, you need to consider the optimization program or algorithm.

Sy: indicates the percentage of CPU time consumed by the kernel process of the system. Generally speaking, us+sy should be less than 80%. If it is greater than 80%, it means that there may be a CPU bottleneck.

Id: indicates the percentage of time that CPU is in the spatial state

Wa: indicates the percentage of CPU time occupied by IP waiting. The higher the w value, the more serious the wait. According to the experience, the reference value of wa is 20%. If it exceeds 20%, it means that the wait is serious. The cause of the wait may be caused by a large number of random reads and writes on the disk, or by the loan bottleneck of the disk or monitor (mainly block operation).

To sum up, if you evaluate CPU, you need to focus on the r column values of procs items and the values of us, sy, and wa columns that CPU thinks.

III. Use practice

Generally, the use of vmstat tools is accomplished by two numeric parameters. The first parameter is the number of sampling intervals in seconds, and the second parameter is the number of sampling times, such as:

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

In fact, in the process of application, we will keep monitoring for a period of time, and we just need to end the vmstat without monitoring, for example:

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

-

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report