=====Article Directory=====
The server in the production environment slows down, talk about diagnosis ideas and performance evaluation
There are many reasons for server slowdown in the production environment. Look at the whole machine, CPU, memory, disk, network IO, etc., and optimize according to the specific situation.
Whole machine: top command
The top command is a commonly used performance analysis tool under Linux, which can display the resource usage of each process in the system in real time .
We know that to determine the load of a system, you can use top , uptime and other commands to view load average
it . It records the average load of the system for one minute, five minutes, and fifteen minutes.
$ top
The sum of the three values of load average is divided by 3 and then multiplied by 100%. If it is higher than 60%, the system load is large.
cpu:vmstat
The vmstat command reports statistics about kernel threads, virtual memory, disks, traps, and CPU activity. The reports generated by the vmstat command can be used to balance system load activity. The system-wide statistics (in all processors) calculate the average value expressed as a percentage, or calculate the sum.
$ vmstat -n 2 3
additional
View all cpu core information
mpstat -P ALL 5 2
Indicates that a report is generated every 5 seconds, and a total of 2 reports are generated.
Detailed explanation of mpstat command parameters in Linux
Decomposition information of CPU usage by each process
pidstat is mainly used to monitor the occupancy of system resources by all or specified processes, such as CPU, memory, device IO, task switching, threads, etc. When pidstat is run for the first time, it displays various statistics from the start of the system, and running pidstat afterwards will display the statistics since the last time the command was run. Users can obtain the required statistical information by specifying the number and time of statistics.
pidstat use -p
options, we can view the system resource usage of a specific process.
Using -u
options, pidstat will display the cpu usage statistics of each active process . The effect of pidstat -u
execution is pidstat
the same as that of individual execution .
pidstat -u 1 -p 进程编号
Sampling every second, print out the details.
Memory: free
How to observe the memory usage problem, free is a very useful command. The
parameter -m
displays the memory usage in MB.
$ free
total used free shared buff/cache available
Mem: 4000436 1192152 266780 53844 2541504 2468412
Swap: 4194300 524 4193776
$ free -g
total used free shared buff/cache available
Mem: 3 1 0 0 2 2
Swap: 3 0 3
$ free -m
total used free shared buff/cache available
Mem: 3906 1163 260 52 2482 2410
Swap: 4095 0 4095
Experience
- Application available memory/system physical memory>70% sufficient memory
- Application available memory / system physical memory <20% insufficient memory, need to increase memory
- 20%<application available memory/system physical memory<70% memory is basically enough
additional
pidstat use -r
option, pidstat will display the memory usage statistics of each active process
pidstat -p 进程号 -r 采样间隔秒数
Detailed explanation of the pidstat command for real-time monitoring of Linux running processes
Disk: df
$ df -h
文件系统 容量 已用 可用 已用% 挂载点
udev 1.9G 0 1.9G 0% /dev
tmpfs 391M 1.5M 390M 1% /run
/dev/sda1 28G 20G 7.1G 74% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 391M 20K 391M 1% /run/user/1000
As you can see, 28G has used 20G, 74% of which have been used
Disk: IO
Iostat is mainly used to monitor the IO load of system equipment. When iostat is run for the first time, it displays various statistical information from the start of the system. After that, running iostat will display the statistical information since the last time the command was run. Users can obtain the required statistical information by specifying the number and time of statistics.
iostat -xdk 2 3
Parameter -d
indicates, the display device (disk) used state; -k
the use of certain block in units of column enforce Kilobytes units; represents 2, data refresh every 2 seconds. 3 means, sampling 3 times.
additional
pidstat use -d
options, we can view the statistics of the process IO
pidstat -d 采样间隔秒数 -p 进程号
The program here is an endless loop printing program, so disk IO does not occupy much.
Network IO
The ifstat tool is a network interface monitoring tool, which is relatively simple to look at network traffic
Download
http://gael.roualland.free.fr/ifstat/ (official website)
wget http://gael.roualland.free.fr/ifstat/ifstat-1.1.tar.gz
Compile and install
tar -zxvf ifstat-1.1.tar.gz
cd ifstat-1.1
./configure #默认会安装到/usr/local/bin/目录中
make
make install
Note: Execution which ifstat
output /usr/local/bin/ifstat
#ifstat
eth0 eth1
KB/s in KB/s out KB/s in KB/s out
0.07 0.20 0.00 0.00
0.07 0.15 0.58 0.00
reference
16 Linux server monitoring commands you need to know
Linux/Unix notebook