How To Use JMeter Elements?

Somethings that we may be concerned about when developing the website are: What will happen to the web server(s) in such severe load conditions when multiple users are going to access the system simultaneously?

Of course!! An application may get hanged.

Fortunately one does not need to get panicked with this situation as there is a software which can help us to deal with these issues and that is JMeter!

JMeter is the tool to measure a website’s performance. Basically, this tool is developed for performance testing of web applications but in fact, it can do much more than that. It has a very complex architecture that provides support for several inbuilt elements and allows extending the functionality of JMeter through plugins. It has many elements like Samplers, Processors, Listeners etc. In simple terms, different types of Elements represent the different features provided by JMeter. Each Element is designed for a specific purpose.

Studying all the components at one go is an invitation to muddle, right?. So here, we will discuss the must-know components in JMeter. For the basics and installation of JMeter, you can refer supportive source:

https://www.loginworks.com/quality-assurance/test-web-services-jmeter/

Elements Of JMeter

The figure below gives some common elements in JMeter:

Test Plan

If you want to check performance, you need a test plan.It narrates a series of test steps, which JMeter will execute and run. Test Plan is the root element of JMeter as shown in the above figure.Test Plan is also the biggest component in JMeter architecture and is at the top of the hierarchy.

There are one or many elements in a complete Test Plan such as Thread Group, Samplers, Listeners, Timers etc. Also, there is one point to be noted here: A Test Plan always has at least one Thread Group.

Thread Group

Thread Group is the most basic element starting point of any Test Plan. It is commonly referred as a collection of Threads. It controls all the threads that JMeter uses to execute the test cases. The controls for a thread group allow you to Set the number of threads for each group.

Each thread illustrates one user using the application under test. Above all, each Thread replicates one real user request to the server. For example, if you set the number of threads as 100; JMeter will create and simulate 100 user requests to the server under test.

Example:

Let’s consider following scenario. During a promotional campaign, 100 real users connect concurrently to the server and use your web application. Each user will create a working session for that web application.

JMeter defines that session as a Thread. Each thread replicates a real user who connects to the web server. JMeter allows Thread Group to be configured as follows:

  • Number of Threads in Thread Group describes the replicate number of real users connected to the web server.
  • Set the duration(ramp-up period) within which all threads have to be run.
  • Number of times to execute each thread (each thread can repeat a certain number of times)
  • Set the schedule to start the thread

All controllers and samplers can only be added to a Thread Group and the other elements, like Listeners (which we cover later in this topic), can be added to a Test Plan or Thread Group. When they are added to a Test Plan in JMeter, they are associated with all the Thread Groups in the Test Plan. When controllers and samplers are added to a Thread Group, they apply only to that Thread Group.

Controllers

JMeter has two types of Controllers: Samplers and Logical Controllers. Both the controllers drive the processing of the test.

In the Samplers section, we will discuss how JMeter creates a request to the server. But there is another need i.e. If we want to control those requests based on a logic such as setting the schedule to send that request, determine which request to be sent… etc. what should we do?

JMeter provides you with the element to do it. It is the Logic Controller.

Samplers

A very interesting question you must have like how JMeter creates a request to the server or how does a Thread Group know which type of requests (HTTP, FTP etc.) it needs to make?

The answer….Using Sampler

The user request could be:

  • FTP Request
  • HTTP Request (can be used for SOAP or REST Webservice also)
  • JDBC Request
  • SMTP and many more…

We will discuss these request on our next blog!!!

Logical Controllers

Earlier in the Samplers section, we discussed how JMeter creates a request to the server. The question is – If we want to control those requests based on a logic such as setting the schedule to send that request, determine which request to be sent and the order of processing Samplers/Requests in a Thread. … etc. what should you do?

JMeter provides you with the element to do it. It is the Logic Controller. Also Logic Controllers will decide “When & How” to send a request to a web server. Logic Controllers can change the order of requests coming from their child elements.

There are following common Logic Controllers. You can use appropriate Controller based on your specific requirement.

We will discuss Logic Controllers in detail on our next blog on.

Processor

The processor is used to modify the Samplers in their scope and customise the Samplers functionality. There are two types of processors in JMeter, PreProcessor and Post Processor.

Pre-Processor

Pre-processor tends to execute few actions before making Sampler Request. It will execute just prior to that sampler element running, if a Pre-Processor is attached to a Sampler element. A Pre-Processor is mostly used to alter the settings of a Sample Request just before it runs, or to update variables that aren’t extracted from response text.

Post-Processor

Post-processor tends to execute few actions after making Sampler Request. It will execute just after that sampler element runs, if a Post-Processor is attached to a Sampler element. A Post-Processor is mostly used to process the response data, often to extract values from it.

Config Element

Config Elements in JMeter allow the user to change the request they create.A configuration element works closely with a Sampler. However it does not send requests, it can add to or alter requests.

A configuration element is accessible from only inside the tree branch where you place the element. For example, the Cookie Manager will only be accessible to HTTP Request Controllers you place inside the Simple Logic Controller, if you place an HTTP Cookie Manager inside a Simple Logic Controller.

Following are commonly used configuration elements in JMeter:

Assertion

An assertion in JMeter is used to validate response to the request, that you have sent to the server. Using an assertion, you can essentially “test” that your application is returning the results you expect it to. Assertions are statements that verify the test results as either positive or negative. Assertions in JMeter can be applied to many elements such as Test Plan, Thread Group or Samplers.

You can add an assertion to any Sampler. Let’s take an example, In an HTTP Request, you can add an assertion that checks for the text, “</HTML>“. JMeter is then obliged to check that the text is present in the HTTP response. This request will however be marked as fail, if JMeter is unable to find the text.

To view assertion results, add an Assertion Listener to the Thread Group. Failed Assertions will also be displayed in the Tree View and Table Listeners, and will count towards the error percentage for example in the Aggregate and Summary reports.

“Assertions apply to all samplers which are in their scope. To restrict an assertion to a single sampler, add the assertion as a child of the sampler.”

Listeners

So far, we have seen how Samplers are used to create and send a request to the server to complete a performance test. Processors can be used to modify the request or the response. After creating and sending the request to the server, JMeter receives the results returned from the server. ….Listeners help users to access the server response and analyze the test results.

It shows the results of the test execution. They can show results in different formats such as a tree, table, graph or log file. Listeners can be added anywhere in the test, including directly under the test plan. They will gather data only from elements at or below their level.There is the number of listeners that come with JMeter. Some of the commonly used Listeners in JMeter are explained below:

Graph result listeners display the server response times on a Graph.

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

Table Result display summary of test results in table format.

Log display summary of the test results in the text file.

Timers

By default, a JMeter thread executes samplers in sequence without pausing. In that case, JMeter could overwhelm your test server by making too many requests in a short amount of times. Let imagine that you send thousands request to a web server under test in a few seconds. What will happen??

Therefore, you need to create a time delay between each request. JMeter offers elements called the Timer elements that you can use in such situations. The purpose of Timer elements is to pause a JMeter Thread representing a virtual user, for a definite amount of time. If you want to add more than one timer to a Thread Group, JMeter catch the sum of the timers and pauses for that amount of time before executing the samplers to which the timers apply. Timers can be added as children of samplers or controllers in order to restrict the samplers to which they are applied.

Following are some common types of  Timer in JMeter:

  • Constant Timer
  • Uniform Random Timer
  • Gaussian Random Timer
  • BeanShell Timer
  • BSF Timer

Constant Timer: Constant timer delays each user request for the same amount of time.

Uniform Random Timer: Uniform random timer delays each user request for a random amount of time.

Gaussian Random Timer: Gaussian random timer delays each user request for a random amount of time.

BeanShell Timer:  The BeanShell Timer can be used to produce a delay time between each user request.

BSF Timer: In order to produce a delay between each user request with the help of BSF scripting language, BSF Timer can be used.

We will surely discuss these in depth on our next relative blog…

Execution Order

  • Configuration elements
  • Pre-Processors
  • Timers
  • Sampler
  • Post-Processors
  • Assertions
  • Listeners

” Timers, Assertions, Pre- and Post-Processors are only processed if there is a sampler to which they apply. Logic Controllers and Samplers are performed according to the order in which they appear in the tree. Other test elements are processed according to the scope in which they are found, and the type of test element. [Within a type, elements are processed in the order in which they appear in the tree].”

As a result, we can conclude that JMeter processes Samplers and Logic Controllers in the sequence that they appear in the Test Plan. Pre Processors, Post Processors, Assertions, and Timers are only processed if they are associated with a Sampler. Thus we have learned about all components or Elements of Jmeter.

In the next topic, we will cover these elements also in detail. So stay tuned for the next article…

Follow me!

Leave a Comment