Stress test Spring Cloud microservices
You can use the microservice stress testing feature to test microservice applications deployed in a VPC. With just a few settings in the PTS console, you can quickly run a microservice stress test. This topic shows you how to stress test a Spring Cloud microservice.
Background
In a typical microservice architecture, services are exposed through a gateway and secured by network isolation. This often means microservices in the cloud are deployed within a secure VPC. However, stress testing applications inside a VPC presents a challenge due to this network isolation. A traditional solution is to set up a testing tool, such as JMeter, within the VPC network. This approach can be time-consuming, requires coding knowledge, and may not be optimized for microservice stress testing.
The PTS microservice stress testing feature solves these challenges. The PTS console lets you quickly configure and run a microservice stress test.
Procedure
- Log on to the PTS console. In the navigation pane on the left, choose performance testing > Create Scenario, and then click Spring Cloud stress test.
- On the Create Microservice Scenario page, enter a Scenario Name, select a Test Application Source, and then select a region and a microservice namespace.
- On the Scenario Configuration tab, click +Add SpringCloud Node to add the required test endpoints to the target API chain.
Scenario configuration
Click the
icon to the right of a serial link to expand it. Then, you can configure its basic information, output parameters, and checkpoints.
Basic configuration
On the Basic configuration tab of the serial link, configure the basic parameters for the test.
| Parameter | Description | Example |
| Application Name | The application that exposes the service. For Spring Boot applications, this is typically the value of spring.application.name. | demo-pts-service-provider |
| Service Name | The name of the service. | demo-service |
| Registry Type | Includes Eureka, Direct Connection, and Nacos. | Direct Connection |
| Endpoint | The IP address of the microservice registry. The format can be http://[ip]:[port] or [ip]:[port].Important For Microservice Engine (MSE) users, the registry address to enter depends on whether a namespace is configured.
| http://172.16.0.0:8080 |
| Request Path | The request path URL. | /demo |
| Request Method | Options include GET, POST, PUT, and DELETE. You must define headers on the Header Definition tab. If you select POST or PUT, you must also specify the request body. | GET |
| Timeout (ms) | The maximum time (in milliseconds) a virtual user waits for a response. The default is 1,000 ms (1 second). For online services, we recommend a timeout of less than 5,000 ms. | 1000 |
Header definition
On the Header Definition tab of the API chain, set key-value pairs. For more information, see Header Definition.
Body definition
On the Body Definition tab of the API chain, set key-value pairs. For more information, see Body Definition.
Output parameters
On the Output parameter settings tab of the serial link, configure the output parameters. For detailed instructions, see API output parameters.
Checkpoints
On the Checkpoint settings tab of the serial link, set checkpoints. For detailed instructions, see Checkpoints (assertions).
Controllers and timers (optional)
You can add controllers and timers as your task requires.
-
On the scene configuration tab, click + Add controller and select a controller.
-
Loop controller: Controls the number of times the test nodes within it are executed.
Select a loop controller and click the
icon to its right to add the test nodes to be executed in the loop and set the number of loops. During a stress test, the test nodes within this loop controller are executed sequentially for the specified number of times. -
Transaction controller: A transaction controller groups all test nodes under it into a single transaction. It has two settings: Generate parent sample and Include duration of timers and pre-post processors in sample time.
-
Generate parent sample:
-
Enabled: The system does not report the individual test results for each node under this transaction controller. Instead, it aggregates and presents them as a single result for the transaction controller in the performance test report.
-
Disabled: The report displays test results for both the transaction controller and each individual node under it.
-
-
Include duration of timers and pre-post processors in sample time: If you enable this option, the average response time of the transaction controller in the performance test report is the sum of the average response times of all test nodes, timers, and pre/post processors. If you disable this option, the average response time includes only the sum of the average response times of the test nodes.
-
-
Once only controller: Nodes under a once only controller execute only once.
-
-
On the scene configuration tab, click + Add timer and select a timer.
-
Constant timer: Adds a fixed delay. This timer pauses execution for the specified duration in milliseconds.
-
Synchronous timer: You can set the Pause duration and the Number of simulated users. This timer holds threads until the specified number of users is reached, and then releases them all at once to create a burst of load. If the number of users does not reach the target within the timeout period, the timer releases the waiting threads.
-
Uniform random timer: This timer introduces a delay that consists of a fixed part and a random part. You can configure the Constant delay offset (the fixed delay) and the Random delay maximum (the maximum random delay). The total delay is the sum of the constant offset and a random value between 0 and the random maximum. Each random value in the range has an equal probability of being chosen.
-
Gaussian random timer: Similar to the uniform random timer, this timer also sets a delay with a Constant delay offset and a Random delay maximum. Use this timer when you need the random portion of the delay to follow a normal (Gaussian) distribution.
-
Constant throughput timer: This timer controls the throughput, ensuring that test nodes execute at a specified rate. You can set the target throughput and the basis for its calculation. The calculation can be based on: this thread only, all active threads, all active threads in current thread group, all active threads (shared), or all active threads in current thread group (shared).
-
Stress configuration
Click the Load Settings tab to configure the load settings.
|
Parameter |
Description |
|
Load Source |
The network type used for the test. Options include public network and Alibaba Cloud VPC private network. For more information, see Stress source (public network and VPC). |
|
Number of concurrent users |
The number of virtual users that initiate requests simultaneously. For example, a value of 100 means 100 virtual users are sending requests concurrently. |
|
Test Duration |
The recommended test duration is at least 2 minutes. The maximum duration is 24 hours by default. |
|
Traffic model |
This setting defines the increment model for the number of concurrent users. When you select a different traffic model, the stress estimation chart on the right side of the page also refreshes.
|
|
Ramp-up period |
The time it takes for all concurrent users to become active, starting from zero. You must configure this setting when the traffic model is set to uniform ramp-up or stepped ramp-up. |
|
Number of steps |
The number of steps to complete the ramp-up. You must configure this setting when the traffic model is set to stepped ramp-up. |
|
Specified IP Addresses |
The number of source IP addresses to use for the test. For more information, see Specify the number of stress IPs. |
|
Custom traffic region |
Simulate user traffic from specific geographical locations by specifying the location of the stress-generating machines. After you enable this feature, you can configure the regional distribution of the stress machines to customize the geographical distribution of your test traffic. For more information, see Customize regional traffic. |
Start the test
In the lower-left corner of the page, click Debug to validate your configuration. For more information, see Debug a scene. Then, click Save and Start and click OK in the confirmation dialog box to start the test.
Next steps
View the performance test report. For more information, see View a multi-protocol performance test report.