2020 Autumn Recruitment_High-performance server optimization and detection

From "LInux High Performance Server Programming"-You Shuang

High number of concurrent computing servers
Query rate per second QPS : A measure of how much traffic a specific query server handles within a specified time, that is, the number of requests per second, that is, the maximum talking capacity.
Concurrent number : Concurrent number and QPS are different concepts. Generally speaking, QPS will say how many concurrent users will use QPS. When QPS is the same, the greater the number of concurrent users, the better the concurrent processing capability of the website. When the number of concurrent users is too large, it will cause frequent processes (threads) to switch. Anyway, the real time for processing requests will decrease, and the number of requests that can be processed per second will decrease. At the same time, the waiting time of users' requests will also increase. Finding the optimal number of threads can make the web system more stable and more efficient.

Instruction use

ps

ps -ef | grep command detailed explanation
The function of ps command is to display process information.
For example, ps -ef | grep Serverdisplay server process information.

System detection tool

mpstat

mpstat (multi-processer statistics), which can detect the usage of each CPU on a multi-processor system in real time .
%usr: Except for processes with a negative nice value, the percentage of time that other processes on the system are running in user space to the total running time of the CPU.
%sys: The ratio of the time that all processes on the system run in the kernel space to the total running time of the CPU, but does not include the CPU time consumed by hardware and software interrupts.
%idle: The ratio of the system idle time to the total running time of the CPU.
The above three fields basically reflect the proportion of business logic code and system calls in the code, and how much load the system can withstand.

(Nice value is a value representing static priority in UNIX-like operating systems. Each process has its own static priority, and processes with high priority are given priority to run.
The range of Nice value is -20~+19, with Nice value The larger the process, the lower the actual priority (that is, the process with a Nice value of +19 has the smallest priority, and the process with a value of -20 has the largest priority), and the default Nice value is 0. Since the Nice value is a static priority, once Set, it will not be modified by the kernel until it is reset. The Nice value only plays a role in interfering with the CPU time allocation. The actual details are determined by the dynamic priority.
The name "Nice value" comes from the English word nice, It means friendly. The higher the Nice value, the more "friendly" the process is, and the more time it will give to other processes.)

iostat

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 since the start of the system. Afterwards, running iostat will display the statistical information since the last time the command was run.
Detailed explanation of Linux IO real-time monitoring iostat command

ifstat

ifstat (interface statistics) is a simple network traffic detection tool.

vmstat

Vmstat (virtual memory statistics) can output the usage of various resources of the system in real time , such as process information, memory usage, CPU usage, and I/O usage.

netstat

netstat is a very powerful network information statistics tool.
Such as netstat -t | grep 127.0.0.1:9006viewing the specified IP:PORTTCP connection status.

strace

strace is an important tool for testing server performance. It tracks the system calls and signals received during the running of the program, and outputs the system call names, parameters, return values, and signal names to standard output or a specified file.

nc

nc (netcat) is mainly used to quickly build network connections . We can make it run as a server, monitor a certain port and receive client connections, so it can be used to debug client programs. We can also make it run as a client, initiate a connection to the server and send and receive data, so it can be used to debug the server program, at this time it is a bit like a telnet program.
Such as nc -C 127.0.0.1 9006connecting to the server.

lsof

lsof (list open file) is a tool that lists file descriptors currently open on the system.

tcpdump

tcpdump is a classic network packet capture tool.

Server modulation, debugging and testing

Performance test indicators

Stress test (webbench)

webbench principle

[Source code analysis] Webbench-a concise and beautiful stress testing tool
for server stress testing tools used under Linux, using fork to establish multiple sub-processes, each sub-process continuously establishes a TCP connection with the server during the test time, sends request messages, and then Statistics by the parent process (through the pipeline): the number of successful TCP connections, the number of failed TCP connections, and the amount of data received from the server.

test

Running ./webbench -c 10500 -t 5 -2 http://127.0.0.1:9006/, it can be seen that the server can withstand 1w+ concurrent connections, the number of requests processed per second is about 4.5w (224613/5), and no failed requests are processed. (The HTTP request of webbench is only to visit the home page of the web, that is http://127.0.0.1:9006/, it does not test the login page etc.)
Stress test-success
Increase the number of concurrent connections ./webbench -c 11000 -t 5 -2 http://127.0.0.1:9006/and find that the 10808th child process of fork fails.
Stress test-failed
Run it again and find that it can only fork 9099 child processes at most. This is because webbench does not end the child processes of fork after exiting abnormally, so killall webbenchall child processes of fork need to be ended.
Stress test-failed 2
ulimit is used for the resources occupied by the shell startup process and can be used to set system limits. Set open filesand max user processesset under root (The maximum file descriptors that can be opened at the same time under ordinary users can only be set to 4096, and the maximum number of user processes can only be set to 63698.
Maximum number of processes, maximum threads, and files opened by processes under Linux ulimit command to change the number and hardware resource constraints
ulimit
present problems, revised open filesand max user processesfailed fork sub-process after the first 10808, limit computer performance? the default maximum number of user processes >> 63698 10808, 10808 Why only fork child process?
test To change the size max user processes=15000, that is ulimit -u 15000, to run again, the fork of the 10808th child process fails. The guess is that the system performance limitation or some setting problem.

Guess you like

Origin blog.csdn.net/XindaBlack/article/details/106661604