Performance testing of a Java EE application based on JMeter

Source: Internet
Author: User

JMeter is an Apache Jakarta project that is used for software stress testing (Load test), which allows for stress testing not only for HTTP, but also for databases (via JDBC), FTP, Web Service, Java objects, and more. Recently, it was used in our project. Our project is based on the BEA WebLogic, a Java EE project that deploys 3 Java EE applications in one domain, thus weblogic memory garbage collection during customer use. We configured the WebLogic cluster and deployed some of these applications separately, and used JMeter for performance testing. This provides the necessary basis for the performance diagnosis of the application.

Basic concepts

JMeter's test plan is a tree-like structure with multiple element types in the tree, and there are some inheritance relationships between the elements of the tree structure (the principle is somewhat similar to log4j). Here's a brief description of the element type:

1, Threadgroup
As the name implies is a thread group, the test must have a threadgroup element as the basis (otherwise there is no test thread running), this element can be configured to run how many threads, each thread loop how many times, all the number of threads total boot time (ramp-up period) and so on.

2. Controller
This includes logical controllers and sampler, which are used for some logical control, such as rotations, conditions, loops, and so on. Sampler is really a "work" of "sampler", such as "HTTP request", is to carry out an HTTP request.

3, Listener
Listener to listen to the request process can be simply understood to obtain the results of the Dongdong. For example, simple data writer, you can write the results into a text file (in fact, all listener can write data into the file), as well as the View Results in table, is to display the results in the table.

4. Timer
Used to control functions such as time delays in the execution process.

5, assertion
assertions, added to sampler, can be used to judge the returned result, such as whether the HTTP return result contains a string. If the assertion is true, jmeter marks the request as successful, otherwise it is marked as failed.

6. Configuration Element
Configuration with the elements that are useful. Because the test plan is tree-like and has an inheritance relationship, you can specify a configuration Element at a high level, and a low-level correlation sampler inherits the high levels of configuration information if the configuration is not explicitly specified. (Is it like log4j?) )

7, Pre-processor/post-processor Elements
Used to perform pre-and post-processing tasks before and after the sampler is run. For example, dynamically modifying the parameters of the request (preprocessing), extracting information from the returned information (post-processing), and so on.

To remind you that jmeter according to the current system locale display menu language, in order to easily set back to English, you can modify the file, settings language=en

Use of JMeter


Everyone can go through Download the release version of JMeter, and then unzip the downloaded. zip file to C:/jmeter (which will be referenced in the following article using%jmeter%) under the 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 picture below is the screen of the JMeter visual interface.

Figure one: Screen when JMeter is turned on

# Build a test plan

A test plan describes the execution process and steps of jmeter during the execution of a test, including one or more thread groups (thread Groups), logical control (logic Controller), and instance generation controller (sample generating Controllers), Listener (Listener), timer (timer), Comparison (assertions), configuration element (config Elements). When JMeter is opened, it has established a default test plan, and an instance of a JMeter application can only establish or open a test plan. Now that we are populating the content of a test plan, this test plan makes a request to a JSP file and a servlet, we need to jmeter simulate five requestors (i.e. five threads), each requester requests two times in a row, and the following sections describe detailed steps.

# Increase Load Information settings

This step, we will add the relevant load settings to the test plan, is jmeter know we need to simulate five requestors, each requester in the test process two times in a row. The detailed steps are as follows:

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

2. The Thread group has three parameters related to load information:

Number of Threads: set of users sending requests

Ramp-up Period: The total time interval, in seconds, that occurs for each request. 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 of the request, and if you select Forever (the default), then the request will continue, and if you do not select forever and enter a number in the input box, the request will repeat the specified number of times, and if you enter 0, the request will be executed once.

According to the design of our demo example, we should set number of threads to 5,ramp-up period set to 0 (i.e. simultaneous concurrent request), uncheck forever, enter 2 in the input box after loop count, and set the following screen as follows:

Figure two: Thread Group with good parameters set

# Add default HTTP properties (optional)

The actual testing work is often carried out on the same server on the Web application, so JMeter provides a setting, in the default HTTP property settings need to be tested server related properties, the subsequent HTTP request settings can be ignored in the settings of the same parameters, reduce the time to set the parameter entry. We will use this attribute here. You can set the default HTTP properties by using the following 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, and his Settings information box will appear to the right of the interface.

2. The main parameters of the default HTTP properties are described below:

Protocal: protocol used when sending a test request

Server name or IP: the IP address or name of the server being tested

Path: The default starting position. For example, if path is set to/jmeter, the/jmeter path will be added to all HTTP request URLs.

Port number: Server provides service port numbers

Our test plan will be tested against a web app on a native Web server, so protocal should be http,ip using localhost because the context path that this web app publishes is/jmeter, So the path here is set to/jmeter because the Tomcat server is used, so port number is 8080.

# Add an HTTP request

Now we need to increase the HTTP request, and he is also the subject part of our test. You can add a sexual HTTP request by using the following steps:

1. Select the Thread group node of the left tree in the visual interface, right-click, select Add ' Sampler ' HTTP request, and his settings information box will appear to the right of the interface.

2. His parameters are about the same as the HTTP properties described in 2.5, and the added attributes have the option of sending HTTP when the method is sent, and you can choose either get or post.

We are now adding two HTTP requests because we have set the default HTTP properties, so the same properties as the default HTTP properties are no longer set again. After setting the screen as follows:

Figure three: Set up a JSP test request

Figure IV: Set up a servlet test request (with parameters)

# Add Listener

Listener is added to record test information and can use the visual interface provided by JMeter to view test results, there are several methods of analysis of results to choose from, you can choose different results according to their own analysis method, we use the form of table to view and analyze the test results. You can add listener by following the steps below:

1. Select the Test Plan node of the left tree in the visual interface, right-click, select Add ' listener ' view result in table, and the right side of the interface will appear with his settings information and the result display box.

2. You can set the FileName property setting on the interface to save the test results to a file interface The test results are displayed using a table, the first column of the table Sampleno shows the order and number of requests executed, the URL shows the target of the request sent, The Sample-ms column shows how long this request will take to complete, and the final success column shows whether the request was executed successfully. The bottom of the interface you can also see some statistics, the most concern should be average bar, that is, the corresponding average time.

# Start execution of test plan

You can now execute the test plan by clicking the menu bar run-start. Here is the result diagram for the test plan:

Figure V: Results show

JMeter is used for energy or performance testing, and by using the energy provided by the jmeter, we can visualize the test plan: including what kind of load to use, what content to test, what parameters are passed in, and he provides many kinds of graphical test results display methods, Allows us to start testing work and analyze test results simply.

Performance testing of a Java EE application based on JMeter

Related Article

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.