JMeter is a Java-based tool for load testing client-server applications. Stefano Mazzocchi originally wrote it to test the performance of Apache JServ (the predecessor of Jakarta Tomcat). It has since become a subproject of Jakarta.
Installing and Running JMeter
The most recent release of JMeter is version 2.8. You can download the latest stable version from JMeter's site. Downloads area available as either .gz
or .zip
files. JMeter 1.8 requires a working JDK 1.5 environment.
Once you extract the binary distribution file, JMeter is ready for you. On Linux/UNIX, run JMeter by invoking the jmeter
shell script. On Windows, call the jmeter.bat
file. Both files can be found in the bin/
directory of the JMeter installation directory. Figure 1 shows JMeter's main window, which is a Swing application.
Figure 1: JMeter's main window.
The user interface has two panes. The left pane displays the elements used in our testing. Initially, there are the Root and two sub-elements, Test Plan and WorkBench. In this article we're only concerned with Test Plans. Add an element to a node by right-clicking it and selecting Add. To remove an element, select the element by clicking on it, then right-click on the element and choose the Remove option.
The right pane of the user interface displays the details of each element. You are now ready to use JMeter. There are two things to note:
- You should not run JMeter on the same machine running the application to be tested. JMeter may use extensive resources that might affect the other application's performance if they are both run on the same machine.
- Make sure that the testing is affected as little as possible by network traffic. The best thing to do is to ask your network administrator to set up an isolated sub-network for the machine running the Web application and the machine running JMeter.
Using JMeter for a Simple Test
Let's start with a very simple test. In this test, we will set up a test plan and stress test a Web application. You will be introduced with some common concepts in JMeter. After understanding this basic test, you should be able to use all of the capabilities of JMeter.
To conduct a test, you must have a test plan. A test plan describes the steps that JMeter will take to perform the testing. A test plan includes elements such as thread groups, logic controllers, sample generating controllers, listeners, timers, assertions, and configuration elements. Don't worry at this stage if you don't understand what these elements are.
A test plan must have at least one thread group. A thread group is the starting point of a test plan, and it can contain all other JMeter elements. A thread group controls the threads that will be created by JMeter to simulate simultaneous users.
Now, let's start by creating a thread group. Right-click the Test Plan element and select Add and then Thread Group. JMeter will create a thread group element under Test Plan element. Click the Thread Group element, and you will see a screen like the one in Figure 2.
Figure 2: Configuring a thread group.
In this page, you can set the following properties:
- Name -- the name of this thread group. You can give a descriptive name to this property.
- Number of Threads -- the number of threads created. Each thread represents a single user. Therefore, if you want to simulate a load test with 10 concurrent users, enter 10 as the value for this property.
- Ramp-Up Period -- the number of seconds JMeter will take to accelerate to create all of the threads needed. If the number of threads used is 10 and the ramp-up period is 20 seconds, JMeter will take 20 seconds to create those 10 threads, creating one new thread every two seconds. If you want all threads to be created at once, put 0 in this box.
- Forever -- if clicked, this option tells JMeter to keep sending requests to the tested application indefinitely. If disabled, JMeter will repeat the test for the number of times entered in the Loop Count box.
- Loop Count --this property value only has an effect if the Forever check box is unchecked. It tells JMeter the number of times it has to repeat the test.
For our simple test, fill the properties with the values found in Figure 2. We will use two users and each test will be performed three times. We use small numbers here so that we can easily explain the results later; in real load testing, you might want to use higher numbers for these properties.
Next, you need to add the element that represents HTTP requests. To do so, right-click the Thread Group element, and select Add, Sampler, and then HTTP Request. An HTTP Request element will be added to the Thread Group element. Click the HTTP Request element to select it, and you should see a screen similar to Figure 3.
Figure 3: Configuring an HTTP Request element.
On the HTTP Request screen, you configure the HTTP requests that will be used to "hit" your application. Here, you can set the following properties.
- Name -- the name of this HTTP request. The name should be descriptive; remember that it is common to have multiple HTTP Request elements in a thread group.
- Server Name or IP -- the server name or the IP address of the machine running the application being tested.
- Port Number -- the port number used by the application. Normally, a Web application runs on port 80.
- Protocol -- the protocol used, either HTTP or HTTPS.
- Method -- the request method, either GET or POST.
- Path -- the path to the resource that will handle this request.
- Follow Redirects -- follows redirections sent by the Web application, if any.
-
Use KeepAlive -- if checked, sends the
Connection = Keep-Alive
request header. By default, an HTTP 1.1 browser usesKeep-Alive
as the value of the Connection header. Therefore, this checkbox should be checked. - Parameters -- the list of parameters sent with this request. Use the Add and Delete buttons to add and remove parameters.
- Send a file with a request -- simulate a file upload to the Web application.
- Retrieve all images and Java Applets -- download embedded content.
-
Now you should be able to figure out the values for the properties in the HTTP Request page. The last element that we need to add to our test plan is a listener, which in JMeter is the same as a report. JMeter comes with various reports to choose from. A report can be a table or a graph. For this testing, use the easiest report available: a table.
To add a listener, right-click the Thread Group element, select Add, and then Listener and View Results in Table. Now you are ready to run the test plan. Before you run your test plan, however, you are advised to save the test plan just in case JMeter crashes the system (an occasional occurrence with higher numbers of threads and loop counts). Afterwards, select Start from the Run menu to execute the test plan.
While the test plan executes, the small box on the bar right below the menu bar will turn green. For a test that does not run indefinitely, JMeter will automatically stop the test plan after it's finished. For a test that goes on indefinitely, you must intervene to stop the test. Do this by selecting Stop from the Run menu.
When I ran my test plan, I got the results like those shown in Figure 4.
<!-- sidebar begins --><!-- don't move sidebars --><!-- sidebar ends -->
Figure 4: A table report.It is very easy to understand the figures in the table. There are six samples taken (two threads and three loop counts, thus 2 x 3 = 6). The response time from each sample is given in the third column. They are 100, 60, 260, 50, 120, and 80 ms. All samples are taken successfully, as described by the fourth column. On average, each sample has a response time of 111 ms ((100 + 60 + 260 + 50 + 120 + 80)/6).
Another important figure is the standard deviation, defined as the square root of the total of the deviation of each sample from the average. This figure indicates how stable your Web application is. If the standard deviation is high, some users will experience very good responses while some other users will wait for a longer time. The smaller this value, the better.
After conducting a simple test, it is very easy to do more complex tests. For load testing Web applications, increase the number of threads and the loop counts gradually and see how your applications cope with the loads. The following sections of this article tackle some other important aspects of load-testing Web applications with JMeter.
Listeners
JMeter comes with a number of listeners or reports. In the previous test, we used a table to display the test results. If this is not suitable for you, you can choose one or more of the other listeners for a thread group. A popular listener is the Graph Results, as shown in Figure 5.
Figure 5: Graph results.Multiple HTTP Requests
A real application has multiple resources, both static and dynamic. Chances are, you want to see the performance of these resources. JMeter makes it easy to employ multiple HTTP requests. Just add any number of HTTP Request elements and configure them, as in the previous test. If you have multiple HTTP Request elements, you might want to use a HTTP Request Defaults element, described in the following section.
HTTP Request Defaults
The HTTP Request Defaults element specifies the default values of existing HTTP Request elements within the same thread group. The HTTP Request Defaults element is especially useful because most, if not all, HTTP Request elements normally have the same server and port. Figure 6 shows the detail page of a HTTP Request Defaults element.
Figure 6: HTTP request defaults.Add an HTTP Request Default element by right-clicking a Thread Group element and then selecting Add, Config Element, and HTTP Request Default.
Cookie Manager
Many Web applications use cookies. JMeter provides cookie capabilities through a Cookie Manager. Adding this element to a thread group allows you to send cookies to the application being tested, just as Web browsers do. Figure 7 displays the details page of a Cookie Manager. Here you can add and delete a cookie.
Figure 7; Cookie Manager.You can add a Cookie Manager element by right-clicking a Thread Group element and then selecting Add, Config Element, and Cookie Manager.
Summary
JMeter is capable of much more than our simple tests demonstrate. From these building blocks, it's possible to create extensive tests with highly detailed reports. Getting useful results is very easy, though.
For more information, see the JMeter User Manual.
- 原载文章:http://onjava.com/pub/a/onjava/2003/01/15/jmeter.html
相关推荐
本教程为jmeter入门教程,帮助初学者了解jmeter。 jmeter是Apache软件基⾦会开源的压⼒测试⼯具,⽀持windows、linux、mac等系统,主要⽀持以下协议: web:HTTP,HTTPS 站点的Web1.0的Web 2.0 (ajax, flex and ...
JMeter入门到精通 介绍JMeter的概念/设置/思想/函数清单等信息
JMeter是一款广泛应用于性能测试领域的开源工具,尤其在Web应用测试方面表现卓越。它由Apache软件基金会开发,支持多种协议,如HTTP、FTP、SMTP、JDBC等,使得测试人员可以对应用程序进行压力测试、负载测试和功能...
jmeter 入门到进阶系列教程 jmeter 是一款优秀的开源性能测试工具,目前最新版本为 3.0 版本。它具有多种优点,如高可扩展性、精心简单的 GUI 设计、完全的可移植性和 100%纯 Java 等。jmeter 的安装非常简单,只...
**JMeter入门实践资料概述** JMeter是一款强大的性能测试工具,由Apache软件基金会开发,主要用于对Web应用程序进行负载和压力测试。它适用于多种协议,包括HTTP、HTTPS、FTP、SMTP、JDBC等,使得测试人员可以模拟...
**JMeter入门基础培训PPT概述** Apache JMeter是一款开源的、Java开发的压力测试工具,主要用于测试Web应用的性能和负载。它最初设计用于HTTP协议的测试,但随着时间的推移,已经发展成为支持多种协议的全面性能...
### JMeter测试入门指导 #### 一、安装JMeter与设定 JMeter是一款开源的压力测试工具,主要用于对静态和动态资源进行性能测试。它能够帮助我们进行Web应用的负载测试和功能测试。JMeter可以模拟多用户并发访问,...
jmeter 入门使用教程 jmeter 是 Apache 组织开发的开源项目,设计之初是用于做性能测试的,同时它在实现对各种接口的调用方面做的比较成熟,因此常被用做接口功能测试和性能测试。 jmeter 能够很好地支持各种常见...
JMeter是Apache软件基金会旗下的一个开源的性能测试工具,主要用于Web应用的压力测试。在性能测试领域,它被广泛使用,尤其适合于对静态和动态资源的性能测试,例如:静态文件、Java小服务程序、CGI脚本、Java对象、...
【标题】"性能测试之Jmeter入门.zip" 提供了一个关于使用JMeter进行性能测试的基础教程,这是一款广泛应用于Web应用的压力和负载测试工具。在IT行业中,性能测试是确保软件系统在高并发、大数据量情况下依然能稳定...
"JMeter入门宝典:安装步骤与基础教程"是一份专为初学者准备的全面指南,旨在帮助用户快速掌握Apache JMeter这一功能强大的性能测试工具。宝典从JMeter的基本概念和用途讲起,详细介绍了系统要求、详细的安装步骤、...
jmeter基础入门必备 JMeter 是一个功能强大且广泛使用的性能测试工具,旨在帮助开发者和测试人员评估 Web 应用程序的性能和可扩展性。本文将从 JMeter 的基础知识开始,逐步介绍 JMeter 的安装、配置、测试组件、...
### JMeter入门使用教程 #### 一、JMeter简介 **Apache JMeter**是一款由Apache组织开发的开源软件,主要用于压力测试。它最初被设计用于Web应用的压力测试,但随着时间的发展,其应用范围逐渐扩展到了其他的测试...
Jmeter 入门指南 Jmeter 是 Apache 组织开发的基于 Java 的压力测试工具,用于对软件做压力测试。它最初被设计用于 Web 应用测试,后来扩展到其他测试领域。Jmeter 主要功能包括压力测试、接口测试、功能测试和回归...
jmeter软件ApacheJMeter_V5.4+JMeter图文入门教程(绝对的适合新手,最佳入门系列) apache jmeter是一款Apache组织开发的基于Java的强大的web压力测试工具,能够对电脑系统的性能和负载进行快速测试,也可以对应用...
**JMeter入门:Java Request实例** Apache JMeter是一款强大的性能测试工具,主要用于Web应用的压力测试。它是一款开源软件,遵循Apache License 2.0协议,适用于多种操作系统,如Windows、Linux和Mac OS等。JMeter...
jmeter入门培训资料!下载之后拿来即用,学习,培训都可。欢迎下载