"Go" test the performance of Tomcat with JMeter

Source: Internet
Author: User

JMeter is the Apache Open source project, it is the function and performance testing tools, 100% in Java Implementation, the latest version is 1.9.1, we can go to HTTP// jakarta.apache.org/jmeter/index.html Download the source code and view the relevant documentation.

JMeter Field of Action

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 the ability to attach high loads on servers, networks, or other objects to test the compression capabilities of their services, 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 conditions.

I. Using JMeter to test Web applications

Test your web App with JMeter

  

In the following chapters, the author will demonstrate in detail how to use JMeter to test the complete process of a Web application.

  

1 Test environment

The author uses Tomcat as a Web server for testing, the content being tested is a JSP file and a servlet,jsp file calls JavaBean, printing related information, the servlet accepts user parameters, calls JavaBean, and outputs relevant information. Please refer to the Jmeter.war content provided by the author for detailed information.

2 Installing the Boot JMeter

Everyone can go through http://apache.linuxforum.net/dist/jakarta/jmeter/binaries/ Jakarta-jmeter-1.9.1.zip 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.

3 Setting up 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.

4 Increasing 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.

Based on the design of our demo example, we should set number of threads to 5,ramp-up period set to 0 (that is, simultaneous concurrent requests), uncheck Forever, and enter 2 in the input box after loop count.

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

6 Adding HTTP Requests

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.

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

8 Start execution of test plan

You can now execute the test plan by clicking the menu bar run-start. The following two figures are the author's first time.

You can see that several large time values for the first execution are from the JSP request, which can be explained by the following reasons: The JSP needs to be compiled into a. class file before execution. So the second result is the normal result.

Summarize

  

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.

In this paper, based on his own experience, the author shows in detail how to use JMeter to carry out the whole process of Web testing , and simply introduces the meaning of relevant parameters in the graphical display interface that JMeter provides test results. We hope to help you learn the basics of using JMeter, and you can refer to this process and JMeter's help documentation to implement test procedures for Java objects, databases, and so on.

"Go" test the performance of Tomcat with 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: 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.