WO2019178967A1 - Jmeter-based stress testing method and apparatus, and device and storage medium - Google Patents

Jmeter-based stress testing method and apparatus, and device and storage medium Download PDF

Info

Publication number
WO2019178967A1
WO2019178967A1 PCT/CN2018/092636 CN2018092636W WO2019178967A1 WO 2019178967 A1 WO2019178967 A1 WO 2019178967A1 CN 2018092636 W CN2018092636 W CN 2018092636W WO 2019178967 A1 WO2019178967 A1 WO 2019178967A1
Authority
WO
WIPO (PCT)
Prior art keywords
target
custom function
stress test
function
original data
Prior art date
Application number
PCT/CN2018/092636
Other languages
French (fr)
Chinese (zh)
Inventor
蔡良
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2019178967A1 publication Critical patent/WO2019178967A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Definitions

  • the present application relates to the field of software testing, and in particular, to a Jmeter-based stress testing method, apparatus, device, and storage medium.
  • Jmeter is one of the more highly recommended stress testing tools. Jmeter can be used to simulate large loads on servers, networks, or objects, testing their strength from different stress classes to analyze overall performance. When using Jmeter for stress testing, it is usually necessary to write a program for auxiliary testing.
  • the main programming methods are BeanShell and JSR223 scripts (Groovy and Javascript). However, no matter how it is programmed, there is often a system crash in stress testing. Traditionally, it is believed that due to memory leaks in BeanShell's Interpreter, conventional methods cannot support system crashes caused by prolonged stress tests.
  • the embodiment of the present application provides a JMET-based stress testing method, apparatus, device, and storage medium to solve the problem that the terminal/system throughput rate is not high during the stress testing process.
  • an embodiment of the present application provides a JMET-based stress testing method, including:
  • the target stress test request including at least one original data identifier
  • the embodiment of the present application provides a Jmeter-based pressure testing device, including:
  • a target stress test request obtaining module configured to acquire a target stress test request, where the target stress test request includes at least one original data identifier
  • a target custom function obtaining module configured to acquire a corresponding target custom function based on at least one of the original data identifiers, wherein the target custom function is a function that is not encapsulated by a class;
  • a target custom function encapsulation module configured to encapsulate the target custom function into a BeanShell script file
  • An initialization module configured to initialize the BeanShell script file
  • the stress test module is used to invoke the target custom function encapsulated in the BeanShell script file for stress testing.
  • an embodiment of the present application provides a computer device, including a memory, a processor, and computer readable instructions stored in the memory and executable on the processor, where the processor executes the computer The following steps are implemented when reading the instruction:
  • the target stress test request including at least one original data identifier
  • the embodiment of the present application provides one or more non-volatile readable storage media storing computer readable instructions, when the computer readable instructions are executed by one or more processors, such that the one or Multiple processors perform the following steps:
  • the target stress test request including at least one original data identifier
  • Embodiment 1 is a flow chart of a Jmeter-based stress testing method in Embodiment 1 of the present application;
  • step S20 of FIG. 1 is a flow chart of a specific embodiment of step S20 of FIG. 1;
  • FIG. 3 is a flow chart of a specific embodiment of step S30 of Figure 1;
  • step S31 in FIG. 3 is a flow chart of a specific embodiment of step S31 in FIG. 3;
  • FIG. 5 is a flow chart of a specific embodiment of step S50 of Figure 1;
  • FIG. 6 is a schematic diagram of a Jmeter-based pressure testing device in Embodiment 2 of the present application.
  • Figure 7 is a schematic diagram of a computer device in Embodiment 4 of the present application.
  • Jmeter is a Java-based stress testing tool developed by the Apache organization for stress testing software.
  • Jmeter can be used to test static and dynamic resources such as static files, Java servlets, CGI scripts, Java objects, databases or FTP servers.
  • Jmeter can be used to simulate large loads on servers, networks, or objects, testing their strength from different stress classes to analyze overall performance.
  • Fig. 1 shows a flow chart of a Jmeter-based stress test method in this embodiment.
  • the Jmeter-based stress test method can be applied to various terminals or systems to solve the problem that the terminal/system throughput rate is not high during the stress test.
  • the Jmeter-based stress test method includes the following steps:
  • S10 Acquire a target stress test request, where the target stress test request includes at least one original data identifier.
  • the stress test is a test process that simulates the software and hardware environment of the actual application and the system load of the user's use process, and runs the test software for a long time or a large load to test the performance, reliability or stability of the system under test.
  • a target stress test request is a request for initiation of a stress test.
  • the original data identifier refers to an identifier that distinguishes the data type of the original data that needs to be imported in the stress test.
  • the data type of the original data may be a GPS message, a CAN message, or an HTTP message.
  • the original data identifier assigns different identifiers to the original data according to the type of the original data.
  • S20 Acquire a corresponding target custom function based on the at least one original data identifier, where the target custom function is a function that is not encapsulated by the class.
  • On-Board Diagnostic is a mobile device with communication capabilities.
  • the OBD is installed in the car, and can collect various data in the driving process of the car in real time, and send it to the background through the communication module.
  • the computing platform in the background will calculate various data of the car (such as fuel consumption information, battery voltage, intake pipe temperature, current The vehicle speed, engine water temperature, engine speed, etc. are calculated.
  • the data packets sent by OBD to the background mainly include: time point, latitude and longitude, speed, current fuel consumption and current mileage.
  • OBD sends packets of the car's driving process through the TCP protocol, so it will contain multiple data packets in one flight mileage, and the time of each data packet increases linearly, and its latitude, longitude, speed and fuel consumption need to change dynamically. Therefore, time, latitude, longitude, latitude, speed, fuel consumption and mileage need to be programmed during the stress test of the Internet of Vehicles.
  • a custom function for generating data such as time point, latitude and longitude data, speed, mileage, fuel consumption, etc. is needed to pass in time point, latitude and longitude, mileage, fuel consumption and the like according to the standard message format, and then call the corresponding java program. Synthesize hexadecimal transmission messages.
  • the corresponding custom function needs to be written according to the data type of the original data to ensure that the original data can be smoothly imported into the Jmeter test tool.
  • the corresponding target custom function is obtained based on at least one original data identifier in the target stress test request.
  • the number of the original data identifiers is consistent with the number of categories of the data types of the original data in the target stress test request.
  • a corresponding custom function has been written according to the commonly used or already tested data type, and is saved in the corresponding terminal. Therefore, in this step, at least one original data identifier in the target stress test request may be directly obtained to obtain a corresponding target custom function.
  • the target custom function is specifically a function that is not encapsulated by a class.
  • Class encapsulation refers to encapsulating data and operations into an organic whole. Since private members in the class are hidden and only provide a limited interface to the outside, internal cohesion and low coupling with the outside can be guaranteed. Users don't have to know the specific implementation details, but just use the external interface to use the members of the class with specific access rights, which can enhance security and simplify programming.
  • the target custom function at this step is a function that is not encapsulated by the class.
  • BeanShell is a small and free JAVA source code interpreter that supports object-oriented scripting language features. It can also be embedded in JAVA source code. It can dynamically execute JAVA source code and extend some features of the scripting language.
  • BeanShell will interpret the scripted function (BSHMethod) into the cache cache, which is stored in NameSpace.methods.
  • NameSpace.methods is a HashTable object. For function names (without parameters, return values), value is a Vector list (value is a list, because Java has overloaded functions), and Vector is a BSHMethod object.
  • BeanShell interprets the data type (Scripted Class, BSHType) in the script and puts it into the cache, which is stored in NameSpace.classManager.listeners (class path listener list, because the class needs to search in the class path), listeners are a The Vector list, the BSHType object wrapped in the WeakReference in the Vector, when a script containing the function is executed repeatedly using a unique interpreter, it will continuously store the data type BSHType referenced by the function to the Vector list represented by the listeners, which will also cause Memory leaks.
  • BSHType scripted Class
  • listeners are a The Vector list, the BSHType object wrapped in the WeakReference in the Vector, when a script containing the function is executed repeatedly using a unique interpreter, it will continuously store the data type BSHType referenced by the function to the Vector list represented by the listeners, which will also cause Memory leaks.
  • the same function as the java class can be implemented by using method declarations and methods in the BeanShell script file, and the methods in the BeanShell script file can have dynamic (loose) parameters and return types. Therefore, in this step, you choose to encapsulate the target custom function into a BeanShell script file.
  • the BeanShell script file is initialized. Specifically, the pre-processor in Jmeter can be used to initialize the BeanShell script file.
  • BeanShell.PreProcessor is a preprocessor in Jmeter that executes an algorithm and stores the result in a parameter.
  • the target custom function in the BeanShell script file can be interpreted in advance.
  • the BeanShell script file can be initialized in the jmeter.properties file.
  • the initialization of the BeanShell script file is as follows:
  • Beanshell.preprocessor.init XX/YY/ZZ/chushihua.bsh;
  • the BeanShell script file is initialized. In this way, in the subsequent stress test process, the required target custom function can be directly called directly, that is, the technical effect of the repeated interpretation can be achieved, and the memory leakage is not easily caused, thereby improving the throughput of the terminal/system. rate.
  • BeanShell script file After the BeanShell script file is initialized, you can call the target custom function encapsulated in the BeanShell script file for stress testing in the corresponding interface.
  • the target custom function encapsulated in the BeanShell script file is invoked for stress testing, and the stress test is performed by calling a corresponding target custom function encapsulated in the BeanShell script file based on the test parameters.
  • the test parameters refer to the parameters that need to be tested in the stress test project. Different test parameters will be imported through the corresponding target custom function to select the corresponding raw data. In different stress test items or types, the test methods may vary due to different test parameters or test requirements. Therefore, during the stress test, not all target custom functions need to be called. In this step, based on the test parameters, the required target custom function is called from the target custom function encapsulated in the BeanShell script file for stress testing. Since the target custom function has been explained in the initialization of the script file, even if the target custom function is called multiple times during the stress test, the target custom function will not be interpreted repeatedly, thus avoiding the memory. Give way.
  • the corresponding target custom function is obtained based on the original data identifier in the target stress test request, and the function writing is not required to be repeated, thereby improving the efficiency of the test.
  • the target custom function is a function that is not encapsulated by the class, and the target custom function is encapsulated into a BeanShell script file, and the BeanShell script file is initialized to ensure that the required target can be directly in the subsequent stress test process.
  • the custom function can be called, and the effect of repeated interpretation and repeated calling can be realized, and the throughput of the terminal/system is improved under the premise of avoiding thread blocking.
  • the corresponding target custom function is obtained based on the at least one original data identifier, as shown in FIG. 2, including the following steps:
  • the custom function list is a table for associating data identifiers and custom functions.
  • the list of custom functions includes data identifiers and custom functions (as shown in Table 1). After obtaining the original data identifier, the data identifier corresponding to the original data identifier is queried in the custom function list based on the original data identifier, so that the corresponding custom function is obtained as the target custom function.
  • the corresponding custom function cannot be obtained in the custom function list, indicating that the custom function corresponding to the original data identifier is not stored in the terminal/system. For example (see Table 1): If the original data in the target stress test request is identified as B, C, and D. For the original data identifiers B and C, the corresponding target custom functions Y and Z can be obtained in the list of custom functions. For the original data identifier D, there is no corresponding custom function in the custom function list.
  • the terminal/system will send a prompt message to remind the user that there is no corresponding custom function in the terminal/system for the original data identifier.
  • the prompt message includes an original data identifier of the corresponding custom function that is not obtained in the custom function list, so as to better remind the user.
  • the user After seeing the prompt message sent by the terminal, the user needs to write a corresponding new custom function according to the original data identifier. After the system obtains the newly added custom function, the new custom function is used as the corresponding The target custom function for the raw data identification.
  • the corresponding target custom function is obtained through the custom function list, the data acquisition efficiency is improved, and when there is no corresponding custom function, a prompt message is sent to guide the user to write a corresponding new custom. Function to ensure the smooth progress of the stress test.
  • the Jmeter-based stress test method further includes: adding a new custom function and corresponding original data identifier. Associate and save to a list of custom functions.
  • the newly added custom function is associated with the corresponding original data identifier, and saved to the custom function list to ensure real-time update of the custom function list.
  • the corresponding target custom function can be directly obtained, thereby improving the efficiency of the stress test.
  • the target custom function is packaged into a BeanShell script file, as shown in FIG. 3, including the following steps:
  • S31 Acquire an existing stress test item, and obtain an average number of calls per target custom function based on the existing stress test item.
  • the existing stress test project refers to the stress test project that has been completed.
  • the number of calls for each custom function is different, so you can get the target custom function by querying the call of the corresponding custom function in the existing stress test project. The number of calls.
  • the average number of calls per target custom function can be obtained by obtaining the number of calls of each target custom function in each existing stress test item and summing the number of these calls. .
  • S32 Encapsulate the target custom function with the average number of calls greater than the preset number into a BeanShell script file.
  • a preset number of times can be set to determine which of the custom functions used in the existing stress test items, which custom functions have an average number of calls in the existing stress test items greater than a preset number of times, and this part of the custom function
  • the target custom function is encapsulated into a BeanShell script file.
  • the preset number of times can be set according to historical test results or actual needs.
  • the average number of calls of each target custom function is obtained by obtaining and calculating the number of calls of each target custom function in the existing stress test item, and then the average number of calls is greater than the preset number of times.
  • the target custom function is packaged into a BeanShell script file, which reduces the burden on the terminal/system and further improves the throughput.
  • the target stress test request also includes a target stress test type.
  • the target stress test type refers to the test type corresponding to the target stress test request.
  • an existing stress test item is obtained, including: obtaining an existing stress test item of the same type of stress test item as the target stress test.
  • the stress test project can be divided into different types according to different test conditions and test requirements.
  • the test process of the same type of stress test project is relatively similar.
  • the accuracy of the data is improved by obtaining the existing stress test items of the same type as the target stress test type and obtaining the average number of calls per target custom function based on the existing stress test items of the same type as the target stress test type.
  • the average number of calls of the target custom function is calculated by acquiring an existing pressure test item having the same type as the target stress test in the existing stress test item, thereby ensuring the accuracy of the data.
  • the existing stress test items include existing stress test types.
  • existing stress test items can be classified according to different types, and different types of existing stress test items can be distinguished by existing stress test types.
  • the average number of calls per target custom function is counted based on the existing stress test item, as shown in FIG. 4, including the following steps:
  • the number of calls of each target custom function in each existing stress test item is obtained by querying the call of the corresponding custom function in the existing stress test item.
  • S312 Set a corresponding weight for each existing stress test item based on the correlation between the existing stress test type and the target stress test type.
  • the stress test project can be divided into different types according to different test conditions and test requirements.
  • the test process of the same type of stress test project is relatively similar. Therefore, a corresponding weight can be set for each existing stress test item based on the correlation between the existing stress test type and the target stress test type. The higher the relevance, the higher the corresponding weight.
  • the weight of the existing stress test item of the same type as the target pressure test type can be set to a, and the weight of the existing stress test item of the other type different from the target stress test type is set to 0.5a. .
  • S313 weighting and summing the number of calls of each target custom function in different existing stress test items based on the weight of each existing stress test item, and obtaining an average of each target custom function. The number of calls.
  • each target custom function After obtaining the number of calls for each target custom function in each existing stress test item, and according to the weights set for each existing stress test item, each target custom function is different.
  • the number of calls in the stress test project is weighted and averaged, that is, the average number of calls per target custom function is obtained.
  • a corresponding weight is set for each existing stress test item according to the correlation between the existing stress test type and the target stress test type, and each target is calculated according to the set weight value.
  • the average number of calls to the custom function further ensures the accuracy of the data.
  • the target custom function encapsulated in the BeanShell script file is invoked for stress testing, as shown in FIG. 5, and the following steps are also included:
  • the number of iterations of the target custom function during the stress test is counted by starting the counter in the Jmeter.
  • the counter allows the user to create a counter that can be referenced within the thread group. This counter allows the user to configure a starting point, a maximum value and a corresponding number of increments, after which the counter starts at the starting point and continues to the maximum value according to the number of increments. Then, start over and continue to cycle until the end of the stress test. Therefore, during the stress test, the corresponding counter can be configured for each target custom function to count the number of iterations of the target custom function during the stress test.
  • the counter counts the number of iterations of each target custom function during the stress test. If the number of iterations of any target custom function is greater than the iteration threshold, the interpreter is reset to free memory and avoid memory leaks.
  • the number of iterations of each target custom function is counted by using a counter. If the number of iterations of any target custom function is greater than the iteration threshold, the interpreter is reset to avoid memory leakage and further avoid thread blocking. Improve the throughput of the terminal/system.
  • Fig. 6 is a block diagram showing the principle of a Jmeter-based pressure testing device corresponding to the Jmeter-based pressure testing method in the first embodiment.
  • the Jmeter-based stress testing device includes a target stress test request acquisition module 10, a target custom function acquisition module 20, a target custom function packaging module 30, an initialization module 40, and a stress test module 50.
  • the implementation functions of the target stress test request acquisition module 10, the target custom function acquisition module 20, the target custom function encapsulation module 30, the initialization module 40, and the stress test module 50 correspond to the Jmeter-based stress test method in Embodiment 1.
  • the steps are one-to-one correspondence, and the details are not described in detail in order to avoid redundancy.
  • the target stress test request acquisition module 10 is configured to obtain a target stress test request, and the target stress test request includes at least one original data identifier.
  • the target custom function obtaining module 20 is configured to obtain a corresponding target custom function based on the at least one original data identifier, wherein the target custom function is a function that is not encapsulated by the class.
  • the target custom function encapsulation module 30 is configured to encapsulate the target custom function into a BeanShell script file.
  • the initialization module 40 is configured to initialize the BeanShell script file.
  • the stress test module 50 is configured to invoke a target custom function encapsulated in the BeanShell script file for stress testing.
  • the target custom function acquisition module 20 includes a target custom function acquisition unit 21, a prompt message transmission unit 22, and a new custom function acquisition unit 23.
  • the target custom function obtaining unit 21 is configured to obtain, according to the at least one original data identifier, a custom function corresponding to the original data identifier in the custom function list as the target custom function.
  • the prompt message sending unit 22 is configured to send a prompt message if any original function is not obtained in the custom function list if any original data identifier exists.
  • a new custom function obtaining unit 23 is configured to obtain a newly added custom function input by the user as a target custom function.
  • the target custom function obtaining module 20 further includes a new custom function associating unit 24.
  • a new custom function association unit 24 is added to associate the newly added custom function with the corresponding original data identifier and save it to the custom function list.
  • the target custom function encapsulation module 30 includes an average call count acquisition unit 31 and a target custom function encapsulation unit 32.
  • the average call count obtaining unit 31 is configured to acquire an existing stress test item, and obtain an average number of calls of each target custom function based on the existing stress test item.
  • the target custom function encapsulating unit 32 is configured to encapsulate the target custom function whose average number of calls is greater than the preset number of times into a BeanShell script file.
  • the target stress test request further includes a target stress test type.
  • the average call count obtaining unit 31 is further configured to acquire an existing stress test item of the same type of the target stress test in the existing stress test item.
  • the average call count acquisition unit 31 includes a call count count sub-unit 311, a weight value setting sub-unit 312, and an average call count acquisition sub-unit 313.
  • the call count statistics sub-unit 311 is configured to count the number of calls of each target custom function in each existing stress test item.
  • the weight setting sub-unit 312 is configured to set a corresponding weight for each existing stress test item based on the correlation between the existing stress test type and the target stress test type.
  • the average call count acquisition sub-unit 313 is configured to perform weighted summation and average the call times of each target custom function in different existing stress test items based on the weight of each existing stress test item, and obtain an average value The average number of calls per target custom function.
  • the stress test module 50 includes an iteration count statistic unit 51 and an interpreter reset unit 52.
  • the iteration count statistic unit 51 is configured to start a counter and count the number of iterations of the target custom function.
  • the interpreter reset unit 52 is configured to reset the interpreter if the number of iterations of any of the target custom functions is greater than an iteration threshold.
  • the embodiment provides one or more non-volatile readable storage media having computer readable instructions that, when executed by one or more processors, cause the one or more processors to execute The steps of the Jmeter-based stress test method in Embodiment 1 are not repeated here to avoid repetition.
  • the computer readable instructions are executed by one or more processors, causing the one or more processors to implement the functions of the modules/units in the Jmeter based stress testing device of Embodiment 2, to avoid duplication, I won't go into details here.
  • non-volatile readable storage medium may include any entity or device capable of carrying the computer readable instruction code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, only Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier signals, and telecommunications signals.
  • ROM Read-Only Memory
  • RAM Random Access Memory
  • FIG. 7 is a schematic diagram of a computer device according to an embodiment of the present application.
  • computer device 60 of this embodiment includes a processor 61, a memory 62, and computer readable instructions 63 stored in memory 62 and executable on processor 61.
  • the processor 61 performs the steps of the Jmeter-based stress test method of Embodiment 1 described above when executing the computer readable instructions 63, such as steps S10 to S50 shown in FIG.
  • the processor 61 executes the computer readable instructions 63
  • the functions of the modules/units in the foregoing device embodiments are implemented, such as the target stress test request acquisition module 10, the target custom function acquisition module 20, and the target self shown in FIG.
  • the functions of function encapsulation module 30, initialization module 40, and stress test module 50 are defined.

Abstract

Disclosed are a Jmeter-based stress testing method and apparatus, and a device and a storage medium. The Jmeter-based stress testing method comprises: obtaining a target stress testing request, the target stress testing request comprising at least one original data identifier; obtaining a corresponding target self-defined function on the basis of the at least one original data identifier, the target self-defined function being a function that is not encapsulated by a class; encapsulating the target self-defined function as a BeanShell script file; initializing the BeanShell script file; and invoking the target self-defined function encapsulated in the BeanShell script file to perform stress testing. According to the Jmeter-based stress testing method, in a stress testing process, a desired target self-defined function can be directly invoked, thereby yielding the technical effect of one interpretation and repeated invoking and improving the throughput of a terminal/system while avoiding thread blocking.

Description

基于Jmeter的压力测试方法、装置、设备及存储介质Jmeter-based pressure test method, device, device and storage medium
本申请以2018年03月22日提交的申请号为201810239745.1,名称为“基于Jmeter的压力测试方法、装置、设备及存储介质”的中国发明专利申请为基础,并要求其优先权。The present application is based on the Chinese Patent Application No. 201101239745.1, entitled "Jmeter-based Pressure Test Method, Apparatus, Apparatus, and Storage Medium", which is filed on March 22, 2018, and claims priority.
技术领域Technical field
本申请涉及软件测试领域,尤其涉及一种基于Jmeter的压力测试方法、装置、设备及存储介质。The present application relates to the field of software testing, and in particular, to a Jmeter-based stress testing method, apparatus, device, and storage medium.
背景技术Background technique
目前市面上有多种对软件进行压力测试的工具,而Jmeter是推荐度较高的压力测试工具之一。Jmeter可以用于对服务器、网络或对象模拟巨大的负载,来自不同压力类别下测试它们的强度,以分析整体性能。在使用Jmeter进行压力测试时,通常需要编写程序进行辅助测试,主要的编程方式主要有BeanShell和JSR223脚本(Groovy和Javascript)两种。然而,无论是采用何种方式进行编程,在压力测试中都经常出现系统崩溃的情况。传统地,认为是由于BeanShell的Interpreter存在内存泄露,常规方法无法支持长时间的压力测试而引起的系统崩溃。Jmeter官网推荐,在使用BeanShell进行长时间测试时,可以打开选项“Reset bsh.Interpreter before each call”,即在每次调用BeanShell程序前,都把解释器进行重置,以释放解释器之前占用的内存。然而,开启了解释器重置选项之后,在压力测试中会导致大量的线程阻塞,这大大降低了终端/系统的吞吐率。There are a variety of tools for stress testing software on the market, and Jmeter is one of the more highly recommended stress testing tools. Jmeter can be used to simulate large loads on servers, networks, or objects, testing their strength from different stress classes to analyze overall performance. When using Jmeter for stress testing, it is usually necessary to write a program for auxiliary testing. The main programming methods are BeanShell and JSR223 scripts (Groovy and Javascript). However, no matter how it is programmed, there is often a system crash in stress testing. Traditionally, it is believed that due to memory leaks in BeanShell's Interpreter, conventional methods cannot support system crashes caused by prolonged stress tests. Jmeter official website recommended, when using BeanShell for long-term testing, you can open the option "Reset bsh.Interpreter before each call", that is, before each call to the BeanShell program, the interpreter is reset to release the front of the interpreter RAM. However, after the interpreter reset option is turned on, a large number of thread blocking is caused in the stress test, which greatly reduces the throughput of the terminal/system.
发明内容Summary of the invention
本申请实施例提供一种基于Jmeter的压力测试方法、装置、设备及存储介质,以解决在压力测试过程中终端/系统吞吐率不高的的问题。The embodiment of the present application provides a JMET-based stress testing method, apparatus, device, and storage medium to solve the problem that the terminal/system throughput rate is not high during the stress testing process.
第一方面,本申请实施例提供一种基于Jmeter的压力测试方法,包括:In a first aspect, an embodiment of the present application provides a JMET-based stress testing method, including:
获取目标压力测试请求,所述目标压力测试请求包括至少一个原始数据标识;Obtaining a target stress test request, the target stress test request including at least one original data identifier;
基于至少一个所述原始数据标识,获取对应的目标自定义函数,其中,所述目标自定义函数为未进行类封装的函数;And acquiring, according to the at least one original data identifier, a corresponding target custom function, where the target custom function is a function that is not encapsulated by the class;
将所述目标自定义函数封装成BeanShell脚本文件;Encapsulating the target custom function into a BeanShell script file;
对所述BeanShell脚本文件进行初始化;Initializing the BeanShell script file;
调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。Call the target custom function encapsulated in the BeanShell script file for stress testing.
第二方面,本申请实施例提供一种基于Jmeter的压力测试装置,包括:In a second aspect, the embodiment of the present application provides a Jmeter-based pressure testing device, including:
目标压力测试请求获取模块,用于获取目标压力测试请求,所述目标压力测试请求包括至少一个原始数据标识;a target stress test request obtaining module, configured to acquire a target stress test request, where the target stress test request includes at least one original data identifier;
目标自定义函数获取模块,用于基于至少一个所述原始数据标识,获取对应的目标自定义函数,其中,所述目标自定义函数为未进行类封装的函数;a target custom function obtaining module, configured to acquire a corresponding target custom function based on at least one of the original data identifiers, wherein the target custom function is a function that is not encapsulated by a class;
目标自定义函数封装模块,用于将所述目标自定义函数封装成BeanShell脚本文件;a target custom function encapsulation module, configured to encapsulate the target custom function into a BeanShell script file;
初始化模块,用于对所述BeanShell脚本文件进行初始化;An initialization module, configured to initialize the BeanShell script file;
压力测试模块,用于调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。The stress test module is used to invoke the target custom function encapsulated in the BeanShell script file for stress testing.
第三方面,本申请实施例提供一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,所述处理器执行所述计算机可读指令时实现如下步骤:In a third aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and computer readable instructions stored in the memory and executable on the processor, where the processor executes the computer The following steps are implemented when reading the instruction:
获取目标压力测试请求,所述目标压力测试请求包括至少一个原始数据标识;Obtaining a target stress test request, the target stress test request including at least one original data identifier;
基于至少一个所述原始数据标识,获取对应的目标自定义函数,其中,所述目标自定义函数为未进行类封装的函数;And acquiring, according to the at least one original data identifier, a corresponding target custom function, where the target custom function is a function that is not encapsulated by the class;
将所述目标自定义函数封装成BeanShell脚本文件;Encapsulating the target custom function into a BeanShell script file;
对所述BeanShell脚本文件进行初始化;Initializing the BeanShell script file;
调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。Call the target custom function encapsulated in the BeanShell script file for stress testing.
第四方面,本申请实施例提供一个或多个存储有计算机可读指令的非易失性可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:In a fourth aspect, the embodiment of the present application provides one or more non-volatile readable storage media storing computer readable instructions, when the computer readable instructions are executed by one or more processors, such that the one or Multiple processors perform the following steps:
获取目标压力测试请求,所述目标压力测试请求包括至少一个原始数据标识;Obtaining a target stress test request, the target stress test request including at least one original data identifier;
基于至少一个所述原始数据标识,获取对应的目标自定义函数,其中,所述目标自定义函数为未进行类封装的函数;And acquiring, according to the at least one original data identifier, a corresponding target custom function, where the target custom function is a function that is not encapsulated by the class;
将所述目标自定义函数封装成BeanShell脚本文件;Encapsulating the target custom function into a BeanShell script file;
对所述BeanShell脚本文件进行初始化;Initializing the BeanShell script file;
调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。Call the target custom function encapsulated in the BeanShell script file for stress testing.
本申请的一个或多个实施例的细节在下面的附图和描述中提出,本申请的其他特征和优点将从说明书、附图以及权利要求变得明显。The details of one or more embodiments of the present invention are set forth in the accompanying drawings and the description of the claims.
附图说明DRAWINGS
为了更清楚地说明本申请实施例的技术方案,下面将对本申请实施例的描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings used in the description of the embodiments of the present application will be briefly described below. It is obvious that the drawings in the following description are only some embodiments of the present application. Other drawings may also be obtained from those of ordinary skill in the art based on these drawings without the inventive labor.
图1是本申请实施例1中的基于Jmeter的压力测试方法的一流程图;1 is a flow chart of a Jmeter-based stress testing method in Embodiment 1 of the present application;
图2是图1中步骤S20的一具体实施方式的一流程图;2 is a flow chart of a specific embodiment of step S20 of FIG. 1;
图3是图1中步骤S30的一具体实施方式的一流程图;Figure 3 is a flow chart of a specific embodiment of step S30 of Figure 1;
图4是图3中步骤S31的一具体实施方式的一流程图;4 is a flow chart of a specific embodiment of step S31 in FIG. 3;
图5是图1中步骤S50的一具体实施方式的一流程图;Figure 5 is a flow chart of a specific embodiment of step S50 of Figure 1;
图6是本申请实施例2中的基于Jmeter的压力测试装置的一示意图;6 is a schematic diagram of a Jmeter-based pressure testing device in Embodiment 2 of the present application;
图7是本申请实施例4中的计算机设备的示意图。Figure 7 is a schematic diagram of a computer device in Embodiment 4 of the present application.
具体实施方式detailed description
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application are clearly and completely described in the following with reference to the drawings in the embodiments of the present application. It is obvious that the described embodiments are a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present application without departing from the inventive scope are the scope of the present application.
本申请采用了Jmeter测试工具来进行压力测试。其中,Jmeter是Apache组织开发的基于Java的压力测试工具,用于对软件做压力测试。Jmeter可以用于测试静态和动态资源,例如静态文件、Java小服务程序、CGI脚本、Java对象、数据库或FTP服务器等。Jmeter可以用于对服务器、网络或对象模拟巨大的负载,来自不同压力类别下测试它们的强度,以分析整体性能。This application uses the Jmeter test tool for stress testing. Among them, Jmeter is a Java-based stress testing tool developed by the Apache organization for stress testing software. Jmeter can be used to test static and dynamic resources such as static files, Java servlets, CGI scripts, Java objects, databases or FTP servers. Jmeter can be used to simulate large loads on servers, networks, or objects, testing their strength from different stress classes to analyze overall performance.
实施例1Example 1
图1示出本实施例中基于Jmeter的压力测试方法的流程图。该基于Jmeter的压力测试方法可以应用在各种终端或系统中,以解决在压力测试过程中终端/系统吞吐率不高的问题。如图1所示,该基于Jmeter的压力测试方法包括如下步骤:Fig. 1 shows a flow chart of a Jmeter-based stress test method in this embodiment. The Jmeter-based stress test method can be applied to various terminals or systems to solve the problem that the terminal/system throughput rate is not high during the stress test. As shown in FIG. 1, the Jmeter-based stress test method includes the following steps:
S10:获取目标压力测试请求,目标压力测试请求包括至少一个原始数据标识。S10: Acquire a target stress test request, where the target stress test request includes at least one original data identifier.
其中,压力测试是模拟实际应用的软硬件环境及用户使用过程的系统负荷,长时间或 超大负荷地运行测试软件,来测试被测系统的性能、可靠性或稳定性等特性的测试过程。目标压力测试请求是指一个压力测试的发起请求。而原始数据标识是指对该压力测试中需要导入的原始数据的数据类型进行区分的一个标识。例如,该原始数据的数据类型可以为GPS报文、CAN报文或HTTP报文等,原始数据标识即根据原始数据的类型的不同而为原始数据赋予不同的标识。Among them, the stress test is a test process that simulates the software and hardware environment of the actual application and the system load of the user's use process, and runs the test software for a long time or a large load to test the performance, reliability or stability of the system under test. A target stress test request is a request for initiation of a stress test. The original data identifier refers to an identifier that distinguishes the data type of the original data that needs to be imported in the stress test. For example, the data type of the original data may be a GPS message, a CAN message, or an HTTP message. The original data identifier assigns different identifiers to the original data according to the type of the original data.
S20:基于至少一个原始数据标识,获取对应的目标自定义函数,其中,目标自定义函数为未进行类封装的函数。S20: Acquire a corresponding target custom function based on the at least one original data identifier, where the target custom function is a function that is not encapsulated by the class.
在Jmeter中内置了一些常用的函数,在Jmeter->选项->函数助手对话框可以查询,但是在部分压力测试过程中这些内置的函数远远不能够满足压力测试的需求。例如,在车联网的压力测试中,车载终端设备(OBD,On-Board Diagnostic)是一款具备通信功能的移动设备。OBD安装在汽车上,可实时采集汽车行驶过程中的各项数据,并通过通信模块发送给后台,后台的计算平台会对汽车的各项数据(如油耗信息、电瓶电压、进气管温度、当前车速、发动机水温和引擎转速等)进行计算。OBD发送给后台的数据包主要包含:时间点、经纬度、速度、当前油耗和当前里程等数据。OBD通过TCP协议发送汽车行驶过程的数据包,所以在一段行程里程中,会包含有多个数据包,而且每个数据包的时间为线性增长,其经纬度、速度、油耗均需要动态变化。因此在进行车联网的压力测试时,时间、经纬度、速度、油耗和里程都需要通过编程实现。具体地,需要生成时间点、经纬度数据、速度、里程、油耗等数据的自定义函数,以根据规范的报文格式,传入时间点、经纬度、里程和油耗等数据,再调用对应的java程序合成16进制的传输报文。Some commonly used functions are built into Jmeter, which can be queried in the Jmeter->Options->Function Assistant dialog box, but these built-in functions are far from meeting the stress test requirements during partial stress testing. For example, in the stress test of the Internet of Vehicles, On-Board Diagnostic (OBD) is a mobile device with communication capabilities. The OBD is installed in the car, and can collect various data in the driving process of the car in real time, and send it to the background through the communication module. The computing platform in the background will calculate various data of the car (such as fuel consumption information, battery voltage, intake pipe temperature, current The vehicle speed, engine water temperature, engine speed, etc. are calculated. The data packets sent by OBD to the background mainly include: time point, latitude and longitude, speed, current fuel consumption and current mileage. OBD sends packets of the car's driving process through the TCP protocol, so it will contain multiple data packets in one flight mileage, and the time of each data packet increases linearly, and its latitude, longitude, speed and fuel consumption need to change dynamically. Therefore, time, latitude, longitude, latitude, speed, fuel consumption and mileage need to be programmed during the stress test of the Internet of Vehicles. Specifically, a custom function for generating data such as time point, latitude and longitude data, speed, mileage, fuel consumption, etc. is needed to pass in time point, latitude and longitude, mileage, fuel consumption and the like according to the standard message format, and then call the corresponding java program. Synthesize hexadecimal transmission messages.
因此,在压力测试过程中,需要根据原始数据的数据类型,编写对应的自定义函数,以保证原始数据可以顺利地导入到Jmeter测试工具中。在获取到目标压力测试请求之后,基于目标压力测试请求中的至少一个原始数据标识,来获取对应的目标自定义函数。其中,原始数据标识的个数和该目标压力测试请求中原始数据的数据类型的类别数一致。具体地,在终端中会根据常用或者已经测试过的数据类型,已编写了对应的自定义函数,并保存在对应的终端中。故在此步骤中可以根据目标压力测试请求中的至少一个原始数据标识,直接来获取对应的目标自定义函数即可。Therefore, during the stress test, the corresponding custom function needs to be written according to the data type of the original data to ensure that the original data can be smoothly imported into the Jmeter test tool. After obtaining the target stress test request, the corresponding target custom function is obtained based on at least one original data identifier in the target stress test request. The number of the original data identifiers is consistent with the number of categories of the data types of the original data in the target stress test request. Specifically, in the terminal, a corresponding custom function has been written according to the commonly used or already tested data type, and is saved in the corresponding terminal. Therefore, in this step, at least one original data identifier in the target stress test request may be directly obtained to obtain a corresponding target custom function.
其中,目标自定义函数具体为未进行类封装的函数。类封装是指将数据和操作封装为一个有机的整体,由于类中私有成员都是隐藏的,只向外部提供有限的接口,所以能够保证内部的高内聚性和与外部的低耦合性。使用者不必了解具体的实现细节,而只是要通过外部接口,以特定的访问权限来使用类的成员,能够增强安全性和简化编程。然而,在编 写自定义函数的过程中,若将对应的目标自定义函数进行类封装,那么在压力测试过程中,在不断地调用对应的目标自定义函数时,会导致不断地进行类加载,而类加载过程中时需要加锁,这必然会导致线程阻塞严重,影响终端/系统的吞吐率。因此,在该步骤的目标自定义函数均是未进行类封装的函数。The target custom function is specifically a function that is not encapsulated by a class. Class encapsulation refers to encapsulating data and operations into an organic whole. Since private members in the class are hidden and only provide a limited interface to the outside, internal cohesion and low coupling with the outside can be guaranteed. Users don't have to know the specific implementation details, but just use the external interface to use the members of the class with specific access rights, which can enhance security and simplify programming. However, in the process of writing a custom function, if the corresponding target custom function is packaged in a class, in the stress test process, when the corresponding target custom function is continuously called, the class loading is continuously performed. In the process of class loading, locks are required, which inevitably leads to serious thread blocking and affects the throughput of the terminal/system. Therefore, the target custom function at this step is a function that is not encapsulated by the class.
S30:将目标自定义函数封装成BeanShell脚本文件。S30: Encapsulate the target custom function into a BeanShell script file.
BeanShell是一个小巧免费的JAVA源码解释器,支持对象式的脚本语言特性,亦可嵌入到JAVA源代码中,能动态执行JAVA源代码并为其扩展了脚本语言的一些特性。在常规地采用Jmeter进行压力测试时,BeanShell会把脚本中的函数(Scripted Method,BSHMethod)解释后放入了缓存cache,即存放于NameSpace.methods上,其中,NameSpace.methods是一个HashTable对象,key为函数名(不包含参数、返回值),value为Vector列表(value为列表,因为Java存在重载函数),Vector内是BSHMethod对象,当一个包含函数的脚本使用唯一的解释器重复执行,就会不断地把函数存放到Vector列表中,从而导致内存泄露。BeanShell is a small and free JAVA source code interpreter that supports object-oriented scripting language features. It can also be embedded in JAVA source code. It can dynamically execute JAVA source code and extend some features of the scripting language. When using Jmeter for stress testing, BeanShell will interpret the scripted function (BSHMethod) into the cache cache, which is stored in NameSpace.methods. NameSpace.methods is a HashTable object. For function names (without parameters, return values), value is a Vector list (value is a list, because Java has overloaded functions), and Vector is a BSHMethod object. When a script containing a function is executed repeatedly using a unique interpreter, The function is continually placed in the Vector list, causing memory leaks.
而且,BeanShell把脚本中的数据类型(Scripted Class,BSHType)解释后放入了缓存,即存放于NameSpace.classManager.listeners(class path监听列表,因为class需要在类路径中搜索)中,listeners是一个Vector列表,Vector内为WeakReference包装的BSHType对象,当一个包含函数的脚本使用唯一的解释器重复执行,就会不断地把函数引用到的数据类型BSHType存放到listeners代表的Vector列表,从而也会引起内存泄露。Moreover, BeanShell interprets the data type (Scripted Class, BSHType) in the script and puts it into the cache, which is stored in NameSpace.classManager.listeners (class path listener list, because the class needs to search in the class path), listeners are a The Vector list, the BSHType object wrapped in the WeakReference in the Vector, when a script containing the function is executed repeatedly using a unique interpreter, it will continuously store the data type BSHType referenced by the function to the Vector list represented by the listeners, which will also cause Memory leaks.
由于NameSpace.methods中的BSHMethod不能释放,那么BSHMethod引用到的class在NameSpace.classManager.listeners中也没法释放,最终也导致了内存泄漏。Since the BSHMethod in NameSpace.methods cannot be released, the class referenced by BSHMethod cannot be released in NameSpace.classManager.listeners, which eventually leads to memory leaks.
而在Beanshell脚本中,通过在Beanshell脚本文件中进行方法宣告和方法使用,就可以实现和java的类一样的功能,而且Beanshell脚本文件中的方法可以有动态的(宽松的)参数和返回类型。因此,在该步骤中,选择将目标自定义函数封装成Beanshell脚本文件。In the BeanShell script, the same function as the java class can be implemented by using method declarations and methods in the BeanShell script file, and the methods in the BeanShell script file can have dynamic (loose) parameters and return types. Therefore, in this step, you choose to encapsulate the target custom function into a BeanShell script file.
S40:对BeanShell脚本文件进行初始化。S40: Initialize the BeanShell script file.
将目标自定义函数封装到Beanshell脚本文件之后,对该Beanshell脚本文件进行初始化操作。具体地,可以采用Jmeter中的前置处理器来实现Beanshell脚本文件的初始化。After the target custom function is encapsulated into the BeanShell script file, the BeanShell script file is initialized. Specifically, the pre-processor in Jmeter can be used to initialize the BeanShell script file.
BeanShell.PreProcessor是Jmeter中一个前置处理器,可以执行一个算法并将结果存储到参数中。通过将目标自定义函数封装成Beanshell脚本文件,并对Beanshell脚本文件的初始化,可以预先对Beanshell脚本文件中的目标自定义函数进行解释。具体地,可以在jmeter.properties文件中进行Beanshell脚本文件的初始化。示例性地,Beanshell脚本文件 的初始化如下:BeanShell.PreProcessor is a preprocessor in Jmeter that executes an algorithm and stores the result in a parameter. By encapsulating the target custom function into a BeanShell script file and initializing the BeanShell script file, the target custom function in the BeanShell script file can be interpreted in advance. Specifically, the BeanShell script file can be initialized in the jmeter.properties file. Illustratively, the initialization of the BeanShell script file is as follows:
Beanshell.preprocessor.init=XX/YY/ZZ/chushihua.bsh;Beanshell.preprocessor.init=XX/YY/ZZ/chushihua.bsh;
在将目标自定义函数封装成BeanShell脚本文件之后,对BeanShell脚本文件进行初始化。如此,在后续的压力测试过程中,可以直接对所需要的目标自定义函数直接进行调用,即可以达到一次解释,重复调用的技术效果,不容易引起内存泄漏,从而提高了终端/系统的吞吐率。After the target custom function is packaged into a BeanShell script file, the BeanShell script file is initialized. In this way, in the subsequent stress test process, the required target custom function can be directly called directly, that is, the technical effect of the repeated interpretation can be achieved, and the memory leakage is not easily caused, thereby improving the throughput of the terminal/system. rate.
S50:调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。S50: Call the target custom function encapsulated in the BeanShell script file for stress testing.
在BeanShell脚本文件初始化完毕之后,可以在相应的界面中,调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。After the BeanShell script file is initialized, you can call the target custom function encapsulated in the BeanShell script file for stress testing in the corresponding interface.
在一个具体实施方式中,调用BeanShell脚本文件中封装的目标自定义函数进行压力测试,还包括:基于测试参数,调用BeanShell脚本文件中封装的对应的目标自定义函数进行压力测试。In a specific implementation, the target custom function encapsulated in the BeanShell script file is invoked for stress testing, and the stress test is performed by calling a corresponding target custom function encapsulated in the BeanShell script file based on the test parameters.
其中,测试参数是指在压力测试项目中需要进行测试的参数。而不同的测试参数会通过对应的目标自定义函数来选择对应的原始数据进行导入。在不同的压力测试项目或类型中,由于测试参数或者测试需求的不同,测试方法也会有差异。故在压力测试过程中,并不是所有的目标自定义函数都是需要调用的。在该步骤中,基于测试参数,从BeanShell脚本文件中封装的目标自定义函数中调用需要的目标自定义函数进行压力测试。由于目标自定义函数在脚本文件的初始化中已经进行了解释,所以即使在压力测试过程中对目标自定义函数进行了多次调用,也不会重复对目标自定义函数进行解释,从而避免了内存泄露。Among them, the test parameters refer to the parameters that need to be tested in the stress test project. Different test parameters will be imported through the corresponding target custom function to select the corresponding raw data. In different stress test items or types, the test methods may vary due to different test parameters or test requirements. Therefore, during the stress test, not all target custom functions need to be called. In this step, based on the test parameters, the required target custom function is called from the target custom function encapsulated in the BeanShell script file for stress testing. Since the target custom function has been explained in the initialization of the script file, even if the target custom function is called multiple times during the stress test, the target custom function will not be interpreted repeatedly, thus avoiding the memory. Give way.
在这个实施方式中,基于目标压力测试请求中的原始数据标识来获取对应的目标自定义函数,不需要重复地进行函数的编写,提高了测试的效率。而且,目标自定义函数为未进行类封装的函数,通过将目标自定义函数封装成BeanShell脚本文件,并对BeanShell脚本文件进行初始化,保证在后续的压力测试过程中,可以直接对所需要的目标自定义函数进行调用即可,可以实现一次解释,重复调用的效果,在避免线程阻塞的前提下,提高了终端/系统的吞吐率。In this embodiment, the corresponding target custom function is obtained based on the original data identifier in the target stress test request, and the function writing is not required to be repeated, thereby improving the efficiency of the test. Moreover, the target custom function is a function that is not encapsulated by the class, and the target custom function is encapsulated into a BeanShell script file, and the BeanShell script file is initialized to ensure that the required target can be directly in the subsequent stress test process. The custom function can be called, and the effect of repeated interpretation and repeated calling can be realized, and the throughput of the terminal/system is improved under the premise of avoiding thread blocking.
在一个具体实施方式中,基于至少一个原始数据标识,获取对应的目标自定义函数,如图2所示,包括以下步骤:In a specific implementation, the corresponding target custom function is obtained based on the at least one original data identifier, as shown in FIG. 2, including the following steps:
S21:基于至少一个原始数据标识,获取自定义函数列表中和原始数据标识对应的自定义函数,作为目标自定义函数。S21: Obtain a custom function corresponding to the original data identifier in the list of the custom function based on the at least one original data identifier, as the target custom function.
其中,自定义函数列表是用于关联数据标识和自定义函数的表格。可选地,自定义函 数列表包括数据标识和自定义函数(如表一所示)。在获取到原始数据标识之后,就可以基于该原始数据标识,在自定义函数列表中查询和原始数据标识对应的数据标识,从而获取到对应的自定义函数,作为目标自定义函数。Among them, the custom function list is a table for associating data identifiers and custom functions. Optionally, the list of custom functions includes data identifiers and custom functions (as shown in Table 1). After obtaining the original data identifier, the data identifier corresponding to the original data identifier is queried in the custom function list based on the original data identifier, so that the corresponding custom function is obtained as the target custom function.
表一 自定义函数列表Table 1 List of custom functions
Figure PCTCN2018092636-appb-000001
Figure PCTCN2018092636-appb-000001
S22:若存在任一原始数据标识,在自定义函数列表中获取不到对应的自定义函数,则发送提示消息。S22: If any original data identifier exists, and the corresponding custom function is not obtained in the custom function list, a prompt message is sent.
若存在任一原始数据标识,在自定义函数列表中获取不到对应的自定义函数,则说明终端/系统中尚未存储有与该原始数据标识相对应的自定义函数。例如(参见表一):若目标压力测试请求中的原始数据标识为B、C和D。对于原始数据标识B和C,可以在自定义函数列表中获取到对应的目标自定义函数Y和Z。而对于原始数据标识D,此时在自定义函数列表中是不存在对应的自定义函数的。If any original data identifier exists, the corresponding custom function cannot be obtained in the custom function list, indicating that the custom function corresponding to the original data identifier is not stored in the terminal/system. For example (see Table 1): If the original data in the target stress test request is identified as B, C, and D. For the original data identifiers B and C, the corresponding target custom functions Y and Z can be obtained in the list of custom functions. For the original data identifier D, there is no corresponding custom function in the custom function list.
此时,终端/系统会发送提示消息,提醒用户对于该原始数据标识,终端/系统中不存在对应的自定义函数。可选地,提示消息中包括在自定义函数列表中获取不到对应的自定义函数的原始数据标识,以更好地提醒用户。At this point, the terminal/system will send a prompt message to remind the user that there is no corresponding custom function in the terminal/system for the original data identifier. Optionally, the prompt message includes an original data identifier of the corresponding custom function that is not obtained in the custom function list, so as to better remind the user.
S23:获取用户输入的新增自定义函数,作为目标自定义函数。S23: Obtain a new custom function input by the user as a target custom function.
用户在看到终端发送的提示消息后,需要根据该原始数据标识,来编写对应的新增自定义函数,系统在获取到该新增自定义函数之后,将该新增自定义函数作为对应的原始数据标识的目标自定义函数。After seeing the prompt message sent by the terminal, the user needs to write a corresponding new custom function according to the original data identifier. After the system obtains the newly added custom function, the new custom function is used as the corresponding The target custom function for the raw data identification.
在这个实施方式中,通过自定义函数列表来获取对应的目标自定义函数,提高数据的获取效率,并且在不存在对应的自定义函数时,发送提示消息以引导用户编写对应的新增自定义函数,保证压力测试的顺利进行。In this embodiment, the corresponding target custom function is obtained through the custom function list, the data acquisition efficiency is improved, and when there is no corresponding custom function, a prompt message is sent to guide the user to write a corresponding new custom. Function to ensure the smooth progress of the stress test.
在一个具体实施方式中,在获取用户输入的新增自定义函数,作为目标自定义函数的步骤之后,该基于Jmeter的压力测试方法还包括:将新增自定义函数和对应的原始数据标识进行关联,并保存至自定义函数列表中。In a specific implementation, after the step of acquiring a new custom function input by the user as the target custom function, the Jmeter-based stress test method further includes: adding a new custom function and corresponding original data identifier. Associate and save to a list of custom functions.
在这个步骤中,在用户输入新增自定义函数之后,将该新增自定义函数和对应的原始数据标识进行关联,并保存至自定义函数列表中,保证对自定义函数列表的实时更新,以 保证下次测试中出现该原始数据标识时,可以直接获取对应的目标自定义函数,提高了压力测试的效率。In this step, after the user inputs a new custom function, the newly added custom function is associated with the corresponding original data identifier, and saved to the custom function list to ensure real-time update of the custom function list. In order to ensure that the original data identifier appears in the next test, the corresponding target custom function can be directly obtained, thereby improving the efficiency of the stress test.
在一个具体实施方式中,将目标自定义函数封装成BeanShell脚本文件,如图3所示,包括以下步骤:In one embodiment, the target custom function is packaged into a BeanShell script file, as shown in FIG. 3, including the following steps:
S31:获取已有压力测试项目,基于已有压力测试项目获取每一目标自定义函数的平均调用次数。S31: Acquire an existing stress test item, and obtain an average number of calls per target custom function based on the existing stress test item.
其中,已有压力测试项目是指已经完成的压力测试项目。在一个压力测试项目中,每一个自定义函数的调用次数都是不尽相同的,故可以通过查询已有压力测试项目中对应的自定义函数的调用情况,来获取每一目标自定义函数的调用次数。Among them, the existing stress test project refers to the stress test project that has been completed. In a stress test project, the number of calls for each custom function is different, so you can get the target custom function by querying the call of the corresponding custom function in the existing stress test project. The number of calls.
可选地,可以通过获取每一目标自定义函数在每一已有压力测试项目中的调用次数,并对这些调用次数进行求和取平均值,从而得到每一目标自定义函数的平均调用次数。Optionally, the average number of calls per target custom function can be obtained by obtaining the number of calls of each target custom function in each existing stress test item and summing the number of these calls. .
S32:将平均调用次数大于预设次数的目标自定义函数封装成BeanShell脚本文件。S32: Encapsulate the target custom function with the average number of calls greater than the preset number into a BeanShell script file.
在实际的压力测试中,只有调用次数较高的目标自定义函数才会对系统的运行有较大的影响。因此,可以设定一预设次数,判断在已有压力测试项目中使用的自定义函数中,哪些自定义函数在已有压力测试项目的平均调用次数大于预设次数,将这部分自定义函数作为目标自定义函数封装成BeanShell脚本文件。其中,该预设次数可以根据历史测试结果或者实际需要进行设定。In the actual stress test, only the target custom function with a higher number of calls will have a greater impact on the operation of the system. Therefore, a preset number of times can be set to determine which of the custom functions used in the existing stress test items, which custom functions have an average number of calls in the existing stress test items greater than a preset number of times, and this part of the custom function The target custom function is encapsulated into a BeanShell script file. The preset number of times can be set according to historical test results or actual needs.
在这个实施方式中,通过对已有压力测试项目中,每一目标自定义函数的调用次数的获取和计算,得到每一目标自定义函数的平均调用次数,进而将平均调用次数大于预设次数的目标自定义函数封装成BeanShell脚本文件,减轻了终端/系统的负担,也进一步提高了吞吐率。In this embodiment, the average number of calls of each target custom function is obtained by obtaining and calculating the number of calls of each target custom function in the existing stress test item, and then the average number of calls is greater than the preset number of times. The target custom function is packaged into a BeanShell script file, which reduces the burden on the terminal/system and further improves the throughput.
在一个具体实施方式中,目标压力测试请求还包括目标压力测试类型。其中,目标压力测试类型是指目标压力测试请求对应的测试类型。In one embodiment, the target stress test request also includes a target stress test type. The target stress test type refers to the test type corresponding to the target stress test request.
在这个实施方式中,获取已有压力测试项目,包括:获取已有压力测试项目中和目标压力测试类型相同的已有压力测试项目。In this embodiment, an existing stress test item is obtained, including: obtaining an existing stress test item of the same type of stress test item as the target stress test.
压力测试项目可根据不同的测试情况和测试需求分为不同的类型,相同类型的压力测试项目的测试过程是较为相似的。通过获取与目标压力测试类型相同类型的已有压力测试项目,并基于与目标压力测试类型相同类型的已有压力测试项目获取每一目标自定义函数的平均调用次数,以提高数据的准确性。The stress test project can be divided into different types according to different test conditions and test requirements. The test process of the same type of stress test project is relatively similar. The accuracy of the data is improved by obtaining the existing stress test items of the same type as the target stress test type and obtaining the average number of calls per target custom function based on the existing stress test items of the same type as the target stress test type.
在这个实施方式中,通过获取已有压力测试项目中和目标压力测试类型相同的已有压 力测试项目来计算目标自定义函数的平均调用次数,保证了数据的准确性。In this embodiment, the average number of calls of the target custom function is calculated by acquiring an existing pressure test item having the same type as the target stress test in the existing stress test item, thereby ensuring the accuracy of the data.
在一个具体实施方式中,已有压力测试项目包括已有压力测试类型。In one embodiment, the existing stress test items include existing stress test types.
对于不同的已有压力测试项目,可以根据类型的不同对已有压力测试项目进行分类,并通过已有压力测试类型来对不同类型的已有压力测试项目进行区分。For different existing stress test items, existing stress test items can be classified according to different types, and different types of existing stress test items can be distinguished by existing stress test types.
在这个实施方式中,基于已有压力测试项目统计每一目标自定义函数的平均调用次数,如图4所示,包括以下步骤:In this embodiment, the average number of calls per target custom function is counted based on the existing stress test item, as shown in FIG. 4, including the following steps:
S311:统计每一目标自定义函数在每一已有压力测试项目中的调用次数。S311: Count the number of times each target custom function is called in each existing stress test item.
通过查询已有压力测试项目中对应的自定义函数的调用情况,来获取每一目标自定义函数在每一已有压力测试项目中的调用次数。The number of calls of each target custom function in each existing stress test item is obtained by querying the call of the corresponding custom function in the existing stress test item.
S312:基于已有压力测试类型和目标压力测试类型的关联性为每一已有压力测试项目设定对应的权值。S312: Set a corresponding weight for each existing stress test item based on the correlation between the existing stress test type and the target stress test type.
压力测试项目可根据不同的测试情况和测试需求分为不同的类型,相同类型的压力测试项目的测试过程是较为相似的。因此,可以根据已有压力测试类型和目标压力测试类型的关联性来为每一已有压力测试项目设定一对应的权值。关联性越高,相对应的权值就越高。在一个实施方式中,可以设定和目标压力测试类型相同的已有压力测试项目的权值为a,而设定其他和目标压力测试类型不相同的已有压力测试项目的权值为0.5a。The stress test project can be divided into different types according to different test conditions and test requirements. The test process of the same type of stress test project is relatively similar. Therefore, a corresponding weight can be set for each existing stress test item based on the correlation between the existing stress test type and the target stress test type. The higher the relevance, the higher the corresponding weight. In one embodiment, the weight of the existing stress test item of the same type as the target pressure test type can be set to a, and the weight of the existing stress test item of the other type different from the target stress test type is set to 0.5a. .
S313:基于每一已有压力测试项目的权值对每一目标自定义函数在不同的已有压力测试项目中的调用次数进行加权求和再取平均值,得到每一目标自定义函数的平均调用次数。S313: weighting and summing the number of calls of each target custom function in different existing stress test items based on the weight of each existing stress test item, and obtaining an average of each target custom function. The number of calls.
在获取每一目标自定义函数在每一已有压力测试项目中的调用次数之后,再根据为每一已有压力测试项目设定的权值,来对每一目标自定义函数在不同已有压力测试项目中的调用次数进行加权求和再取平均值,即得到每一目标自定义函数的平均调用次数。After obtaining the number of calls for each target custom function in each existing stress test item, and according to the weights set for each existing stress test item, each target custom function is different. The number of calls in the stress test project is weighted and averaged, that is, the average number of calls per target custom function is obtained.
在这个实施方式中,通过根据已有压力测试类型和目标压力测试类型的关联性来为每一已有压力测试项目设定对应的权值,并根据这个设定的权值来计算每一目标自定义函数的平均调用次数,进一步保证了数据的准确性。In this embodiment, a corresponding weight is set for each existing stress test item according to the correlation between the existing stress test type and the target stress test type, and each target is calculated according to the set weight value. The average number of calls to the custom function further ensures the accuracy of the data.
在一个具体实施方式中,调用BeanShell脚本文件中封装的目标自定义函数进行压力测试,如图5所示,还包括以下步骤:In one embodiment, the target custom function encapsulated in the BeanShell script file is invoked for stress testing, as shown in FIG. 5, and the following steps are also included:
S51:启动计数器,统计目标自定义函数的迭代次数。S51: Start the counter and count the number of iterations of the target custom function.
传统地,在Jmeter测试工具中使用BeanShell进行长时间测试时,会打开选项“Reset bsh.Interpreter before each call”,即在每次调用BeanShell程序前,都把解释器重置,以释 放解释器在之前所占用的内存。然而,在解释器重置之后,每次都需要重新加载对应的类,类加载的过程会导致线程的大量阻塞。即通过重制解释器可以释放内存,但是相对地阻塞了线程,导致吞吐率无法提高。Traditionally, when using BeanShell for long-term testing in the Jmeter test harness, the option "Reset bsh.Interpreter before each call" is turned on, which resets the interpreter before each call to the BeanShell program to release the interpreter. The memory used before. However, after the interpreter is reset, the corresponding class needs to be reloaded each time, and the process of class loading causes a large amount of blocking of the thread. That is, by re-executing the interpreter, the memory can be freed, but the thread is relatively blocked, resulting in an inability to increase the throughput.
在该步骤中,通过启动Jmeter中的计数器(Counter),统计在压力测试过程中目标自定义函数的迭代次数。具体地,在Jmeter中,计数器允许用户创建一个在线程组之内都可以被引用的计数器。该计数器允许用户配置一个起点,一个最大值和对应的增量数,此后计数器从起点开始,根据增量数一直循环到最大值。然后,重新开始,持续循环,直到整个压力测试结束。因此,在压力测试过程中,可以为每一目标自定义函数配置对应的计数器,从而统计在压力测试过程中目标自定义函数的迭代次数。In this step, the number of iterations of the target custom function during the stress test is counted by starting the counter in the Jmeter. Specifically, in Jmeter, the counter allows the user to create a counter that can be referenced within the thread group. This counter allows the user to configure a starting point, a maximum value and a corresponding number of increments, after which the counter starts at the starting point and continues to the maximum value according to the number of increments. Then, start over and continue to cycle until the end of the stress test. Therefore, during the stress test, the corresponding counter can be configured for each target custom function to count the number of iterations of the target custom function during the stress test.
S52:若任一目标自定义函数的迭代次数大于迭代阈值,则重置解释器。S52: If the number of iterations of any target custom function is greater than an iteration threshold, the interpreter is reset.
通过计数器统计每一目标自定义函数在压力测试过程中的迭代次数,若任一目标自定义函数的迭代次数大于迭代阈值,则进行解释器重置,以释放内存,避免内存泄漏。The counter counts the number of iterations of each target custom function during the stress test. If the number of iterations of any target custom function is greater than the iteration threshold, the interpreter is reset to free memory and avoid memory leaks.
在这个实施方式中,通过采用计数器对每一目标自定义函数的迭代次数进行统计,若任一目标自定义函数的迭代次数大于迭代阈值,则重置解释器,避免内存泄漏,进一步避免线程阻塞,提高终端/系统的吞吐率。In this embodiment, the number of iterations of each target custom function is counted by using a counter. If the number of iterations of any target custom function is greater than the iteration threshold, the interpreter is reset to avoid memory leakage and further avoid thread blocking. Improve the throughput of the terminal/system.
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that the size of the sequence of the steps in the above embodiments does not mean that the order of execution is performed. The order of execution of each process should be determined by its function and internal logic, and should not be construed as limiting the implementation process of the embodiments of the present application.
实施例2Example 2
图6示出与实施例1中基于Jmeter的压力测试方法一一对应的基于Jmeter的压力测试装置的原理框图。如图6所示,该基于Jmeter的压力测试装置包括目标压力测试请求获取模块10、目标自定义函数获取模块20、目标自定义函数封装模块30、初始化模块40和压力测试模块50。其中,目标压力测试请求获取模块10、目标自定义函数获取模块20、目标自定义函数封装模块30、初始化模块40和压力测试模块50的实现功能与实施例1中基于Jmeter的压力测试方法对应的步骤一一对应,为避免赘述,本实施例不一一详述。Fig. 6 is a block diagram showing the principle of a Jmeter-based pressure testing device corresponding to the Jmeter-based pressure testing method in the first embodiment. As shown in FIG. 6, the Jmeter-based stress testing device includes a target stress test request acquisition module 10, a target custom function acquisition module 20, a target custom function packaging module 30, an initialization module 40, and a stress test module 50. The implementation functions of the target stress test request acquisition module 10, the target custom function acquisition module 20, the target custom function encapsulation module 30, the initialization module 40, and the stress test module 50 correspond to the Jmeter-based stress test method in Embodiment 1. The steps are one-to-one correspondence, and the details are not described in detail in order to avoid redundancy.
目标压力测试请求获取模块10,用于获取目标压力测试请求,目标压力测试请求包括至少一个原始数据标识。The target stress test request acquisition module 10 is configured to obtain a target stress test request, and the target stress test request includes at least one original data identifier.
目标自定义函数获取模块20,用于基于至少一个原始数据标识,获取对应的目标自定义函数,其中,目标自定义函数为未进行类封装的函数。The target custom function obtaining module 20 is configured to obtain a corresponding target custom function based on the at least one original data identifier, wherein the target custom function is a function that is not encapsulated by the class.
目标自定义函数封装模块30,用于将目标自定义函数封装成BeanShell脚本文件。The target custom function encapsulation module 30 is configured to encapsulate the target custom function into a BeanShell script file.
初始化模块40,用于对BeanShell脚本文件进行初始化。The initialization module 40 is configured to initialize the BeanShell script file.
压力测试模块50,用于调用BeanShell脚本文件中封装的目标自定义函数进行压力测 试。The stress test module 50 is configured to invoke a target custom function encapsulated in the BeanShell script file for stress testing.
优选地,目标自定义函数获取模块20包括目标自定义函数获取单元21、提示消息发送单元22和新增自定义函数获取单元23。Preferably, the target custom function acquisition module 20 includes a target custom function acquisition unit 21, a prompt message transmission unit 22, and a new custom function acquisition unit 23.
目标自定义函数获取单元21,用于基于至少一个原始数据标识,获取自定义函数列表中和原始数据标识对应的自定义函数,作为目标自定义函数。The target custom function obtaining unit 21 is configured to obtain, according to the at least one original data identifier, a custom function corresponding to the original data identifier in the custom function list as the target custom function.
提示消息发送单元22,用于若存在任一原始数据标识,在自定义函数列表中获取不到对应的自定义函数,则发送提示消息。The prompt message sending unit 22 is configured to send a prompt message if any original function is not obtained in the custom function list if any original data identifier exists.
新增自定义函数获取单元23,用于获取用户输入的新增自定义函数,作为目标自定义函数。A new custom function obtaining unit 23 is configured to obtain a newly added custom function input by the user as a target custom function.
优选地,目标自定义函数获取模块20还包括新增自定义函数关联单元24。Preferably, the target custom function obtaining module 20 further includes a new custom function associating unit 24.
新增自定义函数关联单元24,用于将新增自定义函数和对应的原始数据标识进行关联,并保存至自定义函数列表中。A new custom function association unit 24 is added to associate the newly added custom function with the corresponding original data identifier and save it to the custom function list.
优选地,目标自定义函数封装模块30包括平均调用次数获取单元31和目标自定义函数封装单元32。Preferably, the target custom function encapsulation module 30 includes an average call count acquisition unit 31 and a target custom function encapsulation unit 32.
平均调用次数获取单元31,用于获取已有压力测试项目,基于已有压力测试项目获取每一目标自定义函数的平均调用次数。The average call count obtaining unit 31 is configured to acquire an existing stress test item, and obtain an average number of calls of each target custom function based on the existing stress test item.
目标自定义函数封装单元32,用于将平均调用次数大于预设次数的目标自定义函数封装成BeanShell脚本文件。The target custom function encapsulating unit 32 is configured to encapsulate the target custom function whose average number of calls is greater than the preset number of times into a BeanShell script file.
优选地,目标压力测试请求还包括目标压力测试类型。平均调用次数获取单元31还用于获取已有压力测试项目中和目标压力测试类型相同的已有压力测试项目。Preferably, the target stress test request further includes a target stress test type. The average call count obtaining unit 31 is further configured to acquire an existing stress test item of the same type of the target stress test in the existing stress test item.
优选地,已有压力测试项目包括已有压力测试类型。平均调用次数获取单元31包括调用次数统计子单元311、权值设定子单元312和平均调用次数获取子单元313。Preferably, existing stress test items include existing stress test types. The average call count acquisition unit 31 includes a call count count sub-unit 311, a weight value setting sub-unit 312, and an average call count acquisition sub-unit 313.
调用次数统计子单元311,用于统计每一目标自定义函数在每一已有压力测试项目中的调用次数。The call count statistics sub-unit 311 is configured to count the number of calls of each target custom function in each existing stress test item.
权值设定子单元312,用于基于已有压力测试类型和目标压力测试类型的关联性为每一已有压力测试项目设定对应的权值。The weight setting sub-unit 312 is configured to set a corresponding weight for each existing stress test item based on the correlation between the existing stress test type and the target stress test type.
平均调用次数获取子单元313,用于基于每一已有压力测试项目的权值对每一目标自定义函数在不同的已有压力测试项目中的调用次数进行加权求和再取平均值,得到每一目标自定义函数的平均调用次数。The average call count acquisition sub-unit 313 is configured to perform weighted summation and average the call times of each target custom function in different existing stress test items based on the weight of each existing stress test item, and obtain an average value The average number of calls per target custom function.
优选地,压力测试模块50包括迭代次数统计单元51和解释器重置单元52。Preferably, the stress test module 50 includes an iteration count statistic unit 51 and an interpreter reset unit 52.
迭代次数统计单元51,用于启动计数器,统计目标自定义函数的迭代次数。The iteration count statistic unit 51 is configured to start a counter and count the number of iterations of the target custom function.
解释器重置单元52,用于若任一目标自定义函数的迭代次数大于迭代阈值,则重置解释器。The interpreter reset unit 52 is configured to reset the interpreter if the number of iterations of any of the target custom functions is greater than an iteration threshold.
实施例3Example 3
本实施例提供一个或多个存储有计算机可读指令的非易失性可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如实施例1中基于Jmeter的压力测试方法的步骤,为避免重复,这里不再赘述。或者,该计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器实现如实施例2中基于Jmeter的压力测试装置中各模块/单元的功能,为避免重复,这里不再赘述。The embodiment provides one or more non-volatile readable storage media having computer readable instructions that, when executed by one or more processors, cause the one or more processors to execute The steps of the Jmeter-based stress test method in Embodiment 1 are not repeated here to avoid repetition. Alternatively, when the computer readable instructions are executed by one or more processors, causing the one or more processors to implement the functions of the modules/units in the Jmeter based stress testing device of Embodiment 2, to avoid duplication, I won't go into details here.
可以理解地,所述非易失性可读存储介质可以包括:能够携带所述计算机可读指令代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号和电信信号等。It is to be understood that the non-volatile readable storage medium may include any entity or device capable of carrying the computer readable instruction code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, only Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier signals, and telecommunications signals.
实施例4Example 4
图7是本申请一实施例提供的计算机设备的示意图。如图7所示,该实施例的计算机设备60包括:处理器61、存储器62以及存储在存储器62中并可在处理器61上运行的计算机可读指令63。处理器61执行计算机可读指令63时实现上述实施例1中基于Jmeter的压力测试方法的步骤,例如图1所示的步骤S10至S50。或者,处理器61执行计算机可读指令63时实现上述各装置实施例中各模块/单元的功能,例如图6所示的目标压力测试请求获取模块10、目标自定义函数获取模块20、目标自定义函数封装模块30、初始化模块40和压力测试模块50的功能。FIG. 7 is a schematic diagram of a computer device according to an embodiment of the present application. As shown in FIG. 7, computer device 60 of this embodiment includes a processor 61, a memory 62, and computer readable instructions 63 stored in memory 62 and executable on processor 61. The processor 61 performs the steps of the Jmeter-based stress test method of Embodiment 1 described above when executing the computer readable instructions 63, such as steps S10 to S50 shown in FIG. Alternatively, when the processor 61 executes the computer readable instructions 63, the functions of the modules/units in the foregoing device embodiments are implemented, such as the target stress test request acquisition module 10, the target custom function acquisition module 20, and the target self shown in FIG. The functions of function encapsulation module 30, initialization module 40, and stress test module 50 are defined.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。It will be apparent to those skilled in the art that, for convenience and brevity of description, only the division of each functional unit and module described above is exemplified. In practical applications, the above functions may be assigned to different functional units as needed. The module is completed by dividing the internal structure of the device into different functional units or modules to perform all or part of the functions described above.
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。The above-mentioned embodiments are only used to explain the technical solutions of the present application, and are not limited thereto; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still implement the foregoing embodiments. The technical solutions described in the examples are modified or equivalently replaced with some of the technical features; and the modifications or substitutions do not deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in Within the scope of protection of this application.

Claims (20)

  1. 一种基于Jmeter的压力测试方法,其特征在于,包括:A Jmeter-based stress testing method, comprising:
    获取目标压力测试请求,所述目标压力测试请求包括至少一个原始数据标识;Obtaining a target stress test request, the target stress test request including at least one original data identifier;
    基于至少一个所述原始数据标识,获取对应的目标自定义函数,其中,所述目标自定义函数为未进行类封装的函数;And acquiring, according to the at least one original data identifier, a corresponding target custom function, where the target custom function is a function that is not encapsulated by the class;
    将所述目标自定义函数封装成BeanShell脚本文件;Encapsulating the target custom function into a BeanShell script file;
    对所述BeanShell脚本文件进行初始化;Initializing the BeanShell script file;
    调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。Call the target custom function encapsulated in the BeanShell script file for stress testing.
  2. 如权利要求1所述的基于Jmeter的压力测试方法,其特征在于,所述基于至少一个所述原始数据标识,获取对应的目标自定义函数,包括以下步骤:The Jmeter-based stress testing method according to claim 1, wherein the obtaining the corresponding target custom function based on the at least one of the original data identifiers comprises the following steps:
    基于至少一个所述原始数据标识,获取自定义函数列表中和所述原始数据标识对应的自定义函数,作为目标自定义函数;Obtaining, according to the at least one of the original data identifiers, a custom function corresponding to the original data identifier in the custom function list, as a target custom function;
    若存在任一所述原始数据标识,在自定义函数列表中获取不到对应的自定义函数,则发送提示消息;If any of the original data identifiers are present, a corresponding custom function is not obtained in the custom function list, and a prompt message is sent;
    获取用户输入的新增自定义函数,作为目标自定义函数。Get the new custom function entered by the user as the target custom function.
  3. 如权利要求2所述的基于Jmeter的压力测试方法,其特征在于,在所述获取用户输入的新增自定义函数,作为目标自定义函数的步骤之后,所述压力测试方法还包括:The Jmeter-based stress testing method according to claim 2, wherein after the step of acquiring a newly added custom function input by the user as a target custom function, the stress testing method further comprises:
    将所述新增自定义函数和对应的所述原始数据标识进行关联,并保存至所述自定义函数列表中。The newly added custom function is associated with the corresponding original data identifier and saved in the custom function list.
  4. 如权利要求1所述的基于Jmeter的压力测试方法,其特征在于,所述将所述目标自定义函数封装成BeanShell脚本文件,具体包括以下步骤:The Jmeter-based stress testing method according to claim 1, wherein the encapsulating the target custom function into a BeanShell script file comprises the following steps:
    获取已有压力测试项目,基于已有压力测试项目获取每一目标自定义函数的平均调用次数;Obtain an existing stress test project, and obtain an average number of calls per target custom function based on an existing stress test project;
    将平均调用次数大于预设次数的目标自定义函数封装成所述BeanShell脚本文件。A target custom function with an average number of calls greater than a preset number of times is packaged into the BeanShell script file.
  5. 如权利要求4所述的基于Jmeter的压力测试方法,其特征在于,所述目标压力测试请求还包括目标压力测试类型;The Jmeter-based stress testing method according to claim 4, wherein the target stress test request further comprises a target stress test type;
    所述获取已有压力测试项目,包括:获取已有压力测试项目中和所述目标压力测试类型相同的已有压力测试项目。The obtaining the existing stress test item comprises: acquiring an existing stress test item of the same type of the stress test item and the target stress test type.
  6. 如权利要求4所述的基于Jmeter的压力测试方法,其特征在于,所述已有压力测试 项目包括已有压力测试类型;The Jmeter-based stress testing method according to claim 4, wherein said existing stress test item comprises an existing stress test type;
    所述基于已有压力测试项目统计每一目标自定义函数的平均调用次数,具体包括以下步骤:The calculating the average number of calls of each target custom function based on the existing stress test item includes the following steps:
    统计每一目标自定义函数在每一所述已有压力测试项目中的调用次数;Counting the number of calls per target custom function in each of the existing stress test items;
    基于所述已有压力测试类型和所述目标压力测试类型的关联性为每一所述已有压力测试项目设定对应的权值;And setting a corresponding weight for each of the existing stress test items based on the correlation between the existing stress test type and the target stress test type;
    基于每一所述已有压力测试项目的权值对每一所述目标自定义函数在不同的已有压力测试项目中的调用次数进行加权求和再取平均值,得到每一所述目标自定义函数的平均调用次数。Weighting and summing the number of calls of each of the target custom functions in different existing stress test items based on the weight of each of the existing stress test items, and obtaining an average of each of the target targets Defines the average number of calls to the function.
  7. 如权利要求5所述的基于Jmeter的压力测试方法,其特征在于,所述调用BeanShell脚本文件中封装的目标自定义函数进行压力测试,所述压力测试方法还包括:The Jmeter-based stress testing method according to claim 5, wherein the target custom function encapsulated in the BeanShell script file is used to perform a stress test, and the stress testing method further includes:
    启动计数器,统计所述目标自定义函数的迭代次数;Starting a counter to count the number of iterations of the target custom function;
    若任一所述目标自定义函数的迭代次数大于迭代阈值,则重置解释器。If the number of iterations of any of the target custom functions is greater than the iteration threshold, the interpreter is reset.
  8. 一种基于Jmeter的压力测试装置,其特征在于,包括:A Jmeter-based pressure testing device, comprising:
    目标压力测试请求获取模块,用于获取目标压力测试请求,所述目标压力测试请求包括至少一个原始数据标识;a target stress test request obtaining module, configured to acquire a target stress test request, where the target stress test request includes at least one original data identifier;
    目标自定义函数获取模块,用于基于至少一个所述原始数据标识,获取对应的目标自定义函数,其中,所述目标自定义函数为未进行类封装的函数;a target custom function obtaining module, configured to acquire a corresponding target custom function based on at least one of the original data identifiers, wherein the target custom function is a function that is not encapsulated by a class;
    目标自定义函数封装模块,用于将所述目标自定义函数封装成BeanShell脚本文件;a target custom function encapsulation module, configured to encapsulate the target custom function into a BeanShell script file;
    初始化模块,用于对所述BeanShell脚本文件进行初始化;An initialization module, configured to initialize the BeanShell script file;
    压力测试模块,用于调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。The stress test module is used to invoke the target custom function encapsulated in the BeanShell script file for stress testing.
  9. 一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,其特征在于,所述处理器执行所述计算机可读指令时实现如下步骤:A computer device comprising a memory, a processor, and computer readable instructions stored in the memory and operative on the processor, wherein the processor executes the computer readable instructions as follows step:
    获取目标压力测试请求,所述目标压力测试请求包括至少一个原始数据标识;Obtaining a target stress test request, the target stress test request including at least one original data identifier;
    基于至少一个所述原始数据标识,获取对应的目标自定义函数,其中,所述目标自定义函数为未进行类封装的函数;And acquiring, according to the at least one original data identifier, a corresponding target custom function, where the target custom function is a function that is not encapsulated by the class;
    将所述目标自定义函数封装成BeanShell脚本文件;Encapsulating the target custom function into a BeanShell script file;
    对所述BeanShell脚本文件进行初始化;Initializing the BeanShell script file;
    调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。Call the target custom function encapsulated in the BeanShell script file for stress testing.
  10. 若权利要求9所述的计算机设备,其特征在于,所述基于至少一个所述原始数据标识,获取对应的目标自定义函数,包括以下步骤:The computer device according to claim 9, wherein the obtaining the corresponding target custom function based on the at least one of the original data identifiers comprises the following steps:
    基于至少一个所述原始数据标识,获取自定义函数列表中和所述原始数据标识对应的自定义函数,作为目标自定义函数;Obtaining, according to the at least one of the original data identifiers, a custom function corresponding to the original data identifier in the custom function list, as a target custom function;
    若存在任一所述原始数据标识,在自定义函数列表中获取不到对应的自定义函数,则发送提示消息;If any of the original data identifiers are present, a corresponding custom function is not obtained in the custom function list, and a prompt message is sent;
    获取用户输入的新增自定义函数,作为目标自定义函数。Get the new custom function entered by the user as the target custom function.
  11. 如权利要求10所述的计算机设备,其特征在于,在所述获取用户输入的新增自定义函数,作为目标自定义函数的步骤之后,所述处理器执行所述计算机可读指令时还实现如下步骤:A computer apparatus according to claim 10, wherein said processor executes said computer readable instructions after said step of obtaining a newly added custom function input by a user as a target custom function The following steps:
    将所述新增自定义函数和对应的所述原始数据标识进行关联,并保存至所述自定义函数列表中。The newly added custom function is associated with the corresponding original data identifier and saved in the custom function list.
  12. 如权利要求9所述的计算机设备,其特征在于,所述将所述目标自定义函数封装成BeanShell脚本文件,具体包括以下步骤:The computer device according to claim 9, wherein the encapsulating the target custom function into a BeanShell script file comprises the following steps:
    获取已有压力测试项目,基于已有压力测试项目获取每一目标自定义函数的平均调用次数;Obtain an existing stress test project, and obtain an average number of calls per target custom function based on an existing stress test project;
    将平均调用次数大于预设次数的目标自定义函数封装成所述BeanShell脚本文件。A target custom function with an average number of calls greater than a preset number of times is packaged into the BeanShell script file.
  13. 如权利要求12所述的计算机设备,其特征在于,所述目标压力测试请求还包括目标压力测试类型;The computer apparatus according to claim 12, wherein said target stress test request further comprises a target stress test type;
    所述获取已有压力测试项目,包括:获取已有压力测试项目中和所述目标压力测试类型相同的已有压力测试项目。The obtaining the existing stress test item comprises: acquiring an existing stress test item of the same type of the stress test item and the target stress test type.
  14. 如权利要求12所述的计算机设备,其特征在于,所述已有压力测试项目包括已有压力测试类型;The computer apparatus according to claim 12, wherein said existing stress test item comprises an existing stress test type;
    所述基于已有压力测试项目统计每一目标自定义函数的平均调用次数,具体包括以下步骤:The calculating the average number of calls of each target custom function based on the existing stress test item includes the following steps:
    统计每一目标自定义函数在每一所述已有压力测试项目中的调用次数;Counting the number of calls per target custom function in each of the existing stress test items;
    基于所述已有压力测试类型和所述目标压力测试类型的关联性为每一所述已有压力测试项目设定对应的权值;And setting a corresponding weight for each of the existing stress test items based on the correlation between the existing stress test type and the target stress test type;
    基于每一所述已有压力测试项目的权值对每一所述目标自定义函数在不同的已有压力测试项目中的调用次数进行加权求和再取平均值,得到每一所述目标自定义函数的平均 调用次数。Weighting and summing the number of calls of each of the target custom functions in different existing stress test items based on the weight of each of the existing stress test items, and obtaining an average of each of the target targets Defines the average number of calls to the function.
  15. 如权利要求13所述的计算机设备,其特征在于,所述调用BeanShell脚本文件中封装的目标自定义函数进行压力测试,还包括:The computer device according to claim 13, wherein said calling a custom function encapsulated in a BeanShell script file performs stress testing, and further comprising:
    启动计数器,统计所述目标自定义函数的迭代次数;Starting a counter to count the number of iterations of the target custom function;
    若任一所述目标自定义函数的迭代次数大于迭代阈值,则重置解释器。If the number of iterations of any of the target custom functions is greater than the iteration threshold, the interpreter is reset.
  16. 一个或多个存储有计算机可读指令的非易失性可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:One or more non-transitory readable storage mediums storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the following steps:
    获取目标压力测试请求,所述目标压力测试请求包括至少一个原始数据标识;Obtaining a target stress test request, the target stress test request including at least one original data identifier;
    基于至少一个所述原始数据标识,获取对应的目标自定义函数,其中,所述目标自定义函数为未进行类封装的函数;And acquiring, according to the at least one original data identifier, a corresponding target custom function, where the target custom function is a function that is not encapsulated by the class;
    将所述目标自定义函数封装成BeanShell脚本文件;Encapsulating the target custom function into a BeanShell script file;
    对所述BeanShell脚本文件进行初始化;Initializing the BeanShell script file;
    调用BeanShell脚本文件中封装的目标自定义函数进行压力测试。Call the target custom function encapsulated in the BeanShell script file for stress testing.
  17. 若权利要求16所述的非易失性可读存储介质,其特征在于,所述基于至少一个所述原始数据标识,获取对应的目标自定义函数,包括以下步骤:The non-volatile readable storage medium of claim 16, wherein the obtaining the corresponding target custom function based on the at least one of the original data identifiers comprises the following steps:
    基于至少一个所述原始数据标识,获取自定义函数列表中和所述原始数据标识对应的自定义函数,作为目标自定义函数;Obtaining, according to the at least one of the original data identifiers, a custom function corresponding to the original data identifier in the custom function list, as a target custom function;
    若存在任一所述原始数据标识,在自定义函数列表中获取不到对应的自定义函数,则发送提示消息;If any of the original data identifiers are present, a corresponding custom function is not obtained in the custom function list, and a prompt message is sent;
    获取用户输入的新增自定义函数,作为目标自定义函数。Get the new custom function entered by the user as the target custom function.
  18. 如权利要求17所述的非易失性可读存储介质,其特征在于,在所述获取用户输入的新增自定义函数,作为目标自定义函数的步骤之后,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器还执行如下步骤:The non-volatile readable storage medium according to claim 17, wherein said computer readable instruction is followed by said step of acquiring a newly added custom function input by a user as a target custom function When the plurality of processors are executed, the one or more processors are further configured to perform the following steps:
    将所述新增自定义函数和对应的所述原始数据标识进行关联,并保存至所述自定义函数列表中。The newly added custom function is associated with the corresponding original data identifier and saved in the custom function list.
  19. 如权利要求16所述的非易失性可读存储介质,其特征在于,所述将所述目标自定义函数封装成BeanShell脚本文件,具体包括以下步骤:The non-volatile readable storage medium of claim 16, wherein the encapsulating the target custom function into a BeanShell script file comprises the following steps:
    获取已有压力测试项目,基于已有压力测试项目获取每一目标自定义函数的平均调用次数;Obtain an existing stress test project, and obtain an average number of calls per target custom function based on an existing stress test project;
    将平均调用次数大于预设次数的目标自定义函数封装成所述BeanShell脚本文件。A target custom function with an average number of calls greater than a preset number of times is packaged into the BeanShell script file.
  20. 如权利要求19所述的非易失性可读存储介质,其特征在于,所述目标压力测试请求还包括目标压力测试类型;The non-volatile readable storage medium of claim 19, wherein the target stress test request further comprises a target stress test type;
    所述获取已有压力测试项目,包括:获取已有压力测试项目中和所述目标压力测试类型相同的已有压力测试项目。The obtaining the existing stress test item comprises: acquiring an existing stress test item of the same type of the stress test item and the target stress test type.
PCT/CN2018/092636 2018-03-22 2018-06-25 Jmeter-based stress testing method and apparatus, and device and storage medium WO2019178967A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810239745.1A CN108572916B (en) 2018-03-22 2018-03-22 Pressure testing method, device, equipment and storage medium based on Jmeter
CN201810239745.1 2018-03-22

Publications (1)

Publication Number Publication Date
WO2019178967A1 true WO2019178967A1 (en) 2019-09-26

Family

ID=63574571

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/092636 WO2019178967A1 (en) 2018-03-22 2018-06-25 Jmeter-based stress testing method and apparatus, and device and storage medium

Country Status (2)

Country Link
CN (1) CN108572916B (en)
WO (1) WO2019178967A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112069078A (en) * 2020-09-15 2020-12-11 平安银行股份有限公司 ESA interface pressure testing method, device, testing equipment and storage medium
CN113671929A (en) * 2021-07-09 2021-11-19 江铃汽车股份有限公司 Automobile fault data recording device and method based on CAN communication
CN114077449A (en) * 2020-08-20 2022-02-22 网联清算有限公司 Database server testing method and device, electronic equipment and storage medium

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109542770A (en) * 2018-10-26 2019-03-29 大唐微电子技术有限公司 A kind of method, apparatus of function call, computer storage medium and terminal
CN109582303B (en) * 2018-10-31 2024-05-03 平安科技(深圳)有限公司 General component calling method, device, computer equipment and storage medium
CN109656791B (en) * 2018-11-01 2022-07-12 奇安信科技集团股份有限公司 gPC performance test method and device based on Jmeter
CN110175131A (en) * 2019-04-29 2019-08-27 合肥移瑞通信技术有限公司 A kind of script management method and system based on PyQt kit
CN111427793A (en) * 2020-04-01 2020-07-17 中电万维信息技术有限责任公司 Automatic Jmeter script generation method

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103399814A (en) * 2013-07-16 2013-11-20 西安Tcl软件开发有限公司 Automated testing method and automated testing device
CN105204849A (en) * 2015-08-27 2015-12-30 努比亚技术有限公司 Pressure test system and implementation method thereof
CN107608901A (en) * 2017-10-20 2018-01-19 北京京东金融科技控股有限公司 Method of testing and device based on Jmteter, storage medium, electronic equipment

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102521120B (en) * 2011-11-16 2014-11-12 中国民航信息网络股份有限公司 Software automation test system and method
CN103729361A (en) * 2012-10-12 2014-04-16 百度在线网络技术(北京)有限公司 Method and device for testing performance of database
US20150113331A1 (en) * 2013-10-17 2015-04-23 Wipro Limited Systems and methods for improved software testing project execution
CN106201862B (en) * 2015-05-25 2019-03-15 阿里巴巴集团控股有限公司 Web services method for testing pressure and device
CN106815142A (en) * 2015-12-02 2017-06-09 北京奇虎科技有限公司 A kind of method for testing software and system
US10387656B2 (en) * 2016-03-21 2019-08-20 Checkmarx Ltd. Integrated interactive application security testing
CN107092559A (en) * 2017-04-18 2017-08-25 携程旅游信息技术(上海)有限公司 Test platform middleware, test system and method based on Jmeter
CN107102947B (en) * 2017-05-12 2020-08-04 中国工商银行股份有限公司 ATM transaction flow testing device and method
CN107704568B (en) * 2017-09-29 2019-03-26 马上消费金融股份有限公司 A kind of method and device of test data addition

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103399814A (en) * 2013-07-16 2013-11-20 西安Tcl软件开发有限公司 Automated testing method and automated testing device
CN105204849A (en) * 2015-08-27 2015-12-30 努比亚技术有限公司 Pressure test system and implementation method thereof
CN107608901A (en) * 2017-10-20 2018-01-19 北京京东金融科技控股有限公司 Method of testing and device based on Jmteter, storage medium, electronic equipment

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114077449A (en) * 2020-08-20 2022-02-22 网联清算有限公司 Database server testing method and device, electronic equipment and storage medium
CN114077449B (en) * 2020-08-20 2023-08-01 网联清算有限公司 Database server testing method and device, electronic equipment and storage medium
CN112069078A (en) * 2020-09-15 2020-12-11 平安银行股份有限公司 ESA interface pressure testing method, device, testing equipment and storage medium
CN112069078B (en) * 2020-09-15 2024-03-19 平安银行股份有限公司 ESA interface pressure test method, ESA interface pressure test device, ESA interface pressure test equipment and storage medium
CN113671929A (en) * 2021-07-09 2021-11-19 江铃汽车股份有限公司 Automobile fault data recording device and method based on CAN communication
CN113671929B (en) * 2021-07-09 2022-09-23 江铃汽车股份有限公司 Automobile fault data recording device and method based on CAN communication

Also Published As

Publication number Publication date
CN108572916A (en) 2018-09-25
CN108572916B (en) 2021-09-28

Similar Documents

Publication Publication Date Title
WO2019178967A1 (en) Jmeter-based stress testing method and apparatus, and device and storage medium
US20190324772A1 (en) Method and device for processing smart contracts
US7469362B2 (en) Using a call stack hash to record the state of a process
CN109302522A (en) Test method, device and computer system and medium
CN110058864B (en) Micro-service deployment method and device
US11709703B2 (en) Automated semantic tagging
US9117030B2 (en) System and method to predict elapsed response time for a query during application development stage
CN110059068B (en) Data verification method and data verification system in distributed storage system
CN106649120A (en) Data acquisition method, and data analysis method and system
US20240121261A1 (en) Automated Security Analysis of Software Libraries
WO2019075994A1 (en) Method, device and system for mock data at ios end, and storage medium
CN111897724A (en) Automatic testing method and device suitable for cloud platform
CN110413442A (en) Parameter verification method and apparatus
US9442818B1 (en) System and method for dynamic data collection
CN111221721B (en) Automatic recording and executing method and device for unit test cases
CN108427634A (en) Electronic device, the method for test and computer readable storage medium
CN113127314B (en) Method and device for detecting program performance bottleneck and computer equipment
KR102132449B1 (en) Method and apparatus for testing javascript interpretation engine based on rewriting
CN110147313A (en) A kind of log-output method and device
CN114443337A (en) JS-based log analysis method and device, electronic equipment and media
CN109308256B (en) Dynamic analysis method, equipment and storage medium for java program
CN112667490A (en) Performance test method and device based on hook function
CN110442508A (en) Test assignment processing method, device, equipment and medium
CN110633214A (en) Configuration method and device of internal test message
CN116010112B (en) Method and device for calling hook function, computer equipment and readable storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18910305

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18910305

Country of ref document: EP

Kind code of ref document: A1