JMeter Elements: Thread Group, Samplers, Listeners, Configuration

What is Element in JMeter?

The different components of JMeter are called Elements. Each Element is designed for a specific purpose.

The figure below gives some common elements in JMeter.

Elements in JMeter

Studying all the components in one go is an invitation to confusion and boredome. Here, we will discuss the must-know components before you can start Testing in JMeter.

Remaining components will be discussed as when they are used in the succeeding tutorials. The elements discussed in this tutorial are

Thread Group

Thread Groups is a collection of Threads. Each thread represents one user using the application under test. Basically, each Thread simulates one real user request to the server.

The controls for a thread group allow you to Set the number of threads for each group.

For example, if you set the number of threads as 100; JMeter will create and simulate 100 user requests to the server under test

Thread Group

Samplers

As we know already that JMeter supports testing HTTP, FTP, JDBC and many other protocols.

We already know that Thread Groups simulate user request to the server

But how does a Thread Group know which type of requests (HTTP, FTP etc.) it needs to make?

The answer is Samplers

The user request could be FTP Request, HTTP Request, JDBC Request…Etc.

Samplers

FTP request

Let’s imagine you want to performance test an FTP server. You can use an FTP request sampler in JMeter to do this task. This controller lets you send an FTP “download file” or “upload file” request to an FTP server.

FTP Request

For example, if you want to download a file “Test.txt” from an FTP server under test, you need to configure some parameters in JMeter as the figure below

FTP Request

JMeter will send FTP command to FTP server ftp.example.com, and then download a file Test.txt from that server.

HTTP request

This sampler lets you send an HTTP/HTTPS request to a web server.

Consider the example below. JMeter sends an HTTP request to Google website and retrieve HTML files or image from this website.

HTTP Request

In the tutorial JMeter Performance Testing, we will explain more about this HTTP request.

JDBC request

This sampler lets you execute Database Performance Testing. It sends a JDBC Request (an SQL query) to a database.

JDBC Request

For example, a database server has a field test_result stored in a table name test_tbl. You want to query this data from the database server; you can configure JMeter to send a SQL query to this server to retrieve data.

JDBC Request

BSF Sampler

This sampler allows you to write a sampler using a BSF scripting language.

Here is an example of BSF Sampler in JMeter

BSF Sampler

Access Log Sampler

This sampler allows you to read access logs and generate HTTP requests. The log could be image, Html, CSS…

Access Log Sampler

SMTP Sampler

If you want to test a mail server, you can use SMTP sampler. This sampler is used to send email messages using the SMTP protocol.

SMTP Sampler

Listeners

Listeners: shows the results of the test execution. They can show results in a different format such as a tree, table, graph or log file

Listeners

Graph result listeners display the server response times on a Graph

Listeners Graph Result

View Result Tree show results of the user request in basic HTML format

View Result Tree

Table Result show summary of a test result in table format

Table Result

Log show summary of a test results in the text file

Log show

Configuration Elements

set up defaults and variables for later use by samplers.

The figure below shows some commonly used configuration elements in JMeter

Configuration Elements

CSV Data Set Config

Suppose you want to test a website for 100 users signing-in with different credentials. You do not need to record the script 100 times! You can parameterization the script to enter different login credentials. This login information (e.g. Username, password) could be stored in a text file. JMeter has an element that allows you to read different parameters from that text file. It is “CSV Data Set Config”, which is used to read lines from a file, and split them into variables.

CSV Data Set Config

This is an example of CSV Data. It’s a text file which contains user and password to login your target website

CSV Data Set Config

HTTP Cookie Manager

Let’s understand this with an example –

You used your browser (Firefox, IE…Etc) to browse www.google.com

You log in with your user and password.

Your username and password will be stored in your computer as cookies.

Next time, when you visit www.google.com, you don’t need to do log in again because your browser will use your cookies as user data to log in.

HTTP Cookie Manager also has the same feature as a web browser. If you have an HTTP Request and the response contains a cookie, the Cookie Manager automatically stores that cookie and will use it for all future requests to that particular website.

HTTP request default

This element lets you set default values that your HTTP Request controllers use.

For example,

You are sending 100 HTTP requests to the server google.com

You would have to manually enter server name = google.com for all these 100 requests

Instead, you could add a single HTTP request defaults with the “Server Name or IP” field = google.com

No need to type 100 times!

HTTP Request Default

This element will be explained in detail in tutorial JMeter Performance Testing

Login Config Element

The Login Config Element lets you add or override username and password settings in samplers.

For example, you want to simulate one user login to website www.facebook.com with user and password. You can use the Login Config Element to add this user and password setting in a user request

Login Config Element

The Login Config Element vs. the CSV data Config

Login Config Element CSV Data Config
Used to simulate one user login Used to simulate multiple user login
Suitable for login parameter only (user and password) Suitable for large numbers of parameters