• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JMeter Tutorial

February 10, 2016 //  by Krishna Srinivasan//  Leave a Comment

JMeter is a software that is very useful for load test, performance test and various other testing requirements of your application. This tool is developed and maintained by Apache Software Foundation as open source project. In most of the projects, JMeter tool is primarily used for load test the web applications. It is a simple Java desktop tool that can run on any environment where JVM is installed. In this JMeter tutorial, I am going to explain the following topics.

JMeter Logo

The list topics covered in the tutorial is:

  1. Protocols support
  2. How to install and run JMeter?
  3. Creating a test plan?
    1. Add a thread group
    2. Add a HTTP request defaults
    3. Add a HTTP request sampler
    4. Add a view results in table listener
  4. Run JMeter in command line
  5. Best Practices for JMeter
  6. Summary
  7. JMeter References and Books

Protocols Support

The following protocols are supported by JMeter:

  • Web – HTTP, HTTPS
  • Web Services – SOAP / XML-RPC
  • Database via JDBC drivers
  • Directory – LDAP
  • Messaging Oriented service via JMS
  • Service – POP3, IMAP, SMTP
  • FTP Service

How to Install and Run JMeter?

JMeter is a stand-alone desktop application built on Java  Swing APIs. It is very simple to install and run the JMeter tests without any programming knowledge. Follow the steps to download and install in your system.

  • Download the JMeter software from download. The latest version of JMeter is 2.13, the minimum version of Java 6 is required to run.
  • Once downloaded, just extract the zip file into your system. There is no further configurations required to run the JMeter tool.
  • In Windows OS, just invoke the jmeter.bat under directory apache-jmeter-2.13\bin. This will open a JMeter GUI.
  • That’s it, you have installed JMeter in your system. The next step would be to configure the test plan and execute the tests.

jmeter

Creating a Test Plan

In this section, I am going to explain about how to create a basic test plan for measuring the response time a web page using JMeter GUI screens. A test plan is the root element in the left side menus. A test plan is created using the various components and configured to simulate particular scenario.

If you want to run any tests, first thing you have to configure the test plans by adding various components in the JMeter. The following are the some of the components that are used for simulating a test scenario.

Here is the basic structure of a test plan in the GUI mode:

TestPlan Components

Add a thread group

As a first step, please add a thread group to your test plan. This must be the first step for creating the test plans. A thread group is a set of threads executing the same scenario. Test users are simulated using threads. Threads are created as part of the thread group.

Steps to add thread group:

  1. Right-click on Test Plan
  2. Mouse over Add >
  3. Mouse over Threads (Users) >
  4. Click on Thread Group

Here is the basic elements in the thread group:

Thread Group in JMeter
Thread Group in JMeter

 Add an HTTP Request Defaults

HTTP Request Defaults is one of the configuration node in the JMeter components. These configuration nodes are used for defining the common variables for the samplers. In our example, we are defining http request defaults for the http request sampler. These configuration nodes are executed before the samplers, so any fields configured in this defaults and not configured in the sampler will be taken as the default value.

Each sample have it’s own default configuration nodes. Some of them are listed here:

  • FTP Request Defaults
  • HTTP Cache Manager
  • HTTP Cookie Manager
  • Java Request Defaults
  • LDAP Request Defaults

Steps to add HTTP request defaults:

  1. Select Thread Group, then Right-click it
  2. Mouse over Add >
  3. Mouse over Config Element >
  4. Click on HTTP Request Defaults

Here is the basic elements in the HTTP request defaults:

HTTP Request Defaults in JMeter
HTTP Request Defaults in JMeter

Web Server Details

This section helps you to configure the default server details for all the HTTP request samplers. You can fill only the necessary fields and leave all other fields as blank. For example, Server Name and Port Number fields are common for all the request, so you can fill in the details here and leave it as blank in the individual request sampler form.

HTTP Request Details

Update your request details like Path, Protocol, etc. which are common for all the requests here.

Proxy Server Details

Proxy server tab in the HTTP request defaults helps you to configure the proxy servers, if you are running the tests behind a proxy server and trying to access the web application that is outside your network. This situation arises when you are working inside a company and trying to execute tests using the live website URLs. If your company is using the .PAC file for routing the proxy server, you could open the .PAC file and note down the IP address of the proxy server and port address. There are four fields to e filled depends on the environment.

JMeter Proxy Configuration

  • Server Name or IP
  • Port Number
  • Username
  • Password

Add an HTTP Request Sampler

A sampler is a component that is used for sending the request to different kind of servers. For example, if your test has to perform the HTTP request, then you have to add the HTTP Request Sampler to your test plan. Like that we have various samplers built-in with JMeter.

  • FTP Sampler
  • JDBC Sampler
  • Java Sampler
  • LDAP Sampler
  • JUnit Sampler
  • Debug Sampler

The above mentioned are only few samplers. There is a huge list of samplers available for the configuration. In this tutorial, we are using the http request sampler.

Steps to add HTTP request sampler:

  1. Select Thread Group, then Right-click it
  2. Mouse over Add >
  3. Mouse over Sampler >
  4. Click on HTTP Request

Here is the basic elements in HTTP request sampler:

HTTP Request Sampler in JMeter
HTTP Request Sampler in JMeter

Add a View Results in Table Listener

JMeter has a concept called listeners that are used for displaying the results in different view like table, tree, graphs, etc. to the attache UI screens. To view the response content from a sampler, you have to add the any one of the listener to the test plan for viewing the data.

Here we are using the View Results in Table for viewing the response data in the tabular data. Below is the steps to add the table listener and sample screenshot of displaying the data in a tabular format.

Steps to add view results in table listener:

  1. Select Thread Group, then Right-click it
  2. Mouse over Add >
  3. Mouse over Listener >
  4. Click on View Results in Table
View Results in Table Listener
View Results in Table Listener

Sample Time:

Sample Time or Response Time is the difference between the time when request sent and time when response has been fully received. Response time will be always greater than latency time.

Latency:

Latency is a difference between time when request was sent and time when response has started to be received.

Run JMeter in Command Line

It is not advisable to use JMeter in GUI for actual load test. The reason is that GUI mode consumes lot of memory for processing the data and display to the user. If you performing any serious real time test, it is highly recommended to test it in the command line. In this section I would explain how to run JMeter test in the command line.

jmeter -n -t D:/results.jmx -l D:/report.jtl

JMeter Command Line Tool

In the above command line options,

  • -n tells that you are running the test in non-GUI mode
  • -t tells the complete path of the JMX file (it is the format of the test plan used for JMeter tests)
  • -l tells the complete path of the results where it is stored.The results have the JTL as the file extension. These results can be stored as either XML or CSV format.

Connect time is the time taken to establish the connection between server including SSL handshake.

Best Practices for JMeter

There are many recommended best practices in JMeter for the better performance. Here I am listing down few of the important tips that is wirth remembering while you are executing the test plans.

  • Use non-GUI mode while executing the real time test plans
  • Use only few listeners. The listeners parses the results in easily readable manner, but it consumes lot of memory.
  • View Result Tree listeners consume lot of memory and JMeter may run out of memory. It is recommended to disable or run only enabling “Errors” checked. It is same for all other graphical display inside JMeter.
  • Clean the tab before every test run
  • Monitor the logs
  • Make sure that the JTL file is saved in XML format and not CSV.
  • Assign a meaningful JTL file name

Summary

I hope this tutorial helped you to understand the basic idea on how to use JMeter on GUI and command line mode. We have explored how to create a basic test plan for evaluating the response time for HTTP request. As part of the test plan, we have added HTTP Request Defaults, HTTP Request Sampler and View Results in Table. As you are aware, JMeter is most powerful and popular testing tool for performing load test and stress test for your applications.

After reading this tutorial, let’s try yourself creating a test plan and explore the different configuration elements present in the tool.

Happy Reading!!!

JMeter References / Books

  • Tutorial by Mitchell Anicas in Digital Ocean
  • JTL Files
  • BlazeMeter for Performance Testing
  • Gatling
  • JMeter – Simulate different network speed for load test

Category: JavaTag: Java Performance Testing

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: «java EOFException Example in Java
Next Post: Difference Between Load Testing and Stress Testing java»

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact