an introduction to performance testing using jmeter · pdf filenow, you can install jmeter...

13
AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER

Upload: vuongphuc

Post on 12-Mar-2018

254 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

AN INTRODUCTIONTO PERFORMANCE

TESTING USING JMETER

Page 2: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

11XBOSOFT.COM CONTACT US AT [email protected]

While this is a technical tutorial, it’s meant to be introductory. If you’re an experienced programmer, this will go pretty quickly. Even if you don’t have programming experience, you’ll be able to follow along, though — JMeter has a graphical user interface. And if you’re already familiar with JMeter, connect with us and tell us what aspects of JMeter you'd like more information about. And feel free to share JMeter problems you've encountered.

J Meter isn’t the only load testing or performance

measuring tool out there, but it has a lot going for it. Partof that is due to the software’s age. JMeter’s �rst release was in

1998, so it’s had plenty of time to grow and evolve. JMeter

keeps improving, especially when it comes to testing web

applications:

• Open source: JMeter is open source. Anyone can

update and modify JMeter for their own uses. It’s

adaptable and extensible to a wide variety of projects.

• Well-maintained: While JMeter would be able to vote

this year if it were a person, it’s been thoroughly

modernized. The most recent release, Version 3.1, came

out in November and works with Java 7+.

• Extendable: JMeter is designed around plugins, even

for core functionality. JMeter users have built plugins for

all sorts of special cases, letting us quickly adapt existing

technology to new projects. And the plugin-based

architecture means that you don’t need to mess around

with con�gurations and tweaks that aren’t relevant to

whatever you’re working on.

• Java-based Given that Java is one of the most popular

programming languages out there, you can easily hire

sta� or contractors who can use JMeter (with a little bit of

education).

• Reporting: JMeter has extensive built-in reporting

capabilities. Good reports are invaluable because you can

�x problems without sinking too much time into analysis.

WHY USE JMETER?

eveloping online applications? Worried about performance? You should consider adding JMeter to your testing toolbox. In

this tutorial, we’re going to walk through the basics of setting up JMeter, one of the most popular open source tools used in

performance testing for web-based applications.

D

Page 3: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

J Meter is a great tool, but it shouldn’t be your only tool.

While all problems may start to look like nails when you

only have a hammer, life is a lot easier when you have other

options in your toolbox.

JMeter is best suited for testing web applications. In particular,

you can design and execute load and performance tests with

many di�erent applications, servers and protocol types

including:

• Web - HTTP, HTTPS (Java, NodeJS, PHP, ASP.NET, …)

• SOAP / REST Webservices

• FTP

• Database via JDBC

• LDAP

• Message-oriented middleware (MOM) via JMS

• Mail - SMTP(S), POP3(S) and IMAP(S)

• Native commands or shell scripts

• TCP

• Java Objects

T o start, you’ll need to install JMeter on your computer.

JMeter requires Java.

Let’s check if you have Java installed. Open the terminal or

console for your operating system and type the following

commands:

• For Windows (in Command Console):

c:\> java -version

• For Mac (in Terminal):

machine ~ machinename$ java -version

• For Linux (in Command Terminal):

$ java -version

If you get any sort of error message that shows you don’t have

Java installed, you can follow these instructions to set up the

Java Development Kit on your computer.

Next, you’ll set the environment variable (so your computer

knows where to look for JMeter �les, once you install them).

• For Windows (in Command Console):

Set the environment variable JAVA_HOME

to C:\Program Files\Java\jdk1.7.0_25

• For Mac (in Terminal):

export JAVA_HOME=/Library/Java/Home

• For Linux (in Command Terminal):

export JAVA_HOME=/usr/local/java-current

WHEN JMETER ISN’T THE SOLUTION

INSTALLATION

12XBOSOFT.COM CONTACT US AT [email protected]

Page 4: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

Now, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable �les on

their website.

Once JMeter is installed, you can open the program. The �le name will depend on your operating system:

• For Windows (in Command Console): jmeter.bat

• For Mac (in Terminal): jmeter.sh

• For Linux (in Command Terminal): jmeter.sh

The graphical user interface for JMeter should launch. Figure 1 shows the JMeter interface upon launching JMeter.

13XBOSOFT.COM CONTACT US AT [email protected]

Figure 1. Launching JMeter

Page 5: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

13XBOSOFT.COM CONTACT US AT [email protected]

T est plans are the container JMeter uses for running your

tests. A test plan de�nes what you want to test and howto do so.

Within a test plan, you’ll have at least one thread group. If

you’re not familiar with Java, a thread group is a convenient

way to group the tasks that a particular program performs.

When you �rst launch JMeter, you’ll need to create a test plan.

When you start up JMeter, there will be a blank test plan and

workbench. JMeter will set up a workbench automatically with

your test plan, so you’ll have a place to temporarily store test

