Use JMeter for performance testing


Apache JMeter is an open-source project organization, it is the functional and performance testing tools, 100% pure java implementation, the latest version is 1.9.1, you can go to http://jakarta.apache.org/jmeter/index . html download the source code and view the document.

1 JMeter role in the field

JMeter can be used to test the performance of static or dynamic resources (files, Servlets, Perl scripts, java objects, database and query, ftp servers or other resources). JMeter to simulate the server, network or other object attached to high-load compression test their ability to provide services, or of their services under different load conditions in the overall performance of the situation. You can use JMeter to provide a graphical interface of Performance Indicators, or under high load test server / script / object behavior.

2 Web Application Testing using JMeter

The next chapter, the author will demonstrate in detail how to use JMeter to test the complete process of Web applications.

2.1 Test Environment

On the Web server using Tomcat as a test, the content being tested is a jsp file and a servlet, jsp file called JavaBean, print information, servlet to accept user parameters, call javabean, the output information. Please refer to the detailed content of the content provided JMeter.war.

Installation start JMeter 2.2

You can go through http://apache.linuxforum.net/dist/jakarta/jmeter/binaries/jakarta-jmeter-1.9.1.zip download JMeter's release version, then download the. Zip files to C: / JMeter (later article will use% JMeter% to refer to this directory) directory. Now, use the% JMeter% / bin jmeter.bat the following batch file to start the JMeter's visual interface, the following work will be in the visual interface to operate the interface. The following picture is a visual interface JMeter screenshot.



Figure 1: JMeter open screenshot

2.3 The establishment of test plan (Test Plan)

Test plan describes the implementation of the testing process in JMeter's implementation process and steps, a complete test plan including one or more thread groups (Thread Groups), Logic Control (Logic Controller), generate an instance of the controller (Sample Generating Controllers), detection Hearing (Listener), timer (Timer), comparison (Assertions), configuration elements (Config Elements). Open JMeter, it has established a default test plan, an example of JMeter application can only create or open a test plan. Now we begin to fill a test program content, the test program to a jsp file, and a servlet request, we need to simulate five JMeter requester (that is, five threads), each requestor two successive requests, the following section describes the steps in detail.

2.4 increase the load information set

This step, we will increase the relevant load test program set, is Jmeter know we need to simulate the five petitioners, each requester in the request for two consecutive testing process. Detailed steps are as follows:

1. Select the visual interface of the Test Plan node in the left tree, right-click, select Add''Thread Group, the interface will appear on the right to set his message box.

2. Thread Group has three parameters and load information related to:

Number of Threads: send a request to set the number of users

Ramp-up period: the total time of occurrence of each request interval, in seconds. Such as the number of your request is 5, and this parameter is 10, then the intervals between each request is 10 / 5, that is, 2 seconds

Loop Count: request repetitions occur, if you choose behind forever (the default), then the request will have to continue, if you do not choose forever, while the number in the input box, then the request will be repeated the specified number of times, if you enter 0, then request will be executed once.

According to our demo design examples, we should be Number of Threads is set to 5, Ramp-up period is set to 0 (that is, simultaneous request), do not select forever, back in the Loop Count 2 input box, after setting screenshot below:



Figure 2: set up parameters Thread Group.

Http 2.5 increase in the default property (optional)

The actual testing is often on the same server for Web applications to start, so Jmeter provides such a setting, the default Http property needs to be tested server related properties, since the http request to set them on the same parameters can be ignored settings, reduce set Parameter entry time. We will use this property here. You can use the following steps to set the default http attributes:

1. Select the visual interface on the left of the Test Plan tree node, right click and select Add''config element''http request defaults, he will appear on the right interface settings box.

2. Default http primary parameters as follows:

protocal: send test request to use agreements

server name or ip: Test the server by ip address or name

path: the default starting position. Such as the path set to / jmeter, then all the http url requests are to be increased / jmeter path.

port number: port number of server services

Our testing program will focus on the machine Web server for testing Web applications, so protocal should be http, ip using the localhost, because the web application context path is released / jmeter, so here's path set to / jmeter, because Use Tomcat servers, so port number is 8080. Screenshot of the settings are as follows:



Figure 3: test plan parameters used Http default

Http request to increase 2.6

Now we need to increase the http request, and he is also part of our content of the test subjects. You can use the following steps to increase the resistance of the http request:

1. Selected in the left visual interface of the Thread Group tree node, right-click, select Add''sampler''http request, the interface will appear on the right to set his message box.

2. He described the parameters and http 2.5 similar properties to increase the property in the choice of methods when sending http, you can choose to get or post.

We now add two http requests, because we set the default http properties, so the default http properties and the properties will not repeat the same set. Screenshot of settings as follows:



Figure 4: Set a good jsp test request



Figure 5: Set a good Servlet test request (with parameters)

2.7 increase Listener

Increase the listener is to record the information and can use the Jmeter test provides a visual interface view test results, which are the result of several methods to choose from, you can choose their own custom analysis methods showed different way, we use here a tabular format to view and analyze test results. You can use the following steps to increase the listener:

1. Select the visual interface of the Test Plan node in the left tree, right-click, select Add''listener''view result in table, the interface will be a right of his box set of information and results.

2. You can set the filename property above the interface the test results are saved to a file in the interface will use the following table shows the test results, the first column of the table shows sampleno request execution order and number, url shows the request sent by target, sample -ms column shows the time-consuming to complete this request, the final success column shows whether the request for the successful implementation of change. Bottom of the interface you can also see some statistical information should be most concerned Average bar, which is the corresponding average time.

2.8 test plan started

Now you can by clicking on the menu bar run -> Start test program was started. The following graph is of both the first and the second test the results of the implementation of the plan:



Figure 6: the first results after the implementation of



Figure 7: The second implementation of the results

We can see that the first implementation of several large time values are from jsp request, which can be interpreted by the following reasons: jsp implementation need to be compiled before. Class files. Therefore, the results of the second is the normal result.

3 summarizes

JMeter be used for energy supply or performance test, provided through the use JMeter for performance, we can visualize the development of test plan: including the requirement to use what kind of load, testing what the content of incoming parameters, he provides Good variety of graphical display of test results, so that we can start a simple test and analysis of test results.

This article, the authors use their experience shows in detail how to use JMeter to test the entire process for Web, a simple introduction to the JMeter test results of the graphical display interface, the meaning of the relevant parameters. Want to help you learn the basics of using JMeter the same time, we can refer to this process and to implement JMeter's help documentation on the java objects, databases, the testing process.

References:



JMeter User's Guide: http://jakarta.apache.org/jmeter/usermanual/index.html

Tool download:

1. Tomcat http://jakarta.apache.org/tomcat/index.html

2. JMeter http://jakarta.apache.org/jmeter/index.html