There are many factors that affect the performance of Linux servers, from the underlying hardware to the operating system, from the network to the upper level. Finding the balance between system hardware and software resources is key.
1.uptime
10:27:14 up min, 5 users, Load average:10.78, 9.13, 5.42
Focus on the load average parameter, 3 values representing 1 minutes, 5 minutes, 10 minutes of system load. If the load value is twice times longer than the number of CPUs, the system is in a high load state
2.vmstat
Procs
R indicates the number of processes running and waiting for the CPU time slice, if this value is longer than the number of CPUs, indicating insufficient CPU performance
b indicates the number of processes waiting on the resource, waiting for I/O or memory exchange, etc.
Memory
SWPD represents the amount of memory switched to the inner coarse swap, in kilobytes
Free indicates the amount of memory currently idle, in kilobytes
Buff indicates the amount of memory buffers cache
Cache represents the amount of memory for page cached
Swap
Si indicates the number of memory into the memory swap area
So indicates the number of memory swap zones entering memory
#一般情况下, the values for Si and so are 0. If the value of Si and so is not 0 for a long time, system memory is low
Io
BI represents the total amount of data read from a block device, in kilobytes
Bo represents the total amount of data written to the block device, in kilobytes
The value of #bi + Bo is greater than 1000, and the value of WA is large, indicating a problem with the system disk IO
System
In indicates the number of device interrupts per second observed during a time interval
CS represents the number of context switches produced per second, and the larger the value means the more CPU time the kernel consumes
Cpu
US represents the percentage of CPU time consumed by the user process. High value requires consideration of optimizer or algorithm
SY indicates the percentage of CPU time consumed by the kernel process
ID indicates the percentage of the CPU in idle state time
WA represents the percentage of CPU time that IO waits, the higher the value, the more severe the IO waits
St indicates the percentage of time that the virtual machine occupies
The value of #us + sy is greater than 80% and may be low CPU performance
3.top
Mem: Total Memory free memory used by memory used for cached memory
Swap: Swap space total size free swap space used by swap memory space available memory space
#top命令默认5秒刷新一次
#top命令按m键进入内存模式
4.free Viewing memory usage
5.iostat viewing disk I/O
Number of I/O requests per second that TPS sends to kb_read/s number of data blocks read per second KB_WRTN/S number of data blocks written per second
Kb_read all blocks read KB_WRTN the number of blocks written
Common parameters
-C displays only CPU statistics, with-D mutex
-D displays only disk statistics, with-C mutex
-K Displays the number of disk requests per second in kilobytes, the default unit is block
-P followed by a specific device or all to display statistics for a piece of device and system partition
-T prints the time to collect data when outputting data
-V Print version number
-X Output extension information
6.TCP Connection Optimization
After a TCP/IP connection is disconnected, the port is not released until a certain amount of time is retained in the TIME_WAIT state. When there are too many concurrent requests, there will be a lot of time_wait that can not be disconnected in time, which will consume a lot of port resources and server resources.
Netstat-an|awk '/tcp/{print $6} ' |sort|uniq-c
5 established
5 LISTEN
2048 time_wait
Vim/etc/sysctl.conf
#开启重用, allowing connections to the TIME_WAIT state to be re-used for new TCP connections
Net.ipv4.tcp_tw_reuse = 1
#开启TCP连接中TIME_WAIT连接的快速回收
Net.ipv4.tcp_tw_recycle = 1
#控制同时保持TIME_WAIT套接字的最大数量
Net.ipv4.tcp_max_tw_buckets = 1000
Sysctl-p
Net.ipv4.tcp_tw_reuse = 1
Net.ipv4.tcp_tw_recycle = 1
Net.ipv4.tcp_max_tw_buckets = 1000
Netstat-an|awk '/tcp/{print $6} ' |sort|uniq-c
6 established
5 LISTEN
995 Time_wait
TCP Status Description
Linux Performance analysis Tools