The microservice stress testing feature helps you test microservice applications built in a Virtual Private Cloud (VPC). By configuring settings in the Performance Testing Service (PTS) console, you can quickly run stress tests on your microservices. This topic describes how to stress test gRPC microservices.
Background information
A classic microservices model exposes each service through a gateway and uses network isolation to ensure security. For this reason, cloud microservices are typically built in a secure VPC network. Stress testing these applications can be difficult because of network isolation. A common solution is to set up a testing tool, such as JMeter, in the VPC. However, setting up JMeter is time-consuming, requires coding knowledge, and does not fully support microservice stress testing. The microservice stress testing feature in PTS solves these problems. You can quickly stress test your microservices using simple configurations in the PTS console.
Go to the feature page
Log on to the PTS console, choose , and then click gRPC.
On the Create gRPC Scenario page, enter a Scenario Name and click Upload proto file to upload the relevant proto files.
NoteIf you upload a file with the same name, it overwrites the previous file. To compare files, you can retrieve the MD5 hash from the Actions column for the file and compare it with the MD5 hash of your local file to confirm whether the file has changed.
On the Scenario Configuration tab, click + Add gRPC Request Node to add the required test nodes for the target business session.
Configure a scenario
Click the
icon on the right of a business session to expand the business session and configure the basic information, output parameters, and check points.
Parameter | Description | Example |
Service Endpoint | The IP address of the gRPC service. | 127.0.0.1 |
Service Port | The port number of the gRPC service. | 50051 |
Request Timeout | The maximum time in milliseconds that the stress testing client waits for a response from the server. | 5000 |
SSL/TLS | Specifies whether to establish a secure connection. | Off |
Method Name | The full name of the gRPC method. Note The format is | package.service/method |
Metadata | Similar to an HTTP header. The format is | a:1,b:2 Note Separate multiple metadata entries with commas (,). |
JSON-formatted Request | Describes the message in the proto file in JSON format. | |
Configure output parameters
On the Output Parameter Definition tab of a session, configure output parameters for the session. For more information, see Output parameters.
Configure check points
On the Check Point (Assertion) tab of a session, configure check points for the session. For more information, see Checkpoints (assertions).
(Optional) Controllers and timers
You can add controllers and timers based on the requirements of different stress testing scenarios.
On the Scenario Settings tab, click Add Controller to select the required controller.
Loop controller: controls the number of times that a test node is executed in a loop.
Select a loop controller and click the
icon next to the controller. Then, select the node to be executed in a loop and specify the number of loops. During stress testing, the specified test node in the loop controller is sequentially executed for the specified number of times. Transaction controller: All test nodes in the transaction controller are counted as one transaction. The Generate parent sample and Include duration of timer and pre-post processors in the sample switches are displayed.
Generate parent sample:
If this switch is turned on, the stress testing results of each node in the transaction controller are not independently recorded in a stress testing report, but are aggregated as the results of the transaction controller.
If this switch is turned off, the transaction controller and the stress testing results of test nodes in the controller are displayed in the report.
Include duration of timer and pre-post processors in the sample: If this switch is turn on, the average response time of the transaction controller in the stress test report is the sum of the average response times of all test nodes, timers, and pre- and post- processors. If this switch is turn off, the average response time of the transaction controller is only the sum of the average response times of all test nodes.
Only once controller: The nodes that are added to the controller are executed only once.
On the Scenario Settings tab, click Add Timer to select the required timer.
Constant timer: specifies the pause duration, which indicates the pause duration during stress testing. Unit: milliseconds.
Synchronous timer: specifies the values of Timeout and Number of Simulated Users, which indicates that the stress testing is triggered after a specific number of users is reached within a specified time range. However, if the specific number of users is not reached within the specified time range, the testing is triggered without continuous waiting.
Unified random timer: specifies the pause duration. You can configure Constant Delay Offset and Random Delay. The Constant Delay Offset indicates a fixed pause time, and the Random Delay indicates the maximum random pause time. The pause duration of the unified random timer is the sum of the fixed pause time specified by Constant Delay Offset and the random value within the time range specified by Random Delay. Each random value has equal occurrence probability.
Gaussian timer: specifies the pause duration. The Gaussian timer is similar to the unified random timer. You can configure Constant Delay Offset and Random Delay. If the random pause time is required to conform to the normal distribution, the Gaussian timer can be used.
Fixed throughput timer: specifies the throughput so that test nodes are executed based on the throughput. You can configure conditions and specify the corresponding throughput. The conditions that you can configure include Only the current thread, All active threads, Active threads in the current link, Globally active thread, and Globally active threads in the current link.
Create a PTS scenario
Parameter | Description |
Source of Stress |
|
Stress Mode |
|
Auto Incremental Mode |
|
Max VUs | The Max VUs of the whole scenario in virtual user mode. |
Increment Percentage | In tiered increment mode, you must specify the increment percentage. |
Single Load Level Duration | In tiered increment mode, you must set the Single Load Level Duration to at least 1 minute to ensure that business issues can be found within the Single Load Level Duration. |
Total Test Duration | If the stress testing duration is incremented, the duration is greater than or equal to the value that is calculated by using the following formula: Single Load Level Duration/Incremental magnitude × 1.1 (rounded up). However, the duration cannot exceed 24 hours. |
Number of Specified IP Addresses | The number of IP addresses that apply stress. For more information, see Specify the number of IP addresses applying stress. |
Region-specific Traffic | Specifies whether to set the regions in which stress testers are located. You can turn on this switch to simulate the local user traffic. After you turn on this switch, you can configure the region distribution of stress testers. This implements the customization of the region distribution of stress traffic. For more information, see Custom traffic. |
Start a stress testing task
Click Save and Start. On the Note page, select Execute Now and The test is permitted and complies with the applicable laws and regulations. and then click Start.
To debug a scenario, click Debug. For more information, see Debug scenarios.
Analyze stress testing results
After the test completes, PTS automatically collects the stress testing data and generates a stress testing report. The report includes the following sections:
Scenario metrics
Business details
Monitoring details
API sampling logs
For details, see View PTS stress testing reports.
Scenario example
This section uses a specific proto file as an example to describe how to create a gRPC stress testing scenario.
Upload the proto file that defines the gRPC service and methods. Assume that the method to be tested is CreateShelf. The proto file that defines this method is as follows.
syntax = "proto3"; package bookstore; service Bookstore { rpc ListShelves (google.protobuf.Empty) returns (ListShelvesResponse) {} rpc CreateShelf (CreateShelfRequest) returns (Shelf) {} } message ListShelvesResponse { repeated Shelf shelves = 1; } message CreateShelfRequest { Shelf shelf = 1; }On the Create gRPC Scenario page, click Upload proto file to upload the corresponding proto file.
After you complete the other gRPC scenario configurations in the PTS console, click Save and Run Test.
Method Name: bookstore.Bookstore/CreateShelf.
NoteFrom the proto file, the package name is bookstore, the service name is Bookstore, and the method name is CreateShelf. Therefore, enter bookstore.Bookstore/CreateShelf in the Method Name field.
JSON-formatted Request:
{ "shelf": { "id": 1, "theme": "hello" } }The preceding request code is used because the parameter passed to CreateShelf is CreateShelfRequest, which contains the custom field shelf:
syntax = "proto3"; package bookstore; message Shelf { int64 id = 1; string theme = 2; }