elements as you work. If you do recordings, this is when the

workbench is most helpful as the workbench will

automatically store test elements. However — and this is

important! — when you save your test plan, your workbench

items are not saved with it. See Figure 2.

WRITING A TEST PLAN

Figure 2. Saving Your Test Plan

Page 6: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

Your new test plan is blank, though: it won’t test much of anything until you add elements to it. You can either ‘add,’ ‘merge,’ or ‘open’

new and existing elements to your test plan by right-clicking on your test plan in the JMeter ‘File’ menu as shown in Figure 3.

A test plan describes a series of steps JMeter will execute when run. A complete test plan will consist of one or more Thread Groups.

Try adding a thread group element to your test plan:

• Right click on ‘Test Plan’ on the existing tree elements.

• Choose ‘Add’ > ‘Threads (Users)’ > ‘Thread Group’. See Figure 4 on the next page.

14XBOSOFT.COM CONTACT US AT [email protected]

Figure 3. Adding Elements to Your Test Plan

Page 7: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

Next, let’s save your new test plan. It may be early in the process, but saving early and saving often can prevent a lot of trouble down

the line. Use either ‘Save’ or ‘Save Test Plan As,’ under the ‘File’ menu shown in Figure 5.

15XBOSOFT.COM CONTACT US AT [email protected]

Figure 4. Adding Threads

Figure 5. File Menu; Saving a Test Plan

Page 8: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

unning your test plan is easy when you have JMeter’s interface open. Under the ‘Run’ menu, just click ‘Start’ as shown in

Figure 6 on the next page.

16XBOSOFT.COM CONTACT US AT [email protected]

R

RUNNING A TEST PLAN

Figure 6. Running a Test Plan

Page 9: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

sually we will not stop a script. However sometimes we need to stop it for some instances, verifying an error, debugging a

script, noting an incomplete or incorrect con�guration, etc. You have two options in the ‘Run’ menu:

• ‘Stop,’ which will stop all threads immediately if possible.

• ‘Shutdown,’ which will request all threads to stop at the end of any current work. See Figure 7.

U

17XBOSOFT.COM CONTACT US AT [email protected]

Figure 7. Stopping Execution

STOPPING A TEST

Page 10: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

These steps are just the beginning. You can do a lot more within JMeter, especially once you’ve added some plugins. Some of the

most common plugins that we use include:

• JSON Plugins (jp@gc - JSON Path Extractor): Allows extracting values from JSON responses using JSONPath syntax.

It also has JSONPath Assertion. See Figure 8.

• Stepping Thread Group: JMeter has only one out-of-the-box option for thread (users) scheduling: simple ramp-up.

But many users, especially with HP LoadRunner experience miss a more �exible thread scheduling algorithm. Stepping

Thread Group adds to JMeter thread scheduling similar to LoadRunner‘s. Some of the features of Stepping Thread

Group include:

• preview graph showing estimated load

• initial thread group delay to combine several thread group activities

• increase load by portions of threads (users) with ramp-up period

• con�gurable hold time after all threads started

• decrease load by portions

Figure 8. JSON Plugin

18XBOSOFT.COM CONTACT US AT [email protected]

Page 11: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

Figure 9. Stepping Thread Group plugin

Figure 10. Parameterized Controller

19XBOSOFT.COM CONTACT US AT [email protected]

• Parameterized Controller: if you need to reuse parts of a test plan like regular programming language functions and

procedures, especially calling repeating sequences of the same action with di�erent parameters, Parameterized

Controller can provide this function. See Figure 10.

These are just a few of the plugins available that we use often to customize and add to JMeter’s capabilities. So click around, add some

plugins, and experiment with all of JMeter’s features. And if you run into problems, let us know. We’ve seen most of them over our

many years in working with JMeter and we’re happy to help. Just contact us.

Page 12: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les

110XBOSOFT.COM CONTACT US AT [email protected]

ABOUT XBOSOFT

XBOSoft is a software testing and quality assurance company that o�ers services in web, mobile and desktop applications, as well

as broad domain experience with extended expertise in healthcare, �nance, and software security. XBOSoft’s quality process

assessments and test methodologies speed products to market and improve our clients’ software quality and performance

throughout the software’s life cycle.

With a proven track record working for Fortune 100 companies to small independent developers, XBOSoft today has over 100

employees in San Francisco and Beijing serving clients in the US and Europe. As the �rm surpasses its tenth year of continuous

growth, XBOSoft proudly o�ers its full range of testing and quality assurance as both on and o�-shore services.

PHONE: +1 703 995 9896 EMAIL: [email protected] XBOSOFT

Page 13: AN INTRODUCTION TO PERFORMANCE TESTING USING JMETER · PDF fileNow, you can install JMeter from the Apache Software Foundation. Follow their directions and get the downloadable ˜les