Mini programs are important traffic ingresses in the mobile Internet era. To prevent system performance issues that affect the user experience, you must perform stress testing before new features of mini programs are released. This helps ensure system stability when traffic surges.
Common scenarios
To ensure the stable running of a new system or feature, you need to learn about its performance before the new system or feature is released.
After a system is optimized or scaled out, you need to perform stress testing on the system to understand the performance differences before and after the system optimization.
To prevent system crashes caused by traffic surges from affecting the user experience, you need to evaluate system performance before a large volume of traffic is generated. For example, traffic surges may occur when large-scale activities are held.
Advantages
The Performance Testing (PTS) engine developed by Alibaba Cloud supports the Transaction Per Second (TPS) mode and accurately simulates the traffic funnel model.
PTS can initiate traffic requests in all regions across China during stress testing and simulate the real distribution of users.
PTS provides a diagnostic tool to display error messages of method stacks and accurately locate performance issues.
PTS supports client-side proxy recording, which greatly reduces the cost of constructing stress testing scripts.
Procedure
Unlike stress testing on self-built websites, stress testing on mini programs requires the token information of the platform where the mini programs are located, such as Alipay and WeChat. You must use the token information within its validity period to perform stress testing on business API operations of mini programs. We recommend that you use one of the following methods to obtain the token for the platform:
Recommended. Create an API operation to automatically obtain the token and refresh the token within the validity period. Use PTS to perform stress testing on this API operation to automatically obtain the token.
Record the platform token before stress testing and pass the token into the business API operation of the mini program as a parameter. Take note that the duration of stress testing cannot exceed the validity period of the token. Otherwise, stress testing may fail due to invalid tokens.
In this section, the WeChat platform is used as an example to describe how to perform stress testing on mini programs of a platform.
Method 1: Create an API operation to automatically obtain the token
If you want to perform stress testing on an activity page of a mini program on the WeChat platform, you can create an API operation that obtains the token information of WeChat. Then, orchestrate the API operation into the stress testing scenario and configure an output parameter that passes the token. This way, the token can be passed to subsequent business API operations.
You must create an API operation in an on-premises environment. This way, the API operation can continuously obtain the token information of WeChat during stress testing.
Log on to the PTS console, choose , and then click PTS.
Enter a scenario name, such as
myAPP
. Then, click the drop-down arrow to the right of the API operation to be tested on the Scenario Settings tab. Detailed settings for the API operation are displayed. In the section that appears, enter the information about the custom API operation that is used to obtain WeChat tokens. This is the first API operation.On the Output Parameter Definition tab, configure the following parameters:
Output Parameter Name: Enter access_token.
Source: Select Body:JSON.
Parsing Expression: Enter access_token.
Click Add API and enter the information about the API operation of the activity page of the mini program. On the Basic Request Information tab, set the Request Method parameter to POST. This is the second API operation.
In the lower part of the page, click Parameters. In the Parameters panel, click Session Parameters. On the Session Parameters tab, click the Copy icon of the output parameter to copy the parameter.
If you want to add the copied output parameter access_token to the body of the API operation, click the Body Definition tab of the API operation. Then, enter a custom name in the Key field, such as input_token, and paste the copied output parameter in the Value field.
In the Stress Mode Configuration section of the page, configure the parameters, such as Max VUs and Total Test Duration, based on your business requirements.
NoteTo obtain the information of users who have logged on to WeChat for a session that contains multiple API operations, see Use cookies to simulate logons. The logon information includes the OpenID and token.
For more information about how to configure the stress testing model, see Configure the stress testing model and level.
In the lower part of the Edit Scenario page, click Save and Start. In the Note dialog box, set the Execution Cycle parameter to Execute Now, select the check box for The test is permitted and complies with the applicable laws and regulations, and then click Start Test.
Method 2: Manually record the tokens and add the tokens to the business API operation
If you want to perform stress testing on an activity page of a mini program on the WeChat platform, you can obtain the platform tokens at a time or construct tokens in your on-premises environment (if allowed) before stress testing, save the obtained or constructed tokens in a file, and use the tokens as a global parameter during stress testing.
In most cases, platform tokens have a validity period, and you need to periodically refresh the tokens and use the latest one. Therefore, if you use this method, you must verify the validity period of the tokens. If the tokens expire, stress testing will fail.
Create a file named
token.csv
and enter the token information in a column of the file. You can create an Excel file and save it as a CSV file, or use Apache Commons CSV to generate a CSV file. Sample file content:token T7MeDnBIMKRJdgUB8RNQixyhUPJPaJEG cqKscgeNWFPkkkaR4dBfcD4A2pD1CYFK eh3lbjmsjd9jh65xSwvBWvDtmky25CK9
NoteYou can obtain the platform tokens from the online environment at a time, or construct tokens in your on-premises environment if your business allows such operations.
Log on to the PTS console, choose , and then click PTS.
Enter a scenario name, such as
myAPP
. On the Scenario Settings tab, enter the information about the API operation of the mini program activity page.Click Data Sources in the lower part of the PTS scenario page. On the Files tab of the Data Sources panel, click + Upload File and upload the on-premises file
token.csv
. After the file is uploaded, select Use First Line as Parameter Name for the file. This way, you do not need to manually specify the parameter name. The first line is skipped when PTS reads the parameter data in the file.On the right side of the name of the API operation to be tested, click the icon and select Add Parameter.
Click the drop-down arrow to the right of Parameter to show more detailed settings. On the Data Source Parameters tab, specify the value of the Parameter Name parameter. Click the Copy icon to copy the parameter.
If you want to add the copied parameter to the body of the API operation of the activity page, click the Body Definition tab of the API operation. Then, enter a custom name in the Key field, such as token, and paste the copied output parameter in the Value field.
In the Stress Mode Configuration section of the page, configure the parameters, such as Max VUs and Total Test Duration, based on your business requirements.
In the lower part of the PTS Scenario page, click Save and Start. In the Note dialog box, set the Execution Cycle parameter to Execute Now, select the check box for The test is permitted and complies with the applicable laws and regulations, and then click Start.