Author: Fuyi

Small programs also need stress testing

Mini programs are very important traffic portals in the mobile Internet era. In order to avoid problems such as a white screen and abnormal error reporting during use due to system performance bottlenecks that affect the user experience, the applet needs to do a stress test before the new function is launched to evaluate the system's carrying capacity and configure it based on the stress test results. Limiting. Let the system face the sudden increase in traffic and be as stable as Mount Tai.

3 scenarios where stress testing is required in common small programs

  • Before launching a newly developed system or function, it is necessary to understand its performance level.
  • Perform technical tuning of the system, and compare the performance before and after system expansion through stress testing.
  • Perform performance evaluation of the system before participating in Mini Program platform activities.

How to design the pressure measurement scheme of the applet

According to different stress testing scenarios, stress testing solutions can be simply divided into: single-interface stress testing, hybrid stress testing, performance tuning stress testing, long-term voltage testing, etc. Please choose a different plan according to your needs.

  • Single-interface stress test : Perform separate stress tests on the interfaces involved in core business scenarios to analyze the bottleneck of single-interface links.
  • Hybrid stress test : Perform hybrid stress test for business scenarios to evaluate the comprehensive concurrent processing capability of the system.
  • Performance tuning stress test : Test the impact of application system parameters, JVM parameters, thread pool parameters, etc. on system performance, and obtain best practice parameter settings.
  • Long-term voltage test : maintain a relatively high concurrency for a long time to conduct a stress test to observe the system response. Through 24H * N days of long-term voltage test, the stability of the system is guaranteed, and memory overflow, slow leakage, thread pool, and accidental competition during resource acquisition cause deadlock, queuing, etc.; the length of the long-term voltage test can be determined according to The specific situation is appropriately reduced, for example, the stability stress test time is determined according to the number of occurrences of JVM GC and Full GC.

Best Practices for Stress Testing Mini Programs Using PTS

Different from the stress testing of self-built websites, when stress testing an applet, it is usually necessary to obtain the token information of the platform where the applet is located (such as Alipay and WeChat), and use it within the validity period to properly stress the business interface of the applet. It is recommended that you obtain the token authorized by the platform in the following two ways:

  • (Recommended) Write the API to automatically obtain the Token and refresh the Token within the validity period. During stress testing, you can automatically obtain Tokens by testing the interface through PTS.
  • Before the stress test, record the platform Token in advance and pass it into the applet business interface in the form of parameters. However, please note that the duration of the stress test cannot exceed the validity period of the Token, so as to avoid the failure of the business stress test due to the failure of the Token.

Method 1: Write an interface to obtain Token

Suppose you need to stress test the activity page of the applet on the WeChat platform. You can write an interface to obtain the token information of WeChat, arrange the interface into the stress test scenario, extract the parameters, and pass it to the actual business interface later. The specific operation steps are as follows:

  1. The interface is written locally so that the token information of WeChat can be continuously obtained during the stress test.
  2. Log in to the PTS console [1] and select Create Scenario > Create PTS Scenario in the left navigation bar.
  3. Fill in the scene name, such as "myAPP".
  4. On the Scenario Configuration tab, click the arrow on the right side of the stress test API name column to expand more detailed settings, and fill in the first stress test API, which is the custom interface for obtaining WeChat Token.
  5. Select the Parameter Definition tab. The configuration example is as follows:

 title=

  • Parameter name : access_token
  • Source : Body: JSON
  • Parse expression : access_token
  1. Click + Add Pressure Test API , fill in the second API, the Mini Program activity page interface, and select POST as the request method. The Mini Program activity page interface is the URL of the Mini Program.

 title=

  1. Click the parameter list at the bottom of the Create PTS scene page, and click the copy icon of the parameter name in the pop-up dialog box to copy the parameter.

 title=

  1. Assuming that you need to pass the copied output parameter access_token in the API's Body, click the API's Body Definition tab. Fill in a custom name (eg input_token) in Key, and paste the copied output parameters in Value.

 title=

  1. Click the Pressure Configuration tab, and fill in the information such as the number of concurrent pressure tests and the duration according to actual needs. An example is shown in the following figure.

 title=

