Linux performance monitoring and analysis-CPU

Source: Internet
Author: User


Linux performance monitoring and analysis-CPU performance indicators 1. CPU usage ratio of user processes 2. CPU usage ratio of system processes 3. WIO, waiting for I/O is the ratio of the CPU in idle state. 4. CPU idle rate 5. CPU for context switching ratio 6, nice7, real-time8, run process queue length 9, average load Linux commonly used to monitor CPU performance tools are 1. iostat www.2cto.com can only view the average information of all CPUs. vmstat can view the average information of all CPUs and CPU queue information. mpstat allows you to view information about a single CPU and all CPUs. 4. sar is similar to mpstat 5. top6. nmoniostat [plain] <span style = "font-size: 18px;"> $ iostat Linux 2.6.18-92. el5 08/30/2012 avg-cpu: % user % nice % system % iowait % steal % idle 1.16 0.01 0.62 0.18 0.00 </span> vmstat [plain] <span style = "font-size: 18px; "> $ vmstat-n 5 procs ----------- memory ---------- --- swap -- ----- io ---- -- system -- ----- cpu ------ r B swpd free buff cache si so bi bo in cs us sy id wa st 0 0 96 1261196 981892 3638872 0 0 0 0 16 1 1 1 98 0 0 0 </span>-n 5 parameter indicates refreshing procs www.2cto.com r every 5 seconds -- the following number indicates the running sequence. If this value is greater than the number of CPUs in a row, the system runs slowly and most processes are waiting for the CPU. If the number of r is greater than 4 times that of the CPU, the system is facing a CPU shortage or the CPU speed is too low, resulting in slow system operation. System in -- 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 system process. CPU us: the percentage of CPU consumed by a user process. If it remains high for a long time, you need to optimize the program. Sy-Percentage of CPU consumed by system processes. The high sy value is not benign. Wa -- percentage of CPU time consumed by I/O wait. When the value is high, the I/O wait is serious. This may be caused by a large number of random disk accesses or disk bottlenecks. Id -- percentage of idle CPU time. If it continues to be 0 and sy is twice that of us, the system is facing a shortage of CPU resources. When this 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. mpstat-(Multiprocessor Statistics) implements monitoring. information is stored in the/proc/stat file [SQL] <span style = "font-size: 18px; "> $ mpstat-p all 2 10 Linux 2.6.18-92. el5 () 08/30/2012 www.2cto.com 08:16:34 pm cpu % user % nice % sys % iowait % irq % soft % steal % idle intr/s 08:16:36 PM all 0.78 0.00 0.26 0.26 0.00 0.26 0.00 98.44 1058.85 08:16:36 PM 0 0.52 0.00 0.52 0.00 0.00 0.52 0.00 98.44 1058.85 08:16:36 PM 1 0.52 0.00 0.00 0.00 0.00 0.00 0.00 </span> the preceding figure indicates that all CPU usage is sampled every 2 seconds and the total oversampling is 10 times. Syntax: mpstat [-P {| ALL}] [internal [count]-P monitors which CPU, generally, you can use ALL to set the Internal interval. count the number of samples. output parameter meaning: % user -- user-mode CPU time ratio % nice -- CPU time of the negative process % system-core state time iowait -- IO wait time irq -- softidleintr/s the number of times the CPU receives interruptions per second sar [plain] <font size = "4"> <span style = "color: #990000; "> <strong> <span style =" color: #990000; "> <span style =" font-family: Arial; color: #000000; "> $ sar-u 2 10 Linux 2.6.18-92. el5 () 08/30/2012 www.2cto.com 08: 28:36 pm cpu % user % nice % system % iowait % steal % idle 08:28:38 PM all 0.26 0.00 0.00 0.78 0.00 98.97 08:28:40 PM all 0.52 0.00 0.52 0.00 0.00 98.97 </span>> </strong> </span> </font> 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 is a required parameter. n indicates the number of samples and is optional. The default value is 1, -o file: stores command results in binary format. file is not a keyword but a file name. Options is the command line option, and there are many options for the sar command. below, only common options are listed:-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. www.2cto.com % user: percentage of time when the CPU is 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-1507: 58: 16 PM 0 493 0.64 0.56: 58: 18 PM 1 0.4907 491 0.64: 58: 20 PM 1 488 0.59 0.55: 58: 22 PM 0 0.4907 487: 58: 24 PM 0 0.59 0.55 0.4907: 58: 26 PM 1 485 0.59 0.55: 58: 28 PM 0 481 0.78 0.59: 58: 30 PM 1 0.5007 480 0.72: 58: 32 PM 0 477 0.72 0.58: 58: 34 PM 0 0.5007 474 0.72 Average: 0 0.58 0.50 484 0.68 www.2cto.com runq-sz the queue of processes to be run. Plist-sz Number of processes and threads in the process queue ldavg-1 previous minute average system load (load average) ldavg-5 previous five minutes average system load (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: www.2cto.com-it does not have the result of waiting for the I/O operation-it does not take the initiative to enter the waiting state (that is, it does not call 'wait')-it is not stopped (for example: Waiting for termination) for example: # uptime 20:55:40 up 24 days, :06, 1 user, load average: 8.13, 5.90, the final output content of the 4.94 command indicates the average number of processes in the queue running 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.

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.