Article directory
- foreword
- 1. Concept principle
-
- 1.1 Principle of JMeter
- 1.2 Performance Test Terminology
- 1.3 web project performance standards
- 2. Common components
-
- 2.1 Thread Group
- 2.2 Sampler
- 2.3 Controller
- 2.4 Timers
- 2.5 Pre/Post Processor
- 2.6 Configuration elements
- 2.7 Listeners
- 3. Plug-ins
-
- 3.1 Third-party plug-ins
- 3.2 Recording plug-ins
- 4. JSR223 scripts and functions
-
- 4.1 JSR223 scripts
- 4.2 Function variables
- 5. Actual cases
-
- 5.1 Login pressure test
- 5.2 Database pressure test
- refer to
Foreword
? Apache JMeter is an open source Java application used for performance testing of software. It was originally designed for web application testing, but has since expanded to other testing areas. It can be used to test static and dynamic resources such as static files, Java servlets, CGI scripts, Java objects, databases, FTP servers, and more.
? JMeter provides a graphical user interface that allows testers to easily create and run test plans and view test results. JMeter can also simulate a variety of load types, including static and dynamic resources such as files, images, videos, databases, etc.
Official document address: https://jmeter.apache.org/usermanual/
github address: https://github.com/apache/jmeter
1. Concept principle
1.1 Jmeter principle
The basic principle of Jmeter is to establish a thread pool, run the sampler in multiple threads to simulate user requests, verify the correctness of the results through assertions, and finally record the test results through the listener.
- X1-X5 These components are used to simulate user actions
- Y1 is responsible for simulating user requests, and Y2 is responsible for verifying that the results are correct
- Z is responsible for the collection of results
The overall sequence of execution is:
- configuration element
- Preprocessor
- timer
- sampler
- post processor
- assertion
- listener
If a controller is added, the execution order is also related to the controller and scope
1.2 Performance testing terms
Terms | Meaning | Remarks |
---|---|---|
Pressure testing | is a test method used to test the performance of the system under high load | By simulating a large number of users accessing the system, you can test the stability, reliability and response time of the system under high load. |
Concurrent number | Generally speaking, it refers to the number of concurrent users. The number of users whose requests are being processed by the system at the same time. | In addition to the number of concurrent connections, each user may open multiple connections, so the number of concurrent connections may be greater than the number of concurrent users. |
Throughput | The number of requests processed by the system per unit time | |
QPS | Queries Per Second | |
TPS | Transactions Per Second, the number of transactions processed per second | For a single interface, TPS can be considered equivalent to QPS. For example, accessing a page /index.html is a TPS, and accessing the /index.html page may request 3 Secondary servers such as css, js, and index interfaces generate 3 QPS. |
RT | Response Time, representing the time from when the client initiates the request to when the server receives the request and responds to all The time difference of data | Generally take the average response time. |
PV | Page View, that is, page views, refers to the website or application within a certain period of time Number of visits |
1.3 web project performance standards
The following are general Internet server performance criteria
Dimension | Not passed | Passed |
---|---|---|
Timeout probability | > 0.5‰ | <0.5‰ |
Error Probability | > 0.5‰ | <0.5‰ |
TPS | > expect high peak |
|
CPU utilization | > 75% | <75% |
Response event | > Greater than expected time | |
Load | Average load per core CPU > 1 | Average load per core CPU < 1 |
JVM memory usage | > 75% | < 75% |
Full GC Frequency | average < 0.5h1 times | average> 0.5h1 times |
2. Common components
Common components of JMeter are as follows:
- Thread group: It is used to simulate the situation that users access the system concurrently, and parameters such as the number of threads and the number of cycles can be set.
- Sampler: The component that actually accesses the system in Jmeter, which belongs to the thread group
- Controller: used to control the execution sequence and the number of iterations of each element in the test plan.
- Timer: used to simulate the user’s behavior when executing the test plan, for example, waiting for a period of time before executing the next request.
- Pre/Post Processors: Simulate user behavior while executing the test plan. A pre-processor can perform actions before issuing a Sampler Request, such as modifying the settings of a Sampler Request or updating variables not extracted from the response text. Post-processors can perform actions after a sampler request, such as extracting variables in the response text or writing response data to a file.
- Configuration elements: closely related to samplers, requests can be added or modified
- Listener: used to collect and display test results, such as response time, response code, response message, etc.
For the unknown options in the component, you can access the Internet for document query through Help in the menu bar
2.1 Thread group
The following are some parameter configuration items explained:
-
Ramp-Up time
How long does JMeter take to start all threads. If there are 10 threads with a Ramp-Up time of 100 seconds, then each thread will start within 10 seconds of the previous thread starting, for a total time of 100 seconds (the first thread is always started directly) to make the test fully up to speed.
-
Defer thread creation until needed
If ticked, threads will only be created when an appropriate proportion of the boost time has elapsed. This is best suited for tests that have boost times that are much longer than the execution time of a single thread. That is, earlier threads end before later threads start. If not selected, all threads will be created at the start of the test (then they will be paused for the appropriate proportion of boost time).
-
Scheduler (Duration)
If checked, you can configure and choose a relative end time. JMeter will use this to calculate the end time.
2.2 Sampler
Each sampler produces one or more sample results with various attributes (success/failure, elapsed time, data size, etc.) and can be watched in different Listeners. Jmeter provides many samplers: as follows
The most common is the Http request
-
Agreement
Optional HTTP, HTTPS, FILE
-
Content-Encoding
The content-encoding to use (for POST, PUT, PATCH and FILE). This is the character encoding to use, and is independent of the Content-Encoding HTTP header.
-
Browser-compatible headers
When using multipart/form-data, this suppresses the Content-Type and Content-Transfer-Encoding of the HTTP headers, and only sends the Content-Disposition.
-
Encoding?
Encode special characters in url
-
Contains equal to?
When passing a key-value, some applications do not expect an equals sign when the value is an empty string
2.3 Controller
When dealing with more complex test processes, it is necessary to control the overall test process similar to the if/for control sequence and the number of cycles in the programming language. jmeter provides many controllers to facilitate testing of various scenarios, as follows:
Commonly used controllers are:
- IF controller
- Only one controller login scenario is commonly used
- loop controller
- random controller
2.4 Timers
There is no delay between Jmeter requests, but the actual work sometimes needs to increase the fixed time to test, and sometimes it is necessary to let the threads execute at the same time at a certain point in time, then the timer function can be used
2.5 pre/post processor
-
A pre-processor performs some operations before a sampler request, a post-sampler does something after.
-
Common scenarios for pre-processors in HTTP requests include: assigning a different user id to each thread.
-
Post-processors are most commonly used to process response data.
2.6 Configuration elements
Config Element provides support for static data configuration, which can set default values and variables for samplers.
Store and send cookies like a web browser. If there is an HTTP request and the response contains a cookie, the cookie manager will automatically store the cookie, and then use the cookie in all subsequent requests for a particular web site. Can be viewed in the results tree.
2.7 Listener
The listener is used to monitor the results, and can also view, save and read the saved test results.
The following takes the aggregation report as an example to display the attributes in the table
Attribute name | Meaning |
---|---|
Label | Sample label name, the sampler is the Http request is the Http request name |
Samples | The number of samples with the same label, the sampler is the http request is the number of sending requests |
Average | request response time, average |
Median | Response time from small to large, in the 50% position, 50% of the samples took no more than this time; the rest took at least the same time. |
90% Line | at 90% position |
95% Line | at 95% position |
99% Line | |
99% Line | at the 99% position |
Min | minimum |
Min | td> |
Max | Max |
Error % | Request error rate |
Throught | Throughput |
Received KB/sec | Data rate KB/s received from the server |
Sent KB/sec | Data rate sent to the server, KB/s |
3. Plugins
3.1 Third-party plug-ins
As an open source plug-in, Jmeter is not as good as the commercial software LoadRunner in some functions, but it has added plug-in functions, and you can install the plug-ins you want according to your needs.
- Plugin website: https://jmeter-plugins.org/wiki/Start/
3.2 Recording plugin
badboy is a testing tool developed in C++, designed for testing and developing complex dynamic applications, but it has not been updated for a long time.
Anyone who has used jmeter knows that jmeter can test simple static pages, and script production can be done in three or two steps. But it is very difficult to make complex test steps, such as logging in to the system to enter the user name and password, what functions, parameter configurations, etc., will definitely confuse you. Moreover, there are very few cases of jmeter-related complex points on the Internet, and the help documentation provided by it itself has only a very simple example, which is not very useful. It’s different with badboy. It can provide the same screen recording function as loadrouner. You don’t need to configure any protocol, parameters, cookie manager, etc., as long as you record your test process and save it as jmeter The script format is ok
The official website cannot be accessed, and a badboy installation package was found online: Link: https://pan.baidu.com/s/1Ae3tLuP3q7301SzyXDGw2A Extraction code: jcg5
4. JSR223 scripts and functions
4.1 JSR223 script
jsr233 is java’s support specification for scripting language, and jmeter supports scripting language
-
BeanShell
-
A small, free, embeddable Java source code interpreter written in Java with object scripting language features.
-
GitHub address: https://github.com/beanshell/beanshell
-
-
groovy
- A JVM-based agile development language that combines many of the powerful features of Python, Ruby, and Smalltalk]
-
javascript
4.2 Function variables
A JMeter function is a special value that can populate the field of any sampler or other element in the test, the syntax is as follows:
${__functionName(var1,var2,var3)}
The JMeter variable reference syntax is as follows:
${VARIABLE}
Documentation: https://jmeter.apache.org/usermanual/functions.html
5. Actual case
5.1 Login pressure test
Prepare 100 users to log in, and perform pressure test on the login interface. The test project uses an open source project: Micro Personnel.
Here is a stored procedure that generates users:
DELIMITER $$ CREATE PROCEDURE generate_sql() BEGIN DECLARE i INT DEFAULT 1; WHILE i <= 99 DO SET @sql = CONCAT("INSERT INTO `vhr`.`hr` (`name`, `phone`, `telephone`, `address`, `enabled`, `username`, `password`, `userface`, ` remark`) VALUES ('System administrator', '18568887789', '029-82881234', 'Shenzhen Nanshan', '1', 'admin', LPAD(i, 3, '0'), "', '$2 a$10$ySG2lkvjFHY5O0./CPIE1OI8VJsuKYEzOYzqIa7AJR6sEgSzUFOAm', 'http://bpic.588ku.com/element_pic/01/40/00/64573ce2edc0728.jpg', NULL);"); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET i = i + 1; END WHILE; END$$ DELIMITER; call generate_sql
Prepare user.csv, modify the code to remove the verification code part, and the final test throughput is 50 per second
5.2 Database pressure test
To perform pressure testing on the database, first configure the JDBC connection pool, add the driver jar package to the lib directory, restart Jmeter, and perform pressure testing
Reference
- https://github.com/aliesbelik/awesome-jmeter
- Full-stack performance testing practice book Jmeter actual combat
- Two very useful testing tools jmeter and badboy