To learn the network performance of your ECS instance, you may typically analyze requests completed per second of the Nginx service (for long and short connections). This topic describes a test plan to obtain the optimal Nginx performance of ECS instances.
Testing tools and versions
In this topic, the Nginx service is deployed on the Server, and the Wrk pressure testing tool is deployed on the Client.
- Nginx: A high-performance, lightweight web server for HTTP services and reverse proxy. This topic uses Nginx 1.18.0 as an example.
- Wrk: A lightweight HTTP benchmarking tool. This topic uses wrk [epoll] Copyright (C) 2012 Will Glozer as an example.
Test metric
Requests/sec: The average number of requests completed per second. The higher this value, the better the Nginx performance.
Test environment
Two ECS instances with the same specifications are used, which serve as the service side (Server) and client side (Client), respectively. The specific configuration is shown in the table below.
Procedure
Step 1: Deploy and start the Nginx service on the Server
- Deploy the Nginx service.
- Execute the following command to create an Nginx deployment file.
- Press i key to enter edit mode, and then enter the following content.
- Press the Esc key to exit edit mode, enter :wq, and then press Enter to save and exit the file.
- Execute the following command to install Nginx.
- Start the Nginx service on the Server.
- Execute the following command to create a run file "nginx_run.sh".
- Press i key to enter edit mode, and then enter the following content.
- Execute the following command to start the Nginx service.
Step 2: Optimize instance configurations for optimal Nginx performance (optional)
Step 3: Deploy Wrk on the Client and create a test script
- Execute the following command to create a Wrk deployment file.
- Press i key to enter edit mode, and then enter the following content.
- Press the Esc key to exit edit mode, enter :wq, and then press Enter to save and exit the file.
- Execute the following command to install Wrk.
- Create the test script wrk_run.sh.
- Execute the following command to create the test script.
- Press i key to enter edit mode, and then enter the following content.
- Press the Esc key to exit edit mode, enter :wq, and then press Enter to save and exit the file.
Step 4: Run the test script on the Client and obtain results
- Obtain the private IP address of the Server, and then execute the following command on the Client to run the test.
- bash wrk_run.sh <serverIP> <threadNums> <connNums>
- serverIP (required): Indicates the private IP address of the Server. To obtain the private IP address, go to the Instances page in the ECS console, and then view it in the "Primary IPv4 address" column.
- threadNums (optional): Indicates the number of threads to be created. Default value: 128.
- connNums (optional): Indicates the number of connections to be created. Default value: 1,024.
- The test results are as follows. Pay attention to the Requests/sec metric, because it indicates the average number of requests completed per second. The higher this value, the better the Nginx performance.
-
- Detailed result descriptions are as follows.
Optimal configuration
Multiple factors can impact Nginx performance, such as parameter configurations of the Nginx service, kernel parameters, and network card queues. To optimize your ECS instance configurations for optimal Nginx performance, refer to the instructions below.
Disable napi_tx
Disabling napi_tx can reduce the number of hardware and software interrupts when the network interface transmits packets. As a result, Nginx performance can be improved.
This feature is enabled by default only when the Linux kernel version is ≥ 5.3. You can execute the uname -r command to check the kernel version, and then disable napi_tx as follows.
Execute the cat /sys/module/virtio_net/parameters/napi_tx command. If N is returned, napi_tx is disabled successfully.
Mitigate contention issues
For large-specification instances, contention issues may occur due to the increased number of CPU cores and thereby impact Nginx performance. These mainly include contention for HTML files and socket contention. Below are solutions for these two types of contention to improve Nginx performance.
Solution 1: Modify the number of Nginx worker processes and enable reuseport
After deploying the Nginx service on the Server, you can enable the Nginx reuseport option to allow multiple sockets to listen on the same port to mitigate contention. Or, specify an appropriate number of Nginx worker processes when HTML files are being accessed to improve Nginx performance. The optimal number of Nginx worker processes varies by instance specification, with details shown below.
To modify the number of Nginx worker processes and enable reuseport, follow these steps:
- Execute the following command to open the /etc/nginx/nginx.conf configuration file.
- vim /etc/nginx/nginx.conf
- Press i to enter the edit mode.
- Modify the number of Nginx worker processes and enable reuseport.
- Modify the value of worker_processes based on the specification.
-
- Add the following content to the end of the configuration file to enable reuseport.
- Press the Esc key to exit edit mode, enter :wq, and then press Enter to save and exit the file.
- Execute the following command to restart the Nginx service and apply the configuration.
- systemctl restart nginx.service
Solution 2: Install irqbalance-ng
You can follow the guide in network interface interrupt binding to install irqbalance-ng, which automatically configures interrupts for physical network interfaces. This enables interrupt load balancing and thereby enhances network performance. Disable sniffer
- Execute the following command to check whether sniffer is enabled.
- If the following output is displayed, the sniffer is not enabled. Then, skip this step.
-
- If the following output is displayed, sniffer is enabled. Proceed to the next step.
-
- Execute the following command to check if the dhclient process is present.
- The output is displayed below, which indicates that the dhclient process is present. Execute the following command to terminate the dhclient process and thus disable the sniffer.
-