Binding Nginx Applications to Cores
Purpose
In Binding NIC Interrupts to Cores, the NIC interrupts are bound to cores. In addition, cores need to be bound to Nginx applications to process services and interrupts using different cores.
Tuning guideline: On the premise that service cores are fully loaded, use as few interrupt cores as possible.
Procedure
- Open the nginx.conf file in the /usr/local/nginx/conf directory.
1vim /usr/local/nginx/conf - Press i to enter the insert mode and modify the related parameters.
- Set worker_processes to the number of bound cores.
- Add the worker_cpu_affinity parameter to specify the cores to be bound for the Nginx service in binary masks.
The following is an example of the configuration code:
user root; worker_processes 4; worker_cpu_affinity 1 10 100 1000;
Table 1 describes the parameters.
Table 1 Parameters Parameter
Description
worker_processes
Specifies the number of CPU cores for running Nginx applications.
worker_cpu_affinity
Specifies the cores for running Nginx applications. It is represented by a binary mask. Each core is represented by a separate line. For example, 10 indicates that the second core is used to run Nginx applications.
- In the binary mask of worker_cpu_affinity, the last valid line must end with a semicolon (;).
- The number of valid rows in worker_cpu_affinity must be the same as the value of worker_processes.
- To maximize the server performance, ensure that the cores for processing NIC interrupts do not overlap with those for processing Nginx services. It is recommended that the number of cores for processing NIC interrupts plus the number of cores for processing Nginx services be equal to the total number of cores that can be used on the server.
To achieve the optimal performance, the ratio of the quantity of cores bound to interrupts to the quantity of cores bound to Nginx applications varies with the hardware configurations, core quantities, and client types.
In the following example, the server and client that are based on Kunpeng 4826 (Hi1822 NIC) are used as the hardware platform, and httpress as the test client. Table 2 lists the optimal core binding ratios for different quantities of valid cores.
Table 2 Optimal core binding ratios in different Nginx scenarios Nginx Scenario
Quantity of Cores Available
Quantity of Cores Bound to the NIC Interrupt
Quantity of Cores Bound to the Nginx Applications
Quantity of Clients
HTTPS persistent connections: 4 cores
4
0
4
1
HTTPS persistent connections: 8 cores
8
2
6
1
HTTPS persistent connections: 48 cores (1P)
48
8
40
2
HTTPS persistent connections: 96 cores (2P)
96
16
80
4
HTTPS short connections: 4 cores
4
0
4
1
HTTPS short connections: 8 cores
8
0
8
1
HTTPS short connections: 48 cores (1P)
48
0
48
2
HTTPS short connections: 96 cores (2P)
96
4
92
2
HTTP persistent connections: 4 cores
4
1
3
1
HTTP persistent connections: 8 cores
8
2
6
1
HTTP persistent connections: 48 cores (1P)
48
12
36
2
HTTP persistent connections: 96 cores (2P)
96
24
72
4
HTTP short connections: 4 cores
4
2
2
1
HTTP short connections: 8 cores
8
4
4
2
HTTP short connections: 48 cores (1P)
48
24
24
4
HTTP short connections: 96 cores (2P)
96
48
48
4
- Press Esc, type :wq!, and press Enter to save the file and exit.