Author: Ling Ran

In actual business scenarios, stress testing is an indispensable part, whether it is the evaluation of performance bottlenecks such as servers, databases, and networks, or the guarantee of business continuity for important traffic nodes such as browsing, ordering, and payment. Or estimate the overall business stability of moving to the cloud. These require performance stress testing to help you build a complete understanding of the system and business. According to Google's statistics, if a website is slow to open every 500 milliseconds, user traffic will drop by 20%. According to Amazon statistics, for every 100 milliseconds of slowdown, the transaction volume drops by 1%. These events and statistics sounded the alarm for everyone, and also objectively demonstrated the importance of performance stress testing for enterprise applications.

The stress test is to initiate a request to the business system by simulating user behavior, measure the carrying capacity of the system, and conduct a comprehensive physical examination of the system. After the stress test, the system bottleneck can be optimized according to the stress test performance to prevent online failures.

Common pressure measurement software JMeter and PTS in the industry

At present, JMeter is the most widely used open source software in the field of performance stress measurement.

For simple scenarios and low test concurrency requirements, JMeter local testing can meet the requirements. However, with the increase of Internet users, the demand for the system to carry more concurrency is increasing day by day, and the pressure capacity of a single JMeter press has a certain upper limit, so it is necessary to use multiple presses to improve the pressure capacity of JMeter. , which requires the use of JMeter's distributed pressure function.

However, there are many pre-preparations for distributed stress testing in JMeter, and the following points need to be paid attention to:

  • The presser's firewall is closed or the correct port is open. SSL is set up or disabled for RMI.
  • All presses are on the same subnet. If you use a 192.xxx or 10.xxx IP address, the server is on the same subnet.
  • Use the same version of JMeter and Java on all presses.
  • All presses have already copied the sliced ​​CSV data files, dependency jars, etc.
  • The collection of monitoring data is configured.

It can be seen that JMeter's distributed pressure measurement needs to coordinate various resources by itself, and the pre-preparation is more troublesome, and the pressure measurement efficiency is low for the personnel who implement the pressure measurement.

PTS is a performance testing tool developed by Alibaba Cloud. At first, it was mainly used to simulate the traffic peak of Double Eleven. Now it has gone through ten years. It can provide millions of concurrent, tens of millions of TPS traffic initiation capabilities, and is fully compatible with JMeter, which can naturally make up for the shortcomings of JMeter in performance stress testing. It is a good choice for users who cannot get around clustering issues with JMerer.

The JMeter pressure measurement of PTS greatly simplifies the JMeter distributed pressure measurement process, and also reduces the maintenance cost of the pressure press during the pressure measurement process. Using PTS's JMeter pressure test, the user only needs to configure the number of machines to be used in the console, and the user does not need to prepare multiple pressure machines with the same Java and JMeter versions installed in advance. At the same time, there is no need for the user to divide the CSV parameter file according to the number of pressure machines; after the pressure test, PTS will summarize the monitoring data and generate a detailed pressure test report for users to consult.

Compared with executing JMeter scripts directly on the command line, PTS is more convenient to use, can provide massive pressure capabilities on demand, and can provide concise and intuitive monitoring and reporting.


How to initiate a JMeter stress test for PTS

Like the core steps of all stress testing, JMeter stress testing using PTS mainly focuses on the three steps of creating scenarios, stress testing scenarios, and viewing reports.

1. Create a scenario: The JMeter stress test of PTS takes the scenario as the core, and the stress test object is a scenario. The scenario includes JMeter (native) scripts, JMeter dependencies (a series of dependent jar packages and a series of properties configuration), and some stress tests Configuration (PTS pressure measurement configuration, such as public network/VPC pressure measurement, concurrency, number of engines, pressure measurement duration, etc.).

2. Stress test scenario: The operation of the scenario is divided into two aspects, one is the addition, deletion, modification and inspection of the scenario configuration, and the other is the stress test and debugging of the scenario.

3. Generate a report: Each time a stress test is performed on a scene, a stress test task will be generated, and a report will be generated at the same time, which includes the key indicators of the stress test, such as TPS, RT, success rate, etc., which can assist users to troubleshoot system performance bottlenecks. In addition, PTS saves reports for 30 days by default, historical reports can be viewed at any time, and reports can be exported in PDF format.

In the field of pressure measurement, with the increasingly diversified demands for pressure measurement, more users hope to inherit the pressure measurement capabilities on the cloud to their own systems, or to arrange a custom pressure measurement platform according to their own business systems, so as to realize automatic customization Chemical pressure measurement requirements.

Therefore, in order to facilitate users to schedule PTS's millions of concurrent capabilities, PTS has opened JMeter's OpenAPI, which provides the following core functions of stress testing: editing scenarios, debugging scenarios, stress testing scenarios, viewing runtime data, and viewing reports.

By integrating OpenAPI, customers can more easily realize the capability of PTS millions of concurrent stress tests in their own business scenarios, and realize various operations such as adding, deleting, modifying, and checking scenarios. During the process, stop the pressure measurement at any time. In the stress test report generated at the same time, in addition to JMeter's native logs, there are also aggregated data of PTS's success rate, TPS, and RT indicators for a certain sampler. In addition, you can also view the report list, JMeter native logs, and the aggregated data of the JMeter sampler pressure measurement indicators by PTS.

So what are you waiting for? Come, try to use JMeter's OpenAPI in PTS to write a stress testing platform with millions of concurrent stress testing capabilities for you!

appendix:

Specific steps are as follows

Introduce pom dependencies

<!--创建PTS场景需要的实体类,如果只使用JMeter压测则不需要引入-->
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>pts-api-entity</artifactId>
  <version>1.0.1</version>
</dependency>
<!--PTS Java SDK依赖。-->
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>pts20201020</artifactId>
  <version>1.8.10</version>
</dependency>
<!--阿里云核心库。-->
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>4.5.2</version>
</dependency>

\

Copy the following code

import com.aliyun.pts20201020.Client;
import com.aliyun.pts20201020.models.*;
import com.aliyun.teaopenapi.models.Config;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class StartingDemo {

    public static void main(String[] args) throws Exception {
        Client client = getClient();
        // 创建场景
        String sceneId = createScene(client);
        // 启动场景
        String reportId = startTesting(client, sceneId);
        // 最多等待次数
        int count = 0;
        // 查询是否已生成报告
        while (!hasReport(client, reportId) && count++ < 20) {
            // 若报告还未生成,则等待(30s)一段时间再查询
            // 根据压测时间酌情等待
            Thread.sleep(30 * 1000);
        }
        // 查看报告
        getJMeterReport(client, reportId);
    }

    private static boolean hasReport(Client client, String reportId) throws Exception {
        ListJMeterReportsRequest request = new ListJMeterReportsRequest();
        // 分页设置
        request.setPageNumber(1);
        request.setPageSize(1);
        // 查询条件设置
        request.setReportId(reportId);
        ListJMeterReportsResponse response = client.listJMeterReports(request);
        return response.getBody().getReports().size() > 0;
    }

    private static void getJMeterReport(Client client, String reportId) throws Exception {
        // 查看机器日志
        GetJMeterLogsResponse getJMeterLogsResponse = getJMeterLogs(client, reportId);
        List<Map<String, ?>> logs = getJMeterLogsResponse.getBody().getLogs();
        // 查看采样器聚合数据
        GetJMeterSampleMetricsResponse getJMeterSampleMetrics = getJMeterSampleMetrics(client, reportId);
        List<String> sampleMetricList = getJMeterSampleMetrics.getBody().getSampleMetricList();
        // 查看采样日志
        GetJMeterSamplingLogsResponse getJMeterSamplingLogs = getJMeterSamplingLogs(client, reportId);
        List<String> sampleResults = getJMeterSamplingLogs.getBody().getSampleResults();
    }

    private static GetJMeterSamplingLogsResponse getJMeterSamplingLogs(Client client, String reportId) throws Exception {
        GetJMeterSamplingLogsRequest request = new GetJMeterSamplingLogsRequest();
        // 分页设置
        request.setPageNumber(1);
        request.setPageSize(10);
        // 条件设置
        request.setReportId(reportId);
        GetJMeterSamplingLogsResponse response = client.getJMeterSamplingLogs(request);
        return response;
    }

    private static GetJMeterSampleMetricsResponse getJMeterSampleMetrics(Client client, String reportId) throws Exception {
        GetJMeterSampleMetricsRequest request = new GetJMeterSampleMetricsRequest();
        // 设置报告id
        request.setReportId(reportId);
        GetJMeterSampleMetricsResponse response = client.getJMeterSampleMetrics(request);
        return response;
    }

    private static GetJMeterLogsResponse getJMeterLogs(Client client, String reportId) throws Exception {
        GetJMeterLogsRequest request = new GetJMeterLogsRequest();
        // 分页设置
        request.setPageNumber(1);
        request.setPageSize(10);
        // 查询的压测引擎索引
        request.setReportId(reportId);
        GetJMeterLogsResponse response = client.getJMeterLogs(request);
        return response;
    }

    private static String startTesting(Client client, String sceneId) throws Exception {
        StartTestingJMeterSceneResponse startTestingSceneResponse = startTestingScene(client, sceneId);
        String reportId = startTestingSceneResponse.getBody().getReportId();
        return reportId;
    }

    private static StartTestingJMeterSceneResponse startTestingScene(Client client, String sceneId) throws Exception {
        StartTestingJMeterSceneRequest request = new StartTestingJMeterSceneRequest();
        request.setSceneId(sceneId);
        StartTestingJMeterSceneResponse response = client.startTestingJMeterScene(request);
        return response;
    }

    private static String createScene(Client client) throws Exception {
        SaveOpenJMeterSceneRequest request = new SaveOpenJMeterSceneRequest();
        // 定义场景
        SaveOpenJMeterSceneRequest.SaveOpenJMeterSceneRequestOpenJMeterScene scene = new SaveOpenJMeterSceneRequest.SaveOpenJMeterSceneRequestOpenJMeterScene();
        // 设置场景名
        scene.setSceneName("test");
        // 设置文件列表,包括JMeter脚本、JMeter压测依赖jar包、配置额度数据文件等
        List<SaveOpenJMeterSceneRequest.SaveOpenJMeterSceneRequestOpenJMeterSceneFileList> fileList = new ArrayList<SaveOpenJMeterSceneRequest.SaveOpenJMeterSceneRequestOpenJMeterSceneFileList>();
        // 设置文件的属性 需要设置文件的名称和文件公网可访问的oss地址
        SaveOpenJMeterSceneRequest.SaveOpenJMeterSceneRequestOpenJMeterSceneFileList testFile = new SaveOpenJMeterSceneRequest.SaveOpenJMeterSceneRequestOpenJMeterSceneFileList();
        testFile.setFileName("baidu.jmx");
        testFile.setFileOssAddress("https://pts-openapi-test.oss-cn-shanghai.aliyuncs.com/baidu.jmx");
        fileList.add(testFile);
        scene.setFileList(fileList);
        // 设置场景并发,可设置为100万
        scene.setConcurrency(1000000);
        // 设置引擎数量 说明:一台引擎最多能发500并发,最少1并发所以此处能设置的引擎数为[2,1000],另外引擎数量越多消耗vum越快
        scene.setAgentCount(2000);
        // 设置压测持续时间 60s
        scene.setDuration(60);
        // 设置测试文件的名称,这个文件需包括在文件列表中
        scene.setTestFile("baidu.jmx");
        request.setOpenJMeterScene(scene);
        SaveOpenJMeterSceneResponse response = client.saveOpenJMeterScene(request);
        return response.getBody().getSceneId();
    }

    private static Client getClient() throws Exception {
        // 填写自己的AK/SK
        String accessKeyId = "ak";
        String accessKeySecret = "sk";
        Config config = new Config();
        config.setAccessKeyId(accessKeyId);
        config.setAccessKeySecret(accessKeySecret);
        Client client = new Client(config);
        return client;
    }
}

Fill in your own ak/sk

Fill in the correct ak/sk in the getClient of the above code

Click to start

Click the main method to start

Click here , go PTS official website for more details!


阿里云云原生
1k 声望302 粉丝