The usage __linux of common performance analysis tools under Linux system

Source: Internet
Author: User
Tags time interval cpu usage

Transferred from the "Technology Achievement Dream" blog,

In the previous article, I gave a brief introduction to several aspects of Linux performance and how to solve them, but how do I find out from the system that something is wrong with a certain aspect or a few aspects, which requires the use of several common performance analysis tools provided by the Linux system Here is a detailed account of the use of several common performance analysis tools.

VMSTAT is the acronym for Virtual Meomory Statistics, which is installed by default in many Linux distributions, using the Vmstat command to monitor the operating system's memory information, process status, CPU activity, and so on. The disadvantage is that a process cannot be analyzed in depth.
Vmstat uses the following syntax:
Vmstat [-v] [-n] [delay [count]]
The various options and parameters have the following meanings:
L-v: Indicates that the version information is printed and is an optional parameter.
L-n: Indicates that the output header information is displayed only once when the output is periodically cycled.
L Delay: Represents the time interval between two outputs.
L Count: The number of times that the interval is specified according to "delay". The default is 1.
For example:
Vmstat 3
Indicates that the output information is updated every 3 seconds, the output is cycled, and CTRL + C stops the output.
Vmstat 3 5
Indicates that the output information is updated every 3 seconds, and the output is stopped after 5 times.

Iostat is an abbreviation for I/O statistics (input/output statistics), and the primary function is to monitor disk I/O operations on the system. Its output mainly shows the statistics of disk read and write operations, but also gives the CPU usage. Like Vmstat, Iostat can not analyze a process in depth, only the overall situation of the system analysis.
Iostat generally do not install with the system, to use the Iostat tool, you need to install a SYSSTAT toolkit on the system, Sysstat is an open source software, the official address is Http://
You can choose the source code package or RPM package installation, here is not about the installation process, installation, the system will be more than 3 orders: Iostat, SAR and Mpstat. You can then run the Iostat command directly under the system.
Iostat uses the following syntax:
Iostat [-C |-d] [-K] [-t] [-X [Device]] [interval [count]]
The various options and parameters have the following meanings:
-C: Displays CPU usage.
-D: Displays the usage of the disk.
-K: Displays data in K bytes per second.
-T: Prints the time when the statistics start executing.
-X Device: Specifies the name of the disk device to be counted, and defaults to all disk devices.
Interval: Specify two times of statistical interval;
Count: The number of times that are counted according to the time interval specified by interval.

SAR command is very powerful, is one of the important tools to analyze the performance of the system, through the SAR command, can fully obtain the system's CPU, run queue, disk I/O, paging (swap area), memory, CPU interrupt, network performance data.
SAR use format is:
SAR [options] [G1] [-o filename] [interval [count]]
The various options and parameters have the following meanings:
L options for command-line options, there are a lot of SAR commands, and the following lists only the common options:
-A: Displays the health of all resource devices (CPU, memory, disk) on the system.
-U: Displays the load status of all CPUs in the system during sampling time.
-P: Displays the usage of the specified CPU in the current system.
-D: Displays the usage of all hard disk devices for the system during the sampling time.
-r: Displays the usage in the system for sampling time.
-B: Shows how the buffer is used during the sampling time.
-V: Displays processes, files, I nodes, and lock table states.
-N: Displays network running status. Parameters can be followed by Dev, Edev, sock, and full. DEV Displays network interface information, EDEV display the network error statistics, sock display socket information, full display three all information. They can be used individually or together.
-Q: Shows the size of the run queue, which is the same as the average system load.
-r: Displays the activity of the process during the sampling time.
-y: Displays the activity of the terminal equipment during the sampling time.
-W: Displays the state of the system exchange activity during the sampling time.
L-o FileName: Indicates that the command result is stored in a binary format in a file, filename is the filename.
L Interval: Indicates the sampling interval time, is the necessary parameter.
L Count: Is the number of samples, an optional parameter, and the default value is 1.

To view the overall load status of the system CPU, statistics are counted 5 times per 3 seconds, and the following combinations can be used:
Sar–u 3 5
The system's CPU count starts at 0, and if you want to see the second CPU running load, use the following combination:
Sar–p 1 3 5
To view the read/write performance of the system disk, use the following combination:
Sar-d 3 5
Similarly, to view system memory usage, network running status, you can use the following command:
Sar-r 5 2
Sar-n DEV 5 3
4. System Performance Analysis Standard
The main purpose of performance tuning is to enable the system to effectively use a variety of resources, maximize the performance of the application and system integration, so that the application of efficient and stable operation. However, there is no strict definition of the criteria for measuring system resource utilization, and there is no unified view for different systems and applications, therefore, the standard provided here is actually an empirical value, table 15.1 gives a general guideline for determining the utilization status of system resources:
Table 1 provides a general guideline for determining the utilization status of the system resources:
Table 1
%user: Represents the percentage of time that the CPU is in user mode.
%sys: Represents the percentage of time that the CPU is in system mode.
%iowait: Represents the percentage of time that the CPU waits for input and output to finish.
Swap in: Si, which represents the page import of virtual memory, which is exchanged from swap disk to RAM.
Swap: So, a page export that represents virtual memory, that is, swapping from RAM to swap DISK.

We have explained the three commonly used system performance analysis tools, in fact, there are a lot of analysis tools Linux, such as uptime can check the average CPU load, free can see the use of system memory, PS, top can cooperate with the monitoring system of the process running state, Netstat can monitor network traffic status, and so on, the use of these commands in my previous article has been told a lot, it is not here to explain.

In response to this problem, the first step to do is to detect the network, you can ping the site to check the domain name resolution is normal, at the same time, ping server address delay is too large, and so on, in this way, first of all, to eliminate the problem of the network; If the network is not a The Linux system memory usage check, because the Web site response speed is slow, generally associated with the memory is relatively large, through free, vmstat and other commands to determine whether the memory resources are scarce, if the memory resources do not exist, enter the third step, check the system CPU load status, you can through SAR, Vmstat, top and other commands to determine whether the CPU overload problem, if the CPU is not a problem, continue to enter the fourth step, check the system disk I/O bottlenecks, you can through the Iostat, Vmstat and other commands to check the read and write performance of the disk, if the disk read and write is no problem, Linux system's own performance problems are basically eliminated, the last thing to do is to check the program itself whether there are problems. Through such thinking, layers of detection, step-by-step troubleshooting, performance problems on the "Nowhere to hide", to find the link of performance problems has become very simple.

1. Vmstat command

2. Iostat command

3. SAR command

For example:


5. In conclusion,

System performance optimization is a broad, cumbersome, long-term work, to find the root of the problem is often the hardest part, once the cause of the problem, performance problems will be solved. Therefore, the idea of solving problems becomes very important.

For example, the Linux system under a Web site system, users reflect the speed of Web access is slow, sometimes inaccessible.

Related Article

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: 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.