Methods for stress testing CLB
Classic Load Balancer (CLB) supports both Layer 4 and Layer 7 load balancing. To stress test a CLB instance for your business, refer to this topic for guidance.
Stress testing methods
When you perform a stress test, use the following configurations:
-
Use short-lived connections to test the forwarding capability of CLB.
In addition to testing features such as session persistence and balancing, a stress test primarily verifies the forwarding capability. Short-lived connections are suitable for testing the processing capacity of CLB and backend servers. When you use short-lived connections for testing, be aware of potential client port shortages.
-
Use persistent connections to test the throughput of CLB. This is useful for testing bandwidth limits or special business scenarios.
Set a short timeout period for the stress testing tool, such as 5 seconds. A long timeout period increases the average response time in the test results. This makes it difficult to determine whether the stress level has been reached. A short timeout period affects the success rate in the test results. This makes it easy to quickly determine the stress level.
-
Provide a static webpage on the backend server for stress testing. This avoids performance loss caused by application logic.
-
During the stress test, configure the listener as follows:
-
Disable session persistence. Otherwise, the load may be concentrated on a few backend servers.
-
You can disable the health check feature to reduce access requests to backend servers.
-
A Performance Testing Service (PTS) specification that supports 5,000 concurrent connections can provide five or more public IP addresses.
-
Recommended stress test tools
-
You can use Alibaba Cloud PTS. It lets you set a high level of concurrency. PTS allocates public IP addresses from various regions, which ensures that the load source is distributed. You can also integrate Cloud Monitor with PTS to view all end-to-end performance data in real time.
-
Do not use Apache ab as a stress test tool. In high-concurrency scenarios, Apache ab experiences stepped pauses at 3, 6, and 9 seconds. Apache ab determines request success by checking the content length. If a CLB instance has multiple backend servers attached, the returned content lengths may be inconsistent, which causes inaccurate test results.
Example of a simple stress test using PTS
Create a CLB instance, add two ECS instances as backend servers, and create a TCP listener and an HTTP listener. Set the backend port for both listeners to 80.
The ECS instances are configured with 2 CPU cores, 2 GiB of memory, and the CentOS 7.9 64-bit operating system. Log on to each of the two ECS instances and perform the following steps to install a web service and complete the stress test. For more information about how to log on to an ECS instance, see ECS Remote Connection User Guide.
-
Run the following command to install Apache Web Server to provide web services.
sudo yum install -y httpd -
Run the following command to initialize the default index page, index.html.
echo "testvm" | sudo tee /var/www/html/index.html -
Run the following command to start the HTTP service.
sudo systemctl start httpd -
Run one of the following commands to access port 80 and confirm that the web service is active.
curl http://localhostor
curl http://127.0.0.1:80 -
Create a test scenario in PTS and start the stress test. For more information, see Start a stress test in one minute.
Possible causes of low performance in stress tests
If you find that the stress test performance is low, the cause might be one of the following:
-
Insufficient client ports
During a stress test, insufficient client ports can cause connection establishment to fail. By default, CLB removes the timestamp property of TCP connections. This prevents the tw_reuse feature of the Linux protocol stack (reusing connections in the TIME_WAIT state) from working. The resulting connection buildup in the TIME_WAIT state leads to insufficient client ports.
Solution: On the client, use persistent connections instead of short-lived connections. You can use RST messages to disconnect by setting the SO_LINGER socket property.
-
Full accept queue on backend servers
If the accept queue on a backend server is full, the server does not reply with SYN-ACK messages, and the client times out.
Solution: The default value of net.core.somaxconn is 128. You can run the
sysctl -w net.core.somaxconn=1024command to change the value, and then restart the application on the backend server. -
Application dependencies on backend servers become a bottleneck
After requests pass through the load balancer to the backend servers, the load on the backend servers themselves may be normal. However, the applications on all backend servers depend on other applications, such as a database. If the database becomes a bottleneck, performance also decreases.
Solution: As needed, you can clean up unnecessary applications on the backend servers.
-
Abnormal health check status of backend servers
During a stress test, it is easy to overlook the health check status of backend servers. If a backend server fails a health check, or if the health check status frequently changes from Normal to abnormal and back again, it can also lead to low performance on the stress test.
Solution: You can disable the health check feature to reduce health check requests to the backend servers.