Use jmeter for Performance Testing

Source: Internet
Author: User

Jmeter is an open-source project organized by Apache. It is a tool for functional and performance testing. 100% is implemented in Java. The version used in this article is 1.9.1. You can download the source code and relevant documentation at http://jakarta.apache.org/jmeter/index.html.

Jmeter Fields

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 servers, networks, or other objects to test their ability to provide services, or to analyze the overall performance of the services they provide under different load conditions. You can use the graphic interface provided by jmeter to analyze performance indicators or test the behavior of servers, scripts, and objects under high loads.

Use jmeter to test Web Applications

In the following sections, the author will demonstrate in detail how to use jmeter to test the complete process of Web applications.

2.1 test environment

The author uses Tomcat as a Web server for testing. The tested content is a JSP file and a servlet. the JSP file calls JavaBean and prints relevant information, servlet accepts user parameters, calls JavaBean, and outputs relevant information. For details, refer to the content of jmeter. War provided by the author.

2.2 install and start jmeter

You can go to the catalog (% jmeter % will be used to reference this directory in subsequent articles.

Now, use the jmeter. bat batch file under % jmeter %/bin to start the jmeter visual interface. The following work will be performed on this visual interface. The following figure shows the jmeter visual interface screen.

Figure 1: jmeter Screen

2.3 create a test plan)

The test plan describes the jmeter execution process and steps during the execution of the test. A complete test plan includes one or more thread groups and logic controllers) instance Generation Controller (sample generating controllers), listener (listener), timer (timer), comparison (assertions), configuration element (config elements ). When you open jmeter, it has created a default test plan. Only one test plan can be created or opened for an instance of a jmeter application.

Now we start to fill in the content of a test plan, which sends a request to a JSP file and a servlet. We need jmeter to simulate five requestors (that is, five threads ), each requester requests two consecutive times. The following sections describe the detailed operation steps.

2.4 Add Load information settings

In this step, we will add the relevant load settings to the test plan. jmeter knows that we need to simulate five requestors, each of which has two consecutive requests during the test. The detailed steps are as follows:

1. Select the test plan node in the left Tree of the visual interface, right-click it, and select Add 'thread group. The setting information box appears on the right side of the interface.

2. The thread group has three parameters related to the load information:
Number of threads: set the number of users sending requests
Ramp-up period: the total time interval for each request, in seconds. For example, if your request number is 5 and this parameter is 10, the interval between each request is 10/5, that is, 2 seconds.
Loop count: number of times a request is repeated. If forever (default) is selected, the request will continue. If forever is not selected, enter a number in the input box, the request repeats the specified number of times. If 0 is input, the request is executed once.

According to the design of the demo, we should set number of threads to 5, ramp-up period to 0 (that is, concurrent requests at the same time), without selecting forever, enter 2 in the input box after loop count. The configured screen is as follows:

Figure 2: Set the thread group of the parameter.

2.5 add default HTTP attributes (optional)

The actual testing work is usually carried out for Web applications on the same server. Therefore, jmeter provides such a setting. In the default HTTP attribute setting, the relevant attributes of the server need to be tested, in future HTTP request settings, you can ignore these settings with the same parameters to reduce the time for setting parameter input.

This attribute will be used here. Follow these steps to set the default HTTP attribute:

1. Select the test plan node in the left-side tree of the visual interface, right-click it, and choose add 'config element' HTTP request ults. The setting information box appears on the right side of the interface.

2. the main parameters of the default HTTP attribute are described as follows:
Protocal: protocol used to send a test request
Server name or IP: IP address or name of the server to be tested
Path: the default start position. For example, if you set path to/jmeter, the/jmeter path will be added to all HTTP request URLs.
Port Number: the port number that the server provides services.

Our test plan will be to test the web application on the Web server of the local machine, so protocal should be HTTP, and IP uses localhost, because the context path of the Web application is/jmeter, therefore, the path here is set to/jmeter. Because the Tomcat server is used, the port number is 8080. The configured screen is as follows:

Figure 3: default HTTP parameters used in the test plan

2.6 Add HTTP requests

Now we need to add an HTTP request, which is also the main part of our test content. You can add HTTP requests through the following steps:

1. Select the thread group node in the left Tree of the visual interface, right-click it, and select Add 'sampler' HTTP request. The setting information box appears on the right side of the interface.

2. Its parameters are similar to the HTTP attributes described in 2.5. The added attributes include the method selection for sending HTTP. You can choose get or post.

Now we add two HTTP requests. Because we have set the default HTTP attribute, the same attribute as the default HTTP attribute will not be set again. The configured screen is as follows:

Figure 4: configured JSP test request

Figure 5: configured servlet test request (with parameters)

2.7 add listener

The listener is added to record the test information and you can view the test results on the visual interface provided by jmeter. There are several results analysis methods available, you can select different display methods based on the analysis method you are used to. Here we use the form of tables to view and analyze the test results. You can add a listener by following the steps below:

1. Select the test plan node in the left Tree of the visual interface, right-click it, and select Add 'listener 'view result in table. The setting information and result display box will appear on the right side of the interface.

2. you can set the filename attribute setting on the interface to save the test result to a file. The test result is displayed in the table below the interface. The sampleno column in the table shows the request execution sequence and number, the URL displays the target of the request, the sample-MS column shows the time elapsed for the request to complete, and the final success column shows whether the request is successfully executed.

At the bottom of the page, you can see some statistics. The most important thing is the average, that is, the average time.

2.8 start executing the test plan

Now you can click Run> start on the menu bar to start executing the test plan. The following two figures show the results of the first and second execution of the test plan:

Figure 6: Result Display after the first execution

Figure 7: Result of the second execution

You can see that the maximum time value of the first execution is from the jsp request. This can be explained through the following reasons: the JSP must be compiled into a. Class file before execution. Therefore, the second result is normal.

Summary

Jmeter is used for energy supply or performance testing. By using the power supply provided by jmeter, We can visually develop a test plan, including specifying what load to use, what to test, what to pass in parameters, and at the same time, he provides a variety of graphical display methods for test results, allowing us to easily start testing and analyze test results.

In this article, the author demonstrates in detail how to use jmeter for Web testing based on his own experience, this section briefly introduces the meanings of relevant parameters on the graphic display interface that jmeter provides test results. We hope to help you learn the basic knowledge of using jmeter. At the same time, you can refer to this process and the help documentation of jmeter to implement the testing process for Java objects and databases.

References

Jmeter User Guide: http://jakarta.apache.org/jmeter/usermanual/index.html

 

Use jmeter for Performance Testing

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.