システムパフォーマンス入門

パフォーマンスに詳しいインフラに憧れて

ユーザ用ツール

サイト用ツール


· 最終更新: 2021/03/06 by kurihara


Linux CPU状況の確認(コマンド比較 top, mpstat, sar)

Linux CPUの基礎知識

/proc/cpuinfoで、CPU情報の取得

root@ubuntu20:~# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 63
model name      : Intel(R) Xeon(R) CPU E5-2660 v3 @ 2.60GHz
stepping        : 2
microcode       : 0x1
cpu MHz         : 2599.996
cache size      : 4096 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single pti fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips        : 5199.99
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 63
model name      : Intel(R) Xeon(R) CPU E5-2660 v3 @ 2.60GHz
stepping        : 2
microcode       : 0x1
cpu MHz         : 2599.996
cache size      : 4096 KB
physical id     : 1
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single pti fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips        : 5199.99
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

root@ubuntu20:~#

lscpuで、CPU情報の取得

root@ubuntu20:~# lscpu
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          2
On-line CPU(s) list:             0,1
Thread(s) per core:              1
Core(s) per socket:              1
Socket(s):                       2
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           63
Model name:                      Intel(R) Xeon(R) CPU E5-2660 v3 @ 2.60GHz
Stepping:                        2
CPU MHz:                         2599.996
BogoMIPS:                        5199.99
Hypervisor vendor:               KVM
Virtualization type:             full
L1d cache:                       64 KiB
L1i cache:                       64 KiB
L2 cache:                        8 MiB
NUMA node0 CPU(s):               0,1
Vulnerability Itlb multihit:     KVM: Vulnerable
Vulnerability L1tf:              Mitigation; PTE Inversion
Vulnerability Mds:               Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Full generic retpoline, STIBP disabled, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxs
                                 r sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl cpui
                                 d tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt ts
                                 c_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single pti fs
                                 gsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt


Linuxコマンド

topで、1秒間隔でCPU状況を確認

top - 00:28:47 up 46 min,  1 user,  load average: 0.00, 0.02, 0.05
Tasks: 149 total,   1 running, 148 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.5 sy,  0.0 ni, 99.0 id,  0.2 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   757968 total,   225028 free,   255560 used,   277380 buff/cache
KiB Swap:   839676 total,   839676 free,        0 used.   364836 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 1289 mysql     20   0 1632884 112180   9392 S   0.3 14.8   0:10.52 mysqld
  949 root      20   0  448308  29240  13908 S   0.0  3.9   0:07.45 dockerd-current
  950 root      20   0  562408  16624   5888 S   0.3  2.2   0:00.90 tuned
  744 root      20   0  113372  15936   3444 S   0.0  2.1   0:00.11 dhclient
  942 root      20   0  379760  12104   7384 S   0.0  1.6   0:00.41 php-fpm
  631 polkitd   20   0  534136  12012   4604 S   0.0  1.6   0:00.08 polkitd
  951 root      20   0  223584  10792   6412 S   0.0  1.4   0:02.88 snmpd
 1041 root      20   0  218604   9756   4020 S   0.3  1.3   0:04.43 docker-containe
  637 root      20   0  537556   9308   6776 S   0.0  1.2   0:00.32 NetworkManager
  647 root      20   0  212936   7324   2744 S   0.0  1.0   0:00.28 rsyslogd
 1684 root      20   0  148360   5964   4632 S   0.0  0.8   0:00.09 sshd
 1606 zabbix    20   0  361732   5848   2568 S   0.0  0.8   0:00.49 zabbix_server
 1601 zabbix    20   0  361732   5840   2520 S   0.0  0.8   0:00.53 zabbix_server
 1075 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.00 php-fpm
 1076 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.02 php-fpm
 1077 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.00 php-fpm
 1078 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.00 php-fpm
 1079 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.00 php-fpm
 1603 zabbix    20   0  361572   5440   2216 S   0.0  0.7   0:00.49 zabbix_server
 1604 zabbix    20   0  361572   5440   2220 S   0.0  0.7   0:00.46 zabbix_server
 1605 zabbix    20   0  361572   5440   2220 S   0.0  0.7   0:00.53 zabbix_server
 1607 zabbix    20   0  361568   5172   1980 S   0.0  0.7   0:00.27 zabbix_server
 1618 zabbix    20   0  358988   5172   1976 S   0.0  0.7   0:00.17 zabbix_server
  953 root      20   0  105996   4068   3096 S   0.0  0.5   0:00.00 sshd



