phenomena
Haproxy bind 4 Core CPU, 8 core CPU, 16 core CPU, when the pressure is measured, will appear CPU 100% is used situation.
Tracing Process
1. Through the Mpstat-p all 1 command to see where the CPU is used, you can see most of the CPU used in the SYS state.
2. View the Haproxy process through Strace-p pid-c the system call takes up the most CPU and sees the CPU used on the Connect system call.
3. Haproxy Connect back end will use Connect system call, view Haproxy configuration, found that haproxy connected to the back end of only two backend, that is, this situation: Vegeta (40 pressure machine)-"haproxy-" Httptest (2 haproxy back end), where the haproxy connected to the back end can only have 63,000 ports or so, a large number of connections backlog in the Haproxy machine, resulting in the CPU is depleted.
How to use multithreading
Nbproc <number>
Cpu-map < "all" | " Odd "|" Even "|process_num> <cpu-set> .....
These 2 configurations are closely related, and Nbproc refers to how many haproxy processes are started.
#nbproc设置为4, talk about starting 4 processes
Haproxy 11472 0.0 0.0 56520 1228 ? Ss 08:57 0:00./haproxy-f/usr/local/haproxy/conf/haproxy.cfg
haproxy 11473 0.0 0.0 56520 1228? Ss 08:57 0:00./haproxy-f/usr/local/haproxy/conf/haproxy.cfg
haproxy 11474 0.0 0.0 56520 1228? Ss 08:57 0:00./haproxy-f/usr/local/haproxy/conf/haproxy.cfg
haproxy 11475 0.0 0.0 56520 1228? Ss 08:57 0:00./haproxy-f/usr/local/haproxy/conf/haproxy.cfg
#查看pid文件, you can also see four process ID
# cat/run/ Haproxy.pid
11472
11473
11474
11475
Cpu-map is the process of binding processes to a specific CPU, which is the benefit of preventing multiple processes from preemption to the CPU, and can improve a small amount of performance. This configuration directive has 2 parameters, the first parameter is the process sequence number, starting from 1. The second parameter is the CPU number, starting at 0. For example, if a process is bound to a specified CPU.
#查看本机的CPU个数, you can also see the number of CPUs starting at 0
# Cat/proc/cpuinfo | grep processor
Processor : 0
Processor : 1
Processor : 2
processor : 3
# specify
cpu-map 1 0
cpu-map 2 1
cpu-map 3 2
cpu-map 4 3
cpu-map 5 4//The number of the section over Nbproc will be ignored
#全部的进程由0号c PU treatment.
cpu-map all 0
#奇数的进程有0号cpu处理, even processes have 1th CPU processing.
cpu-map Odd 0
Cpu-map even 1
Back-end bindings
Frontend access_http
bind 0.0.0.0:80
bind-process 1
frontend access_https
bind 0.0.0.0:443 SSL Crt/etc/yourdomain.pem
bind-process 2 3 4