illustrate

  • If you need to obtain the logged-in WeChat user information for use by multiple serial links, such as OpenID or Token, please refer to Simulating Login Scenario with Cookies [2] .
  • If there is limited flow information on the information side, such as the frequent login and logout restrictions of the same user, the interface invocation restrictions, etc., you can prepare a serial link with low concurrency and low RPS login information.
  • For more information on pressure configuration, see How to do pressure configuration [3] .
  1. Click Save at the bottom left of the Create PTS Scenario page to remove the stress test to initiate the stress test.

Method 2: Manually record the Token and write it into the business interface

Suppose you need to stress test the activity page of the applet on the WeChat platform. Then, you can obtain the platform tokens in batches before the stress test, or prepare some data locally (if the business allows it), put it in the data file, and use it as a global parameter during the stress test.

Note that the general platform Token has a validity period limit, which needs to be refreshed regularly before it can be used. Therefore, please pay attention to confirming the validity period of the Token when using this method. After this period, the stress test cannot be performed normally.

The specific operation steps are as follows:

1. Create a new .csv file (edit it with Excel and save it in .csv format, or use Apache's commons-csv to generate it), and write the Token information in one column. The example is as follows:

 title=

It means that you can obtain platform tokens in batches through the online environment, or you can construct token data locally if the business allows.

  1. Log in to the PTS console [1] and click Create Scenario > Create PTS Scenario in the left navigation bar.
  2. On the Create PTS scene page, fill in the scene name, such as "myAPP".
  3. On the Scenario Configuration tab, fill in the Mini Program activity page interface.
  4. Click Data Source Management at the bottom of the Create PTS Scenario page, click + Upload File , and upload the locally prepared .csv file. After uploading, fill in the parameter name and click OK .

 title=

  1. Click the drop-down arrow to the right of the +Add stress test API , and select Add Data Configuration .
  2. Click the arrow icon on the right side of the data configuration column to expand more detailed settings, and select the parameter name in the file parameter setting tab. Click the copy icon to copy the parameter.

 title=

  1. Assuming that the copied parameters need to be passed in the API's Body, click the Body Definition tab of the Active Page API. Fill in a custom name (such as token) in Key , and paste the copied out parameters in Value .

 title=

  1. Click the Pressure Configuration tab, and fill in the information such as the number of concurrent pressure tests and the duration according to actual needs. An example is shown in the following figure.

 title=

  1. Click Save at the bottom left of the Create PTS Scenario page to remove the stress test to initiate the stress test.

Advantages of using PTS for small program stress testing

  • PTS's fully self-developed stress measurement engine supports throughput mode and accurately simulates traffic funnel model
  • Supports the initiation of pressure measurement traffic across the country and simulates the distribution of real users
  • Provide problem diagnosis tools, display method stack granularity error information, and accurately locate performance problems
  • Supports client-side proxy recording, greatly reducing the cost of building stress test scripts

At the same time, the new sales method of PTS is coming, and the price of the basic version will drop by 50%! The price of one million concurrent transactions is only 6200! There are also 0.99 trial version for new users and VPC stress test exclusive version, welcome to buy!

 title=

Related Links

[1]PTS console

​​https://pts.console.aliyun.com/?accounttraceid=e03f85e8c48a48239986f1adbd831f5etyot

[2] Use cookies to simulate login scenarios

​​https://help.aliyun.com/document_detail/71027.htm#multiTask1285

[3] How to perform pressure configuration

​​https://help.aliyun.com/document_detail/70480.htm#concept-70480

[4] Alipay Mini Program Stress Test Solution

​​https://opendocs.alipay.com/support/01rb1x

[5] How to initiate a stress test in one minute

​​https://help.aliyun.com/document_detail/70290.html

Click ​​here​​ to learn more about performance testing PTS!


阿里云云原生
1.1k 声望310 粉丝