表示中に「1」を入力すると、各CPUごとに確認ができる

top - 00:29:29 up 47 min,  1 user,  load average: 0.00, 0.01, 0.05
Tasks: 149 total,   1 running, 148 sleeping,   0 stopped,   0 zombie
%Cpu0  :  0.7 us,  0.7 sy,  0.0 ni, 98.3 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.3 us,  0.3 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   757968 total,   224956 free,   255556 used,   277456 buff/cache
KiB Swap:   839676 total,   839676 free,        0 used.   364796 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 1289 mysql     20   0 1632884 112192   9392 S   0.3 14.8   0:10.68 mysqld
  949 root      20   0  448308  29240  13908 S   0.0  3.9   0:07.55 dockerd-current
  950 root      20   0  562408  16624   5888 S   0.0  2.2   0:00.90 tuned
  744 root      20   0  113372  15936   3444 S   0.0  2.1   0:00.11 dhclient
  942 root      20   0  379760  12104   7384 S   0.0  1.6   0:00.41 php-fpm
  631 polkitd   20   0  534136  12012   4604 S   0.0  1.6   0:00.08 polkitd
  951 root      20   0  223584  10792   6412 S   0.3  1.4   0:02.92 snmpd
 1041 root      20   0  218604   9756   4020 S   0.3  1.3   0:04.50 docker-containe
  637 root      20   0  537556   9308   6776 S   0.0  1.2   0:00.36 NetworkManager
  647 root      20   0  212936   7324   2744 S   0.0  1.0   0:00.28 rsyslogd
 1684 root      20   0  148360   5964   4632 S   0.0  0.8   0:00.09 sshd
 1606 zabbix    20   0  361732   5848   2568 S   0.0  0.8   0:00.49 zabbix_server
 1601 zabbix    20   0  361732   5840   2520 S   0.0  0.8   0:00.53 zabbix_server
 1075 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.00 php-fpm
 1076 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.02 php-fpm
 1077 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.00 php-fpm
 1078 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.00 php-fpm
 1079 nginx     20   0  379760   5488    768 S   0.0  0.7   0:00.00 php-fpm
 1603 zabbix    20   0  361572   5440   2216 S   0.3  0.7   0:00.50 zabbix_server
 1604 zabbix    20   0  361572   5440   2220 S   0.0  0.7   0:00.46 zabbix_server
 1605 zabbix    20   0  361572   5440   2220 S   0.0  0.7   0:00.54 zabbix_server
 1607 zabbix    20   0  361568   5172   1980 S   0.0  0.7   0:00.27 zabbix_server
 1618 zabbix    20   0  358988   5172   1976 S   0.0  0.7   0:00.19 zabbix_server
  953 root      20   0  105996   4068   3096 S   0.0  0.5   0:00.00 sshd


mpstatで、vmstat風に1秒間隔でCPU状況を表示

# mpstat -P ALL 1
Linux 3.10.0-693.21.1.el7.x86_64 (centos7)      2019年03月30日  _x86_64_        (2 CPU)

23時58分36秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
23時58分37秒  all    0.00    0.00    0.00    0.51    0.00    0.00    0.00    0.00    0.00   99.49
23時58分37秒    0    1.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.00
23時58分37秒    1    0.00    0.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00   99.00

23時58分37秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
23時58分38秒  all    0.00    0.00    0.50    0.00    0.00    0.00    0.00    0.00    0.00   99.50
23時58分38秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
23時58分38秒    1    0.00    0.00    1.01    0.00    0.00    0.00    0.00    0.00    0.00   98.99

23時58分38秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
23時58分39秒  all    0.51    0.00    0.00    1.02    0.00    0.00    0.00    0.00    0.00   98.48
23時58分39秒    0    0.00    0.00    0.00    1.03    0.00    0.00    0.00    0.00    0.00   98.97
23時58分39秒    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

23時58分39秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
23時58分40秒  all    0.00    0.00    0.51    1.01    0.00    0.00    0.00    0.00    0.00   98.48
23時58分40秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
23時58分40秒    1    1.00    0.00    0.00    3.00    0.00    0.00    0.00    0.00    0.00   96.00

