About the inconsistent CPU usage of the Vmstat,top,ps aux view

Source: Internet
Author: User



About the inconsistent CPU usage of the Vmstat,top,ps aux view

Problem:

Use the vmstat,top, and PS aux three commands to see the CPU occupancy rate of the process, the value varies greatly.


Cases:

Use Vmstat to view the system CPU idle rate, ID is the CPU idle rate, it can be seen that the idle rate has been more than 73%

CPU utilization of two compress processes with PS aux, constant at 15.5% and 28.9% for a long time

Using top statistics Two compress process CPU utilization, can be seen as a dynamic change of the process

(Command execution results are shown later)


These three commands isolate the CPU utilization is not uniform

First, the PS aux two compress process consumes CPU 15.5%+28.9%>40%, plus other processes, for

Vmstat View CPU idle rate ID can also always be greater than 73%

Second, the top command shows the process compress CPU usage and the value of PS display difference is very large, PS

The CPU occupancy rate is shine, always constant,

Top of the comparison dynamic, is the PS aux display process CPU utilization is not reliable?

Finally, the CPU usage detected by these three commands is not uniform with each other, which one is more reliable? For example, enter the following command, in bold is CPU usage


$ vmstat 1

procs-----------Memory-------------Swap-------io------System------CPU----

R b swpd free buff cache si so bi bo in CS US sy ID WA

0 0 432 802660 28724 5747324 0 0 204 770 0 0 6 3 90 2

3 0 432 799196 28724 5747392 0 0 0 152 1455 681 2 2 96 0

0 0 432 802420 28724 5747460 0 0 0 480 1599 1892 10 8 82 0

0 0 432 802292 28724 5747664 0 0 0 440 1859 6179 14 13 73 0

2 0 432 797636 28724 5752084 0 0 0 240 1403 3419 8 7 85 0

1 0 432 798732 28724 5751268 0 0 0 448 1506 4608 10 8 81 0

2 0 432 797924 28724 5752084 0 0 0 192 1752 4332 11 10 79 0

0 0 432 802076 28724 5747936 0 0 0 280 1705 1527 14 6 79 0


$ps aux | grep compress

USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND

IMG 6569 15.5 0.2 36716 16540? S Aug12 230:57./bin/compress 8014

IMG 6570 28.9 0.2 54592 22524? S Aug12 430:28./bin/compress 8004


$top | grep compress

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND

6569 img 0 40956 20m 6632 R 10.7 0.3 231:10.12 Compress

6570 img 0 54592 21m 2456 S 20.3 0.3 430:54.32 Compress

6569 img 0 36740 16m 2456 S 10.3 0.2 231:10.43 Compress

6570 img 0 54592 21m 2456 R 58.9 0.3 430:56.09 Compress

6569 img 0 36716 16m 2456 R 53.9 0.2 231:12.05 Compress

6570 img 0 58444 24m 4752 R 69.9 0.3 430:58.19 Compress

6569 img 0 36716 16m 2456 S 60.2 0.2 231:13.86 Compress

6570 img 0 54592 21m 2456 S 52.6 0.3 430:59.77 Compress

6569 img 0 36716 16m 2456 S 45.3 0.2 231:15.22 Compress


Probably read some of the source code, add:

Top,ps,vmstat are calculated based on the system's proc files, where Vmstat,top uses/proc/stat files, and ps,top uses/procstat files, where * is the process number, calculated as the total number of time slices used by the CPU/ Hertz, currently recognized as the occupancy ratio for each physical CPU, so the values displayed on a dual-core machine need to be divided by the number of cores 2;


3.top uses/proc/stat to calculate the CPU usage shown above, using/proc/*/stat to calculate the elapsed time for each process. However, the calculation is different, the code is more complex, but currently recognized as the default display as Irix mode, that is, the time taken for a single CPU core, such as a dual-core machine needs to divide this value by 2*2 calculation, through shift+i can be switched;


The above explanation can explain the problems that June found:

Question 1: First, PS aux in two compress process consumes CPU 15.5%+28.9%>40%, plus other processes, why Vmstat view CPU idle rate ID can still be greater than 73%

The CPU occupancy of PS needs to be divided by the number of dual cores CPU to 2, so the actual occupancy is (15.5%+28.9%)/2=22.2%, also approximately equal to 100%-73%;


Issue 2: Second, the top command shows the process compress CPU utilization and PS display value difference is very large, PS CPU occupancy rate shine, has been constant value, top of the comparison dynamic, is the PS aux display process CPU utilization is not reliable?

The difference between PS and top is twice times, so the occupancy rate of the display is very different, and the rate of change is larger.


Question 3: Finally, the CPU utilization detected by these three commands is not consistent with each other, which one is more reliable? For example, enter the following command, in bold is CPU usage

The occupancy rate of these three commands is uniform, and the data is consistent when calculated according to the following formula:

Vmstat 100%-idle = = PS CPU occupied/cpu Core Number = = Top CPU occupied/CPU core/physical CPU number;







I think Topas is the real-time reflection process consumes CPU usage, and PS is not, so your script doesn't seem to fulfill your needs.


If PS is, then at the peak of business, you see that the CPU usage should be greater, but actually not. You can observe your system, and the longer the system runs, the smaller the CPU usage of the process seen using PS will appear.





The CPU usage that PS sees is the CPU usage accumulated since the process is running, so inaccurate, please use Topas




As far as AIX systems are concerned, there is no way to use system commands to get the real-time CPU usage of the process, but only by using Topas to get it, but it cannot be recorded.

PS gets to%cpu is the ratio of the actual CPU usage time of the process to the duration of the process, which means that the longer the run time, the less accurate the value.




The CPU usage that PS sees is the CPU usage accumulated since the process is running, so inaccurate, please use Topas



PS command does have limitations, PS aux see the process%cpu is the lifetime mean of the process, not real-time data

I took a lot of detours and finally found an easy way out of Aix's command encyclopedia Tprof




It's not hard to understand. PS is calculated from the beginning of the process, is the average occupancy rate, and top is from the last refresh from the beginning of the calculation, usually a few seconds a brush, can be considered instantaneous. And the desktop system we generally pay more attention to the immediate, so top CPU utilization is what I need. And the top default CPU occupancy rate is not 100%, but the number of x100%, so sometimes there will be a process to occupy more than 100% of the situation.


About the inconsistent CPU usage of the Vmstat,top,ps aux view

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.