JMeter Performance Test, complete introductory article

Source: Internet
Author: User
Tags current time http request min zip port number java se
1. JMeter Introduction

Apache JMeter is a pure Java writing load function test and performance test open source Tool software. Compared to LoadRunner, JMeter is small, lightweight and free, becoming a mainstream performance testing tool, one that every tester has to master.

This article is a complete primer for JMeter performance testing, from JMeter download installation to writing a full performance test script, ultimately performing performance tests, and analyzing performance test results.

The operating environment is a Windows 10 system with a JDK version of 1.8,jmeter version 3.3. 2. JMeter Install 2.1 JDK installation

Since JMeter is based on Java development, you first need to download the installation JDK (currently jmeter only support Java 8, Java 9 is not yet supported)
1. Website Download Address: http://www.oracle.com/technetwork/java/javase/downloads/index.html
2. Select Java SE 8u151/8u152, click JDK Download

3. Install the downloaded JDK
4. Configure the system environment variable 2.2 jmeter installation website download address: http://jmeter.apache.org/download_jmeter.cgi Download the latest JMeter 3.3 Version: Apache-jmeter-3.3.zip
Unzip the zip package to start jmeter after download is complete
Double-click the Jmeter.bat under the JMeter decompression path (apache-jmeter-3.3\bin) bin to
3. Test examples

We choose the most common Baidu search interface: 3.1 interface Address

Http://www.baidu.com/s?ie=utf-8&wd=jmeter Performance Test 3.2 request Parameters

IE: encoding mode, default is Utf-8
WD: Search Term 3.3 return result

Search results, we can determine whether this request succeeds or fails by verifying that the result contains the search term WD. 4. JMeter Scripting 4.1 adding thread groups

Right-click on "Test Plan", "Add", "Threads", "Thread Group"

Here you can configure the thread group name, number of threads, length of preparation (ramp-up Period (in seconds)), number of cycles, scheduler, and other parameters:

Thread group parameters in detail:
1. Number of threads: number of virtual users. A virtual user occupies a process or thread. Set how many virtual users here is the number of threads set.
2. Ramp-up Period (in seconds) preparation time: How long the number of virtual users set will take to start all. If the number of threads is 10 and the preparation time is 2, then 2 seconds will be required to start 10 threads, that is, 5 threads per second.
3. Number of cycles: the number of times each thread sends a request. If the number of threads is 10 and the number of cycles is 100, then each thread sends 100 requests. The total number of requests is 10*100=1000. If "Forever" is checked, then all threads will continue to send the request, one to choose to stop running the script.
4. Delay thread creation until needed: delays the creation of threads until needed.
5. Scheduler: Set start time and end time for thread group startup (when configuring the scheduler, you need to tick the number of cycles to always)
Duration (seconds): test duration, overwrite end time
Startup delay (seconds): Test delay start time, overwrite start time
Start time: Test start time, the startup delay will overwrite it. When the boot time is over, the current time is overwritten by manual testing only.
End time: The test end time, and the duration will overwrite it.

Because of the interface debugging needs, we use the default settings for the time being, and then come back to configure when the performance test is actually performed later. 4.2 Adding an HTTP request

Right-click on "Thread Group", "Add", "Sampler", "http request"

For our interface Http://www.baidu.com/s?ie=utf-8&wd=jmeter performance test, you can refer to the following diagram to fill in:

HTTP request main Parameters detailed: Web server
Protocol: Sends an HTTP request protocol to the target server, which can be HTTP or HTTPS, default to HTTP
The server name or the destination server name or IP to which the ip:http request was sent
Port number: The port number of the destination server, the default value is 80
2.Http Request
Methods: Methods for sending HTTP requests, including GET, POST, HEAD, PUT, OPTIONS, TRACE, delete, and so on.
Path: Destination URL path (the rest of the URL is stripped of the server address, port, and parameters)
Content encoding: Encoding, default is ISO-8859-1 encoding, here configured to utf-8 with the request to send parameters
The URL parameter that is sent in the request, the user can set all parameters in the URL in this table, the table each behavior one parameter (corresponding URL of name=value), note that the parameter in Chinese need to tick "encode" 4.3 add view result tree

Right-click on "Thread Group", "Add", "Listener", "View result tree"

At this time, we run the HTTP request, modify the response data format as "HTML Source formatted", you can see the results of this search page titled "JMeter Performance Test _ Baidu search."
4.4 Adding user-defined variables

We can add user-defined variables to the HTTP request parameterization, right-click on "Thread Group", "Add", "Configuration Components", "User-defined variables":

Add a parameter, WD, to store the search term:

and use this parameter in an HTTP request in the format: ${WD}
4.5 Adding assertions

Right-click "http Request", "add", "assertion", "response assertion"

We verify that the returned text contains the search term, adding the parameter ${wd} to the pattern to be tested:
4.6 Adding an assertion result

Right-click on "HTTP Request", "add", "listener", "assertion result"

At this point, we run it again to see that the assertion result succeeds or fails.
4.7 Adding aggregation reports

Right click on "Thread Group", "Add", "Listener", "Aggregation Report" to store performance test report

In this way, we have completed a JMeter performance test script for a full HTTP interface. 5. Performing performance tests 5.1 Configuring thread groups

Click on the thread group, configure the relevant parameters of the performance test: Number of threads, number of cycles, duration, etc., here we configure the number of concurrent users is 10, the duration is 60s
5.2 Performing tests

Click the small green arrow button to launch the test, you need to click the Small Broom button to clear the previous debugging results.
6. Analysis of test reports

When the performance test execution is complete, open the aggregation report to see:

An explanation of the aggregation report parameters:
1. Label: Each JMeter element (for example, HTTP Request) has a name attribute, which shows the value of the Name property
2. #Samples: Number of requests-indicates how many requests have been made in this test, and if 10 users are simulated, each user iterates 10 times, then this shows 100
3. Average: Average response time--By default is the average response time for a single Request, and when Transaction Controller is used, the average response time is displayed in Transaction units
4. Median: Median, which is the response time of 50% users
5.90% line:90% User's response time
6. Min: Minimum response time
7. Max: Maximum response time
8. error%: Error Rate--Number of error requests/Total requests
9. Throughput: Throughput--By default represents the number of requests completed per second (request per Second), when Transaction Controller is used, it can also represent LoadRunner-like Transaction Per Second number
Kb/sec: The amount of data received from the server side per second, equivalent to throughput/sec in LoadRunner

In general, the data we need to focus on in performance testing are: #Samples requests, Average average response time, min response time, max maximum response time, error% error rate, and throughput throughput. 7. Source code Download

At this point, we used JMeter to complete a complete HTTP interface performance testing process, from scripting to execution to final result analysis.

Full Script source Download link: https://pan.baidu.com/s/1eS90cVo Password: st15

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.