23時58分40秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
23時58分41秒  all    0.50    0.00    0.00    3.02    0.00    0.00    0.00    0.00    0.00   96.48
23時58分41秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
23時58分41秒    1    0.00    0.00    0.00    5.10    0.00    0.00    0.00    0.00    0.00   94.90
^C

平均値:   CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
平均値:   all    0.20    0.00    0.20    1.11    0.00    0.00    0.00    0.00    0.00   98.49
平均値:     0    0.20    0.00    0.00    0.20    0.00    0.00    0.00    0.00    0.00   99.60
平均値:     1    0.20    0.00    0.20    1.81    0.00    0.00    0.00    0.00    0.00   97.78


sarでCPUの状況を確認

# sar -P ALL 1
Linux 3.10.0-693.21.1.el7.x86_64 (centos7)      2019年03月31日  _x86_64_        (2 CPU)

23時12分56秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
23時12分57秒     all      0.00      0.00      0.00      0.00      0.00    100.00
23時12分57秒       0      0.00      0.00      0.00      0.00      0.00    100.00
23時12分57秒       1      0.00      0.00      0.00      0.00      0.00    100.00

23時12分57秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
23時12分58秒     all      0.50      0.00      0.50      0.00      0.00     98.99
23時12分58秒       0      0.00      0.00      1.01      0.00      0.00     98.99
23時12分58秒       1      1.00      0.00      0.00      0.00      0.00     99.00

23時12分58秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
23時12分59秒     all      0.00      0.00      0.50      0.00      0.00     99.50
23時12分59秒       0      1.00      0.00      0.00      0.00      0.00     99.00
23時12分59秒       1      0.00      0.00      1.00      0.00      0.00     99.00

23時12分59秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
23時13分00秒     all      0.00      0.00      0.51      0.00      0.00     99.49
23時13分00秒       0      0.00      0.00      1.01      0.00      0.00     98.99
23時13分00秒       1      0.00      0.00      0.00      0.00      0.00    100.00

23時13分00秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
23時13分01秒     all      0.00      0.00      0.50      0.00      0.00     99.50
23時13分01秒       0      0.00      0.00      0.00      0.00      0.00    100.00
23時13分01秒       1      0.00      0.00      0.00      0.00      0.00    100.00
^C


23時13分01秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
23時13分02秒     all      0.75      0.00      0.00      0.00      0.00     99.25
23時13分02秒       0      0.00      0.00      0.00      0.00      0.00    100.00
23時13分02秒       1      0.00      0.00      0.00      0.00      0.00    100.00

平均値:      CPU     %user     %nice   %system   %iowait    %steal     %idle
平均値:      all      0.18      0.00      0.35      0.00      0.00     99.47
平均値:        0      0.18      0.00      0.36      0.00      0.00     99.47
平均値:        1      0.18      0.00      0.18      0.00      0.00     99.64
#

sarで1秒間隔で情報取得

# sar 1
Linux 3.10.0-327.10.1.el7.x86_64 (133-130-97-240)       2021年01月28日  _x86_64_        (2 CPU)

22時52分44秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
22時52分45秒     all      0.00      0.00      0.00      0.00      0.00    100.00
22時52分46秒     all      0.50      0.00      0.50      0.00      0.00     99.00
22時52分47秒     all      1.01      0.00      0.00      0.00      0.00     98.99
22時52分48秒     all      1.99      0.00      0.50      0.50      0.00     97.01
22時52分49秒     all      4.55      0.00      0.00      0.00      0.00     95.45
22時52分50秒     all      3.00      0.00      0.50      0.00      0.00     96.50
22時52分51秒     all      8.50      0.00      0.50      1.00      0.00     90.00
22時52分52秒     all      0.00      0.00      0.00      0.00      0.00    100.00
22時52分53秒     all      2.51      0.00      0.50      0.00      0.00     96.98
22時52分54秒     all      0.00      0.00      0.00      0.00      0.00    100.00
22時52分55秒     all      0.00      0.00      0.00      0.00      0.00    100.00
^C

22時52分55秒     all      1.30      0.00      0.00      0.00      0.00     98.70
平均値:      all      1.98      0.00      0.22      0.13      0.00     97.67
#





· 最終更新: 2021/03/06 by kurihara

ページ用ツール