写本文的原因是http://blog.csdn.net/msdnchina/article/details/53926867
在该链接中,提到了用mpstat看到各个物理cpu使用的不均衡(有的已经在使用,有的基本没有用),然后我的疑问就出来了:mpstat是查看物理cpu使用率的?还是查看逻辑cpu使用率的?
于是我就做了一个实验:
[oracle@localhost ~]$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 2 ---->>>每个插槽2个Core.
Socket(s): 2 ---->>>两个CPU插槽.
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 58
Stepping: 9
CPU MHz: 2494.399
BogoMIPS: 4988.79
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
[oracle@localhost ~]$ mpstat -P ALL 1 5
Linux 2.6.32-573.el6.x86_64 (localhost.localdomain) 12/27/2016 _x86_64_ (4 CPU)
05:07:25 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
05:07:26 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:26 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:26 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:26 PM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:26 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:26 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
05:07:27 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:27 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:27 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:27 PM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:27 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:27 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
05:07:28 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:28 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:28 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:28 PM 2 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 99.00
05:07:28 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:28 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
05:07:29 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:29 PM 0 0.00 0.00 0.99 0.00 0.00 0.00 0.00 0.00 99.01
05:07:29 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:29 PM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:29 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:29 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
05:07:30 PM all 0.00 0.00 0.25 0.00 0.00 0.00 0.00 0.00 99.75
05:07:30 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:30 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:30 PM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
05:07:30 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
Average: all 0.00 0.00 0.05 0.00 0.00 0.00 0.00 0.00 99.95
Average: 0 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 99.80
Average: 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
Average: 2 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 99.80
Average: 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
[oracle@localhost ~]$ --->>>从上面的结果看,mpstat是显示的逻辑cpu,而不是物理cpu.
[oracle@localhost ~]$ uname -a
Linux localhost.localdomain 2.6.32-573.el6.x86_64 #1 SMP Wed Jul 1 18:23:37 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
[oracle@localhost ~]$
而vmstat只是所有逻辑cpu的一个总体使用率,如下:
[oracle@localhost ~]$ vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 1731664 15580 71568 0 0 27 1 27 16 0 1 98 1 0
0 0 0 1731616 15580 71596 0 0 0 0 31 23 0 0 100 0 0
0 0 0 1731616 15580 71596 0 0 0 0 22 17 0 0 100 0 0
0 0 0 1731616 15580 71596 0 0 0 0 17 17 0 0 100 0 0
0 0 0 1731616 15580 71596 0 0 0 0 25 24 0 0 100 0 0
[oracle@localhost ~]$