Pomiar obciążenia CPU z mpstat w Linuksie
Program mpstat dostarcza informacji o wykorzystaniu poszczególnych procesorów systemu. W wielordzeniowym systemie każdy rdzeń widziany jest jako procesor. W systemach z procesorami z Hyperthreading jeden procesor / rdzeń widziany jest jako dwa rdzenie . mpstat jest w dystrybucjach Linuksa często zawarty w pakiecie sysstat (vide np. w Debianie http://packages.debian.org/sysstat).
Podstawowe informacje o mpstat
mpstat jest zazwyczaj uruchomiany z opcją mpstat -P ALL
. Przez co wyświetlane są informacje o wszystkich poszczególnych procesorach. mpstat -P ALL
pokazuje średnie wartości od ostatniego uruchomienia:
[root@centos4 ~]# mpstat -P ALL Linux 2.6.9-023stab048.6-smp (centos4.thomas-krenn.com) 04/08/09 16:16:08 CPU %user %nice %system %iowait %irq %soft %idle intr/s 16:16:08 all 6.48 0.00 0.87 0.15 0.00 0.14 92.36 1130.51 16:16:08 0 6.38 0.00 0.88 0.15 0.00 0.14 92.44 141.31 16:16:08 1 6.29 0.00 0.85 0.14 0.00 0.14 90.99 141.31 16:16:08 2 6.60 0.00 0.87 0.15 0.00 0.14 91.81 141.31 16:16:08 3 6.81 0.00 0.87 0.14 0.00 0.14 90.47 141.31 16:16:08 4 6.48 0.00 0.86 0.15 0.00 0.14 92.36 141.31 16:16:08 5 6.23 0.00 0.85 0.15 0.00 0.13 91.04 141.31 16:16:08 6 6.37 0.00 0.87 0.15 0.00 0.14 92.03 141.31 16:16:08 7 6.21 0.00 0.84 0.14 0.00 0.13 91.08 141.31 [root@centos4 ~]#
Do analizy przez określony okres mogą zostać podane dwa dalsze parametry. mpstat -P ALL 1 60
odczytuje co sekundę aktualną wartość (60 razy = 1 min.). Ostatnia wartość pokazuje średnią wartość z okresu pomiaru. Możliwy jest wygodny zapis wyniku z mpstat -P ALL 1 60
do pliku:
[root@centos4 ~]# mpstat -P ALL 1 60 > /root/mpstatanalyse20090408-1.txt [root@centos4 ~]#
Oto fragment z tego pliku:
Linux 2.6.9-023stab048.6-smp (centos4.thomas-krenn.com) 04/08/09 15:55:53 CPU %user %nice %system %iowait %irq %soft %idle intr/s 15:55:54 all 22.88 0.00 1.29 0.00 0.00 0.26 75.58 1590.82 15:55:54 0 34.69 0.00 6.12 0.00 0.00 0.00 59.18 198.98 15:55:54 1 17.35 0.00 0.00 0.00 0.00 0.00 80.61 198.98 15:55:54 2 9.18 0.00 1.02 0.00 0.00 0.00 91.84 198.98 15:55:54 3 13.27 0.00 1.02 0.00 0.00 1.02 81.63 198.98 15:55:54 4 31.63 0.00 2.04 0.00 0.00 0.00 67.35 198.98 15:55:54 5 4.08 0.00 0.00 0.00 0.00 0.00 93.88 197.96 15:55:54 6 71.43 0.00 0.00 0.00 0.00 1.02 29.59 198.98 15:55:54 7 0.00 0.00 0.00 0.00 0.00 0.00 96.94 198.98 [...] 15:56:52 CPU %user %nice %system %iowait %irq %soft %idle intr/s 15:56:53 all 25.26 0.00 1.41 0.77 0.00 0.26 72.31 1237.50 15:56:53 0 12.50 0.00 0.00 0.00 0.00 0.00 87.50 155.21 15:56:53 1 40.62 0.00 2.08 0.00 0.00 1.04 60.42 155.21 15:56:53 2 1.04 0.00 1.04 0.00 0.00 1.04 100.00 155.21 15:56:53 3 35.42 0.00 0.00 0.00 0.00 1.04 65.62 154.17 15:56:53 4 8.33 0.00 2.08 0.00 0.00 0.00 90.62 155.21 15:56:53 5 35.42 0.00 3.12 7.29 0.00 0.00 56.25 155.21 15:56:53 6 63.54 0.00 1.04 0.00 0.00 1.04 36.46 154.17 15:56:53 7 8.33 0.00 1.04 0.00 0.00 0.00 90.62 154.17 Average: CPU %user %nice %system %iowait %irq %soft %idle intr/s Average: all 21.58 0.00 1.83 0.59 0.00 0.34 75.66 1417.71 Average: 0 21.87 0.00 2.07 0.32 0.00 0.36 75.38 177.21 Average: 1 20.97 0.00 1.50 0.82 0.00 0.29 75.28 177.21 Average: 2 19.76 0.00 1.68 0.07 0.02 0.34 78.03 177.23 Average: 3 23.98 0.00 1.95 0.05 0.00 0.37 72.49 177.21 Average: 4 23.02 0.00 1.63 0.53 0.00 0.32 74.49 177.21 Average: 5 20.29 0.00 1.65 1.53 0.00 0.36 75.02 177.21 Average: 6 25.95 0.00 2.21 0.08 0.00 0.34 71.27 177.21 Average: 7 15.75 0.00 1.80 1.31 0.00 0.31 79.63 177.21
Znaczenie poszczególnych wartości
(Quelle man mpstat
):
- CPU: Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
- %user: Show the percentage of CPU utilization that occurred while executing at the user level (application).
- %nice: Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
- %sys: Show the percentage of CPU utilization that occurred while executing at the system level (kernel). Note that this does not include time spent servicing interrupts or softirqs.
- %iowait: Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
- %irq: Show the percentage of time spent by the CPU or CPUs to service interrupts.
- %soft: Show the percentage of time spent by the CPU or CPUs to service softirqs. A softirq (software interrupt) is one of up to 32 enumerated software interrupts which can run on multiple CPUs at once.
- %steal: Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
- %idle: Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
- intr/s: Show the total number of interrupts received per second by the CPU or CPUs.
Analiza
Wykorzystanie poszczególnych procesorów / rdzeni
W systemie z kilkoma procesorami lub rdzeniami jest zalecane, w miarę możliwości, ich równomierne obciążenie. Jeśli średnia z mpstat -P ALL
pokazuje jeden procesor ze zbyt dużym udziałem %user, inne procesory zaś ze zbyt niskim udziałem, to przez optymalizację konfiguracji aplikacji może zostać zwiększona całkowita wydajność systemu. Bank danych, który korzysta tylko z pojedynczego theadu / procesu może wykorzystywać tylko jeden rdzeń.
=Okres analizy
mpstat -P ALL
dostarcza średnią od ostatniego uruchomienia (przez co również zawiera czas niskiego obciążenia - nocą i w weekend), dlatego może zostać przeprowadzony przez mpstat -P ALL 1 600 > /root/mpstatanalyse.txt
10-minutowy pomiar w okresie maks. obciążenia. Na końcu tego pomiaru udostępniana jest średnia z tych 10 minut.