Introduction to JMeter Web Performance testing __web

Source: Internet
Author: User
Tags tomcat server

JMeter is an open source project for the Apache organization, which is a tool for functional and performance testing, with 100% in Java and the latest in 2.2.3. You can download the source code and view the related documents to This will show you how to test your Web application using JMeter.
1. jmeter function Field
JMeter can be used to test the performance of static or dynamic resources (files, Servlets, Perl scripts, Java objects, databases and queries, FTP servers, or other resources). JMeter is used to simulate attaching high loads to a server, network, or other object to test the compression capability of the service they provide, or to analyze the overall performance of the services they provide under different load conditions. You can use the graphical interface provided by JMeter to analyze performance metrics or test server/script/object behavior under high load.
2, the use of JMeter test Web applications
The following is a detailed demonstration of how to use JMeter to test the complete process of Web applications.
2.1 test Environment
In this case, we tested with Tomcat as a Web server, and the content tested was a JSP file http://localhost:8080/examples/jsp/snp/snoop.jsp.
2.2 Installation Start JMeter
First of all we can go to the Web site JMeter, and then the download of the. zip file for decompression, such as extract to C:/jmeter (in the following article will use %jmeter% to refer to this directory) directory.
Now, use the Jmeter.bat batch file below%jmeter%/bin to start the JMeter visual interface, and the following work will be done on this visual interface. The following picture is a screenshot of the JMeter visual interface.

Figure I: Screenshot of JMeter when opened
2.3 Establish test plan
The test plan describes the execution process and steps of the jmeter during the execution of the test. A complete test plan consists of one or more thread groups (thread Groups), logical control (Logic Controller), Instance generation controller (sample generating controllers), listener (Listener), Timer (timer), Comparison (assertions), configuration element (config Elements). When you open JMeter, it has established a default test plan, and an instance of a JMeter application can only establish or open a test plan.
Now we're starting to populate the content of a test plan that makes a request to a JSP file index.jsp, we need to jmeter five requesters (that is, five threads), and each requester requests two consecutive times, and the following sections describe detailed procedures.
2.4 Adding Load information settings
In this step, we will add the related load setting to the test plan, which is jmeter knows that we need to simulate five requesters, each requesting two consecutive times during the test process. Detailed steps are as follows:
1. Select the Test Plan node of the left tree in the visual interface, right-click, and select Add | Thread Group, his Settings information box appears to the right of the interface.
2. Thread Group has three parameters related to load information:
number of Threads: Set the number of users who sent the request
ramp-up Period: The total time interval, in seconds, that each request takes place. For example, your request number is 5, and this parameter is 10, then the interval between each request is 10/5, that is 2 seconds
loop Count: The number of repetitions that the request occurs, and if you select the Forever (default), the request continues, and if you do not select forever and enter a number in the input box, the request repeats the specified number of times, and if you enter 0, the request executes once.
Based on the design of our demo example, we should set the number of threads to 5,ramp-up period set to 0 (that is, concurrent requests), do not select Forever, enter 2 in the input box after loop count, and set the screenshot below:

Figure two: Thread Group with parameters set.
2.5 Adding default HTTP properties (optional)
The actual test work is often done for Web applications on the same server, so JMeter provides a setting in which the default HTTP property settings need to be tested for the relevant properties of the server, and the settings of the same parameters can be ignored in future HTTP request settings, reducing the time to set parameter entry.
We will use this attribute here. You can set the default HTTP properties by following these steps:
1. Select the Test Plan node of the left tree in the visual interface, right-click, and select Add | Config Element | HTTP request defaults, the right side of the interface will appear with his Settings information box.
2. The main parameters for the default HTTP properties are described below:
protocal: protocol used when sending test requests
server name or IP: the IP address or name of the server being tested
path: The default starting position. For example, if you set path to/examples, then all HTTP request URLs will add/examples paths.
port Number: Port numbers for server-provided services
Our test plan will test Web applications on the local Web server, so protocal should be http,ip using localhost because the context path for this Web application publication is the root directory, that is, So the path here is set to/examples because the Tomcat server is used, so port number is 8080. The following screenshot is set:

Figure three: default HTTP parameters used in test plans
2.6 increase HTTP requests
now we need to add HTTP requests, which is the content body part of our test. You can increase the HTTP request by using the following steps:
1. Select the Thread group node of the left tree in the visual interface, right-click, and select Add | sampler | HTTP request, the following settings information box will appear on the right side of the interface.
2. The parameters to be entered here are similar to the HTTP properties described in 2.5, and the added attribute has the option of sending HTTP when the method is sent, and you can choose to get or post.
We are now adding two HTTP requests because we set the default HTTP properties, so the same properties in the default HTTP properties do not repeat the settings. The screenshot below is set up as follows:

Figure Four: Set up the JSP test request
If you want to test the performance of a servlet, you can use the following configuration:

Figure five: Set up a servlet test request (with parameters)
2.7 Add listener
To increase the listener is to record the test information and to view the test results using the visual interface provided by JMeter, which has several result analysis options available. You can choose different results to display according to your own customary analysis, and we use tabular forms to view and analyze test results. You can add listener by following these steps:
1. Select the Test Plan node of the left tree in the visual interface, right-click, and select Add | listener | View results in table, where the corresponding setting information and result display box will appear on the right side of the interface.

Figure VI:
2. You can set the FileName property setting on the interface to save the test results to a file the interface below will use the table to display the test results.
The first column of the table Sampleno displays the order and number of the request execution, the URL shows the destination for the request to be sent, the Sample-ms column shows the time it takes to complete the request, and the final success column shows whether the request was executed successfully.
The bottom of the interface you can also see some statistical information, the most concern should be average bar, that is, the corresponding average time.
2.8 Start execution of test plan
Now you can run the test plan by clicking the menu bar run-> start. The following two graphs are the results of the first execution of the test plan:

Figure VII: Results after the first execution show
Meter is used for energy or performance testing, by using the jmeter provided, we can visualize the development of a test plan: including what kind of load to use, what to test, what to pass in, and how many graphical test results to display. Allows us to simply start the test and analyze the test results.
JMeter In addition to the Web application for stress testing, you can also implement the Java objects, databases and other testing process, in particular, refer to the JMeter Help documentation.

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: 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.