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

How to use vmstat in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to use vmstat in Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use vmstat in Linux.

Vmstat is the abbreviation of Virtual Meomory Statistics (Virtual memory Statistics), which can monitor the virtual memory, processes and CPU activities of the operating system. He is to carry on the statistics to the overall situation of the system, the deficiency is unable to carry on the in-depth analysis to a certain process. The vmstat tool provides a low-overhead way to observe system performance.

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:

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 wa1 00 3498472 315836 3819540 0 1 2000 0 100 0

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:

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

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

All right, after the introduction of the command, let's start to explain the meaning of each parameter.

R represents the running queue (that is, how many processes are actually assigned to CPU). The server I tested is currently idle in CPU, and there are no programs running. When this value exceeds the number of CPU, there will be a CPU bottleneck. This also has something to do with the load of top. Generally, if the load exceeds 3, it is high, if it exceeds 5, it is high, and if it exceeds 10, it is abnormal. The state of the server is very dangerous. The load of top is similar to the run queue per second. If the running queue is too large, it means that your CPU is very busy, which generally results in high CPU utilization.

B means blocked process, not to mention, process blocking, we all know.

The size of swpd virtual memory that has been used, if it is greater than 0, indicates that 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 memory-consuming tasks to other machines.

The size of free's free physical memory, my machine has a total of 8g of memory, leaving 3415m.

The buff Linux/Unix system is used to store the cache of what contents and permissions are in the directory. My computer takes up more than 300m.

Cache cache is directly used to memorize the files we open and buffer them. My local machine takes up more than 300m. (here is the wisdom of Linux/Unix. Use 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 reads the amount of virtual memory from disk per second. If this value is greater than 0, it means that the physical memory is insufficient or there is a memory leak. Find the memory-consuming process to solve it. My machine has plenty of memory and everything is fine.

So the amount of virtual memory written to disk per second. If this value is greater than 0, it is the same as above.

The number of blocks received by bi block devices per second. The block devices here refer to all disks and other block devices on the system. The default block size is 1024byte. There is no IO operation on my computer, so it has always been 0, but I have seen that it can reach 140000amp s on a machine that handles copying a large amount of data (2-3T), and the disk write speed is about 140m per second.

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

Number of interrupts per second of CPU in in, including time interrupts

The number of context switches per second in cs. For example, when we call system functions, we need to switch contexts, and when we switch threads, we also need to switch the context of processes. This value should be as small as possible, which is too large. We should consider reducing the number of threads or processes. For example, in web servers like apache and nginx, we usually do thousands or even tens of thousands of concurrency 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.

Us user CPU time, I used to do encryption and decryption very frequently on a server, I can see that the us is close to 100 and the running queue reaches 80 (the machine is doing stress testing and the performance is not good).

If the CPU time of the sy system is too high, it means that the system calls take a long time, for example, frequent IO operations.

Id idle CPU time, generally speaking, id + us + sy = 100. generally speaking, I think id is idle CPU utilization, us is user CPU utilization, and sy is system CPU utilization.

Wt wait time for IO CPU.

Thank you for your reading, the above is the content of "how to use vmstat in Linux", after the study of this article, I believe you have a deeper understanding of how to use vmstat in Linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report