Ext.: http://coolshell.cn/articles/7490.html
3.1) View operating system load
First of all, when we have a problem with the system, we do not rush to investigate our code, this is meaningless. The first thing we need to see is the operating system report. Look at the CPU utilization of the operating system, look at the memory usage, look at the OS io, the IO of the network, the number of network links, and so on. Perfmon under Windows is a great tool, and there are a lot of related commands and tools under Linux, such as: Systemtap,latencytop,vmstat, SAR, Iostat, top, tcpdump, etc. By observing the data, we can see where the performance of our software is basically. Like what:
1) First look at the CPU utilization, if the CPU utilization is not high, but the system throughput and latency, which means that our program is not busy computing, but busy with other things, such as IO. (in addition, CPU utilization also depends on the kernel state and the user state, the kernel state of one up, the performance of the entire system down.) For multi-core CPUs, CPU 0 is very critical, if the load of CPU 0 is high, it will affect the performance of other cores, because the CPU is required to have the inter-core scheduling, which is done by CPU0)
2) Then, we can look at the IO is not big, IO and CPU is generally reversed, CPU utilization is high, IO is small, io large CPU. About IO, we want to see three things, one is disk file Io, one is the driver Io (such as: Network card), one is the memory paging rate. These three things can affect the performance of the system.
3) Then, look at the network bandwidth usage, under Linux, you can use Iftop, Iptraf, ntop, tcpdump these commands to view. Or use Wireshark to see.
4) If the CPU is not high, Io is not high, memory usage is not high, network bandwidth usage is not high. But the performance of the system does not go. This indicates a problem with your program, for example, your program is blocked. Maybe it's because of waiting for that lock, maybe because of a resource, or a switch context.
by understanding the performance of the operating system, we know the performance of the problem, such as: insufficient bandwidth, insufficient memory, TCP buffer is not enough, and so on, many times, do not need to adjust the program, only need to adjust the hardware or operating system configuration can be .
Viewing program system bottlenecks