Jmetersphere performance stress test execution process

 (1) First, at the controller layer, receive request parameters through RunTestPlanRequest

@PostMapping("/run")
 public String run(@RequestBody RunTestPlanRequest request)

(2) Perform specific logical processing in run in PerformanceTestService,

  First, obtain the test case information stored in the library based on the ID in the request (empty judgment and running status judgment)

final LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(request.getId());
        if (request.getUserId() != null) {
            loadTest.setUserId(request.getUserId());
        }
        if (loadTest == null) {
            MSException.throwException(Translator.get("run_load_test_not_found") + request.getId());
        }
  • Then, based on the resource pool id in the found use case information, determine whether the resource pool with this id exists and the status is valid.
String testResourcePoolId = loadTest.getTestResourcePoolId();
        TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(testResourcePoolId);
        if (testResourcePool == null) {
            MSException.throwException(Translator.get("test_resource_pool_not_exists"));
        }
        if (ResourceStatusEnum.INVALID.name().equals(testResourcePool.getStatus())) {
            MSException.throwException(Translator.get("test_resource_pool_invalid"));
        }
  •   And check whether kafka is accessible
 String bootstrapServers = kafkaProperties.getBootstrapServers();
        String[] servers = StringUtils.split(bootstrapServers, ",");
        try {
            for (String s : servers) {
                String[] ipAndPort = s.split(":");
                //1,建立tcp
                String ip = ipAndPort[0];
                int port = Integer.parseInt(ipAndPort[1]);
                Socket soc = new Socket();
                soc.connect(new InetSocketAddress(ip, port), 1000); // 1s timeout
                //2.输入内容
                String content = "1010";
                byte[] bs = content.getBytes();
                OutputStream os = soc.getOutputStream();
                os.write(bs);
                //3.关闭
                soc.close();

 Then instantiate different Engines according to different resource pool types, such as node node type, new DockerTestEngine(loadTest); if it is k8s type, (Engine) ConstructorUtils.invokeConstructor(kubernetesTestEngineClass,loadTest); if the node type is instantiated, mainly Do two tasks, one is initialization work, such as threadNum, JMETER_IMAGE, HEAP, and the other is to obtain RestTemplate from the container for subsequent requests.

final ResourcePoolTypeEnum type = ResourcePoolTypeEnum.valueOf(resourcePool.getType());
 
        if (type == ResourcePoolTypeEnum.NODE) {
            return new DockerTestEngine(loadTest);
        }
        if (type == ResourcePoolTypeEnum.K8S) {
            try {
                return (Engine) ConstructorUtils.invokeConstructor(kubernetesTestEngineClass, loadTest);
  • Through startEngine, start executing the use case. First, set the basic information such as the test report start time, and then call the start method in the engine to start execution. The start processing is divided into:

  Determine whether the currently required concurrent threads are less than the number of idle threads

int totalThreadNum = resourceList.stream()
                .filter(r -> ResourceStatusEnum.VALID.name().equals(r.getStatus()))
                .map(r -> JSON.parseObject(r.getConfiguration(), NodeDTO.class).getMaxConcurrency())
                .reduce(Integer::sum)
                .orElse(0);  //获取所有有效资源池的最大并发数,并累加
        if (threadNum > totalThreadNum - runningSumThreadNum) {
            MSException.throwException(Translator.get("max_thread_insufficient"));
        }

  Calculate the ratio of the maximum number of concurrencies in each resource pool to the total number of concurrencies

Object[] resourceRatios = resourceList.stream()
                .filter(r -> ResourceStatusEnum.VALID.name().equals(r.getStatus()))
                .map(r -> JSON.parseObject(r.getConfiguration(), NodeDTO.class).getMaxConcurrency())
                .map(r -> r * 1.0 / totalThreadNum)
                .map(r -> String.format("%.2f", r))
                .toArray();// 各个资源池最大并发数占总的并发数比例

Start using the resource pool for testing, such as preparing the environment parameters needed to start the jmeter container, such as image, test ID, report ID, topic, etc., and then send a start container request to the node controller through RestTemplate and pass the corresponding environment parameters. node

The controller creates a jmeter container after receiving the request. The jmeter container will automatically download jmx from the metis platform according to the corresponding environment parameters, thus starting the stress test.

summary:

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

Insert image description here

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you!   

Guess you like

Origin blog.csdn.net/qq_48811377/article/details/133274014