CPU performance indicators:
1. CPU usage;
CPU runs regular user processes
CPU runs niced Process
CPU runs Real-Time Processes
2. CPU usage of the system;
For I/O management: interrupt and driver
MemoryManagement: Page exchange
User Process Management: process start and context switch
3. WIO: the ratio at which the CPU is idle when the process waits for disk I/O.
4. CPU idle rate, except for the preceding WIO
5. Percentage of CPU used for context switching
6. Nice
7. Real-time
8. Length of the running process queue
9. Average Load
Tools commonly used in Linux to monitor the overall CPU performance include:
Mpstat: mpstat not only displays the average information of all CPUs, but also the information of the specified CPU.
Vmstat: Only the average information of all CPUs can be viewed; CPU queue information can be viewed;
Iostat: Only the average information of all CPUs can be viewed.
SAR: Like mpstat, you can not only view the average CPU information, but also the information of the specified CPU.
Top: The displayed information is similar to PS, but top can understand the CPU consumption and update the Display Based on the time specified by the user.
The following is a one-to-one introduction:
I. vmstat
[Root @ localhost ~] # Vmstat-N 3 (refresh every 3 seconds)
Procs ----------- memory ------------------ swap -- ---- Io ---- -- System ---- ------ CPU --------
R B SWPD free buff cache Si so Bi Bo in CS us Sy ID wa
10 144 186164 105252 2386848 0 0 18 166 83 2 48 21 31 0
20 144 189620 105252 2386848 0 0 177 1039 34 10 56 0
00 144 214324 105252 2386848 0 0 0 10 1071 670 32 5 63 0
00 144 202212 105252 2386848 0 0 0 189 1035 20 3 77 0
20 144 158772 105252 2386848 0 0 203 1065 70 14 15 0
Red content indicates CPU-related parameters
Proc (esses) -- R: If the sequence (process R) Running in processes is continuously greater than the number of CPUs in the system, it indicates that the system is running slowly, most processes are waiting for the CPU.
If the number of R outputs is four times the number of available CPUs in the system, the system is facing a CPU shortage problem, or the CPU speed is too low. Most processes in the system are waiting for the CPU, the process in the system is slow.
System
-- In: The number of interruptions per second.
-- CS: Number of context switches generated per second
The larger the two values, the larger the CPU time consumed by the kernel.
CPU
-Us: CPU time consumed by user processes
When the value of us is high, it indicates that the user process consumes a lot of CPU time. However, if the CPU usage exceeds 50% for a long time, we should consider optimizing program algorithms or accelerating (such as PHP/perl)
-Sy: Percentage of CPU time consumed by kernel processes (when the SY value is high, it indicates that the system kernel consumes a lot of CPU resources, which is not a benign performance. We should check the cause)-Wa: percentage of CPU time consumed by I/O wait
When the value of WA is high, it indicates that the IO wait is serious, which may be caused by a large number of random access to the disk or disk bottlenecks (block operations ).
-ID: percentage of time when the CPU is idle. If the idle time (cpu id) persists to 0 and the system time (CPU Sy) is twice the user time (CPU us) the system is facing a shortage of CPU resources.
Solution:
When the preceding problem occurs, adjust the CPU usage of the application. so that the application can use the CPU more effectively. you can also consider adding more CPUs. the CPU usage can also be combined with mpstat, PS aux top prstat-A, and other related commands to comprehensively consider the specific CPU usage, and those processes are occupying a lot of CPU time. generally, application problems may be larger. for exampleSQLUnreasonable statements and so on will cause such a phenomenon. 2. SAR
SAR [Options] [-A] [-o file] T [N]In the command line, the N and T parameters are combined to define the sampling interval and number of times. t indicates the sampling interval, which must be
N is the number of samples and is optional. The default value is 1.-o file indicates that the command result is in binary format.
Stored in a file. The file is not a keyword but a file name. Options is the command line option, sar command
There are many options, and only common options are listed below:
-A: total of all reports.
-U: CPU usage
-V: process, I node, file, and lock table status.
-D: hard disk usage report.
-R: memory and swap space usage statistics.
-G: serial port I/O.
-B: Buffer usage.
-A: file read/write status.
-C: System Call status.
-Q: Report queue length and average system load
-R: Process activity.
-Y: terminal device activity.
-W: system exchange activity.
-X {pid | self | all}: reports statistics of the specified process ID. The self keyword is the statistics of the SAR process, and the All keyword is the statistics of all system processes.
Analysis of CPU utilization using SAR # Sar-U 2 10
Linux 2.6.18-53. el5pae (localhost. localdomain) 03/28/200907: 40: 17 Pm CPU % USER % nice % System % iowait % steal % idle
07:40:19 all 12.44 0.00 6.97 1.74 0.00 78.86
07:40:21 all 26.75 0.00 12.50 16.00 0.00 44.75
07:40:23 all 16.96 0.00 7.98 0.00 0.00 75.06
07:40:25 all 22.50 0.00 7.00 3.25 0.00 67.25
07:40:27 all 7.25 0.00 2.75 2.50 0.00 87.50
07:40:29 all 20.05 0.00 8.56 2.93 0.00 68.46
07:40:31 all 13.97 0.00 6.23 3.49 0.00 76.31
07:40:33 all 8.25 0.00 0.75 3.50 0.00 87.50
07:40:35 all 13.25 0.00 5.75 4.00 0.00 77.00
07:40:37 all 10.03 0.00 0.50 2.51 0.00 86.97
Average: All 15.15 0.00 5.91 3.99 0.00 74.95 displayed:% USER: Percentage of CPU time in user mode.
% Nice: Percentage of CPU time in user mode with nice value.
% SYSTEM: Percentage of CPU time in system mode.
% Iowait: Percentage of CPU waiting for input/output completion time. % Steal: Percentage of unconscious waiting time of the virtual CPU when the hypervisor maintains another virtual processor.
% Idle: Percentage of idle CPU time. In all the displays, we should pay attention to % iowait and % idle. The value of % iowait is too high, indicating that the hard disk has an I/O bottleneck, and the value of % idle is high, indicating that the CPU is idle, if the % idle value is high but the system response is slow, it may be that the CPU is waiting for memory allocation. In this case, the memory capacity should be increased. If the value of % idle is lower than 10, the CPU processing capability of the system is relatively low, indicating that the most important resource to be solved in the system is the CPU. Analyze the queue length of running processes using SAR: # Sar-Q 2 10
Linux 2.6.18-53. el5pae (localhost. localdomain) 03/28/200907: 58: 14 PM runq-SZ plist-SZ ldavg-1 ldavg-5 ldavg-15
07:58:16 PM 0 493 0.64 0.56 0.49
07:58:18 pm 1 491 0.64 0.56 0.49
07:58:20 pm 1 488 0.59 0.55 0.49
07:58:22 PM 0 487 0.59 0.55 0.49
07:58:24 PM 0 485 0.59 0.55 0.49
07:58:26 pm 1 483 0.78 0.59 0.50
07:58:28 PM 0 481 0.78 0.59 0.50
07:58:30 pm 1 480 0.72 0.58 0.50
07:58:32 PM 0 477 0.72 0.58 0.50
07:58:34 PM 0 474 0.72 0.58 0.50
Average: 0 484 0.68 0.57 runq-SZ: The process running queue to be run.
Plist-SZ Number of processes and threads in the process queue
Average system load (average) of the last minute of the ldavg-1)
Average system load for the first five minutes of the ldavg-5 (load average)
By the way, load avarage can be understood as the number of processes that the CPU is waiting to run per second. in Linux systems, commands such as SAR-Q, uptime, W, and top all have average system load and average output. What is the average system load?
The average system load is defined as the average number of tasks in the queue during a specific time interval. If a process meets the following conditions, it will be in the running queue:
-It has no results waiting for I/O operations.
-It does not take the initiative to enter the waiting state (that is, it does not call 'wait ')
-Not stopped (for example, waiting for termination)
For example:
# Uptime
20:55:40 up 24 days, 1 user, load average: 8.13, 5.90, 4.94
The final content of the command output indicates the average number of processes in the queue in the past 1, 5, and 15 minutes.
Generally, as long as the number of active processes of each CPU is not greater than 3, the system performance is good. If the number of tasks of each CPU is greater than 5, it indicates that the performance of this machine has a serious problem. In the preceding example, if the system has two CPUs, the current number of tasks for each CPU is 8.13/2 = 4.065. This indicates that the system performance is acceptable. Iii. iostat # iostat-C 2 10
Linux 2.6.18-53. el5pae (localhost. localdomain) 03/28/2009 AVG-CPU: % USER % nice % System % iowait % steal % idle
30.10 0.00 4.89 5.63 0.00 59.38avg-CPU: % USER % nice % System % iowait % steal % idle
8.46 0.00 1.74 0.25 0.00 89.55avg-CPU: % USER % nice % System % iowait % steal % idle
22.06 0.00 11.28 1.25 0.00 4, mpstat
Mpstat is short for Multiprocessor statistics and is a real-time system monitoring tool. Its report and CPU statistics are stored in the/proc/STAT file. In a multi-CPUs system, it can not only view the average status information of all CPUs, but also view information about specific CPUs. The following describes only the CPU-related parameters of mpstat. The mpstat syntax is as follows:
Mpstat [-P {| all}] [internal [count]
The parameters are described as follows:
Parameter description
-P {| all} indicates the CPU to be monitored. The CPU value ranges from 0 to 1.
Interval between two adjacent internal sampling
Count: the number of samples. Count can only be used with delay.
If no parameter exists, mpstat displays the average value of all information after the system is started. The average information of the first line since the system was started when interval exists. From the second line, the output is the average information of the previous interval period. CPU-related output is described as follows:
Get data from/proc/STAT
CPU processor ID
User-state CPU time (%) during the internal period, excluding nice value for negative process usr/total * 100
Nice in the internal period, nice value is the CPU time of the negative process (%) Nice/total * 100
System in the internal time period, the core time (%) system/total * 100
Hard Disk I/O wait time (%) iowait/total * 100 during the internal Period
IRQ in the internal period, Soft Interrupt time (%) IRQ/total * 100
Soft Interrupt time (%) softirq/total * 100 during internal Period
Idle in the internal period, the idle time (%) idle/total * 100 (excluding the idle time (%) of CPU waiting for disk I/O operations for any reason)
Intr/s: the number of CPU interruptions received per second during the internal period. intr/total * 100
Total CPU time = total_cur = user + system + nice + idle + iowait + IRQ + softirq
Total_pre = pre_user + pre_system + pre_nice + pre_idle + pre_iowait + pre_irq + pre_softirq
User = user_cur-user_pre
Total = total_cur-total_pre
_ Cur indicates the current value, and _ pre indicates the value before the interval time. All values in the preceding table can be two decimal places.
# Mpstat-P all 2 10
Linux 2.6.18-53. el5pae (localhost. localdomain) 03/28/2009 10:07:57 CPU % USER % nice % sys % iowait % IRQ % Soft % steal % idle intr/s
10:07:59 all 20.75 0.00 10.50 1.50 0.25 0.25 0.00 66.75 1294.50
10:07:59 PM 0 16.00 0.00 9.00 1.50 0.00 0.00 0.00 73.50 1000.50
10:07:59 pm 1 25.76 0.00 12.12 1.52 0.00 0.51 0.00 60.10 5, top of the command for details: http://space.itpub.net /? Uid-8554499-action-viewspace-itemid-580475 from: http://space.itpub.net/8554499/viewspace-580300