Http://c.biancheng.net/cpp/html/2782.htmlLinux System Performance Analysis
The purpose of this tutorial is to introduce a number of free system performance analysis tools (commands) that can be used to monitor the utilization of systems resources and to facilitate the detection of bottlenecks.
The overall performance of the system depends on the balance of various resources, similar to the cask theory, the depletion of some resources can seriously hinder the performance of the system.
The resources that need to be monitored in Linux are CPU, main memory (RAM), hard disk space, I/O time, Network time, application and so on.
The main factors that affect system performance are:
Factors |
Description |
User-configured CPU |
The amount of time the CPU spends running user programs in the user state, including library calls, but excluding the time the kernel spends. |
Kernel-State CPU |
The amount of time the CPU spends running system services in the kernel state. All I/O operations require invoking system services, and programmers can influence this part of the time by blocking I/O transmissions. |
I/O time and network time |
The amount of time spent responding to I/O requests and processing network connections. |
Memory |
The time it takes to toggle the context and Exchange data (Virtual memory page import and export). |
Application |
The program waits for the run time--CPU is running another program, waiting to switch to the current program. |
Note: It is generally considered that the user-state CPU and the kernel state CPU spend less than 70% of the time is good.
The following commands can be used to monitor system performance and make appropriate adjustments:
Command |
Description |
Nice |
Specifies the process priority when the program is started. |
Renice |
Adjusts the priority of existing processes. |
Netstat |
Displays various network-related information, including network connectivity, routing tables, Interface states (Interface Statistics), masquerade connections, multicast members (multicast memberships), and so on. In fact, Netstat is used to display statistics related to IP, TCP, UDP, and ICMP protocols, and is typically used to verify the network connectivity of each port on the machine. |
Time |
Detects a command run time and the use of resources (CPU, memory, I/O, and so on). |
Uptime |
View system load conditions. |
Ps |
View resource usage for processes in the system (transient state, not dynamic monitoring). |
Vmstat |
Reports virtual memory usage. |
Gprof |
Accurate analysis of the performance of the program, can give the function call time, number of calls, call relations and so on. |
Top |
Real-time monitoring the resource usage of each process resource in the system. |
Common Command combinations:
- Vmstat, SAR, Mpstat detect whether there is a CPU bottleneck;
- Vmstat, free to detect the existence of memory bottlenecks;
- Iostat detect the presence of disk I/O bottlenecks;
- Netstat detects if there is a network I/O bottleneck.
Linux System Performance Analysis