From accessing production readiness, finding the source of performance problems to discovering which application parts are performing poorly, performance testing is the answer to all of your questions. Key performance testing types that help you maintain superior quality are load testing, stress testing, volume/capacity testing, endurance testing, and scalable testing.

Moving ahead, choosing the best tool to conduct performance testing is a big concern. JMeter is an open-source tool provided by Apache that can be used for performance testing of different kinds of client-server applications like websites, web services, databases, FTP servers, etc.

Whether it is cost, customization, community support, record and playback feature, platform independency or versatility to test performance testing type, Jmeter is here to the rescue. This blog will get down to the nitty-gritty to explain why and how Jmeter can be your best bet for performance testing.  

Performance testing determines whether the application meets speed, scalability, and stability requirements under expected workloads. Some common performance bottlenecks are

  • CPU utilization
  • Memory utilization
  • Network utilization
  • Operating System limitations
  • Disk usage

Let’s take a deep dive into JMeter.

JMeter is the most popular open-source load testing tool. The following are the steps mentioned to start the JMeter.

Steps to start Jmeter

  1. Install the latest 64-bit JRE or JDK. This is needed as JMeter is a pure Java application.
  2. The latest version of JMeter is Apache JMeter 5.2.1. You can download it here http://jmeter.apache.org/download_jmeter.cgi)
  3. Unzip the zip/tar file into the directory where you want JMeter to be installed.

Following directories you will find in a Jmeter Directory:

    •   /bin: Contains JMeter script file for starting JMeter
    •   /docs: JMeter documentation file
    •   /extras: ant related extra files
    •   /lib/: Contains the required Java library for Jmeter
    •   /printable_docs:
  1. To start Jmeter go to /bin directory 
    • For Mac/Linux/Unix: ./jmeter.sh
    • For Windows: jmeter.bat

JMeter Elements

JMeter Test Plan: 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, Logic Controllers, Sample Generating Controllers, Listeners, Timers, Assertions, and Configuration Elements.

Run Jmeter thread groups consecutively

If you have multiple Thread Groups and run them they will be executed in parallel. In some scenarios, it causes some problems(i.e dependency between thread groups). In that case, you need to run your thread groups consecutively. 

ThreadGroup

Threads mean no. of Virtual Users in a JMeter.

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

How to add ThreadGroup: Right Click on Test Plan-> Hover over Threads(Users)-> Click Thread Group


Let’s explore the Thread Group options

  • Number Of Threads: It represents the total number of virtual users performing the test script execution.
  • Ramp-Up Period (in seconds): It tells JMeter how long it takes to reach the full number of threads. For example, if you have 100 users with a ramp-up period of 50 seconds, JMeter will take 50 seconds to get all 100 threads running, adding 2 threads per second.
  • Loop Count: It is the number of executions for the script. For example, if the loop count is 2 and the number of threads is 100 then the script will run 200 times. If the loop count is set “forever” then new threads will keep starting until the tests are stopped.

Samplers

Samplers in JMeter allows JMeter to send different types of requests to a server.

How to add Samplers: Right Click on Thread Group -> Hover over Add -> Hover Over Sampler -> Click on the required Sampler


Name: Any logical name in order to distinguish your request.

Protocol: It mentions the protocol used for example HTTP or HTTPS. 

Server Name: This is the domain name of the server

Method: Any of the methods such as GET, PUT, POST, DELETE, etc may be selected from the       drop-down

Path: This is the path of the resource. For example “/wiki/Cheese”.

Parameters: Any parameters that are required to be passed will be added in this section.

Body Data: This comes into picture if any JSON, XML, etc needs to be passed in the request. That is added to Body Data.

HTTP Request Defaults

If you are going to send multiple requests to the same web server, consider using an HTTP Request Defaults Configuration Element so you do not have to enter the same information for each HTTP Request.

How to add : Right Click on either of Test Plan/Thread Group/Logic Controller -> Hover over Add -> Hover Over Config Element -> Click on the HTTP Request Defaults

Logic Controllers

Logic Controllers will decide “When & How” to send a request to a web server.

How to add: Right Click on Thread Group -> Hover over Add -> Hover Over Logic Controllers -> Click on the required Logic Controllers

Random Controller makes all the user requests run in the random order in each loop period.

For example, you have 3 user requests to website http://www.google.com in the following order:

  1. HTTP request
  2. FTP request
  3. JDBC request

PreProcessors

Pre-Processors executes some action just prior to a sample being run.The Pre Processor elements are used to modify the sampler requests before their processing(hence the name pre-processor).

How to add PreProcessor: Right Click on either of Test Plan/Thread Group -> Hover over Add -> Hover Over Add element-> Click on the PreProcessors

Example: User Parameters

User Parameters are used to define values for the variables before they are used in the Samplers. When JMeter executes this Pre-Processor element, it stores the values in the variables which can be referenced by any Samplers within the same thread group.

Post-Processor 

It will be executed when a Sampler Request finishes its execution. If you need to use a post-processor for a particular Sampler, then add it as a child of that Sampler

How to add Post-Processor: Right Click on either of Test Plan/Thread Group -> Hover over Add -> Hover Over Add element-> Click on the 

Post-Processors

Example: Regular Expression Extractor

It allows the user to extract values from a server response using a Perl-type regular expression.


Assertions

An assertion in JMeter is used to validate the response of the request that you have sent to the server.

How to add Assertions: Right Click on either of Test Plan/Thread Group -> Hover over Add -> Hover Over Add element-> Click on theAssertion Assertions

Example: Duration Assertion: The Duration Assertion tests that each server response was received within a given amount of time. Any response that takes longer than the given number of milliseconds (specified by the user) is marked as a failed response.

Timer

Timers allow JMeter to delay between each request which a thread makes. A timer can solve the server overload problem.

How to add Timer: Right Click on Thread Group -> Hover over Add -> Hover Over Timer -> Click on the required Timer


Example: Constant Timer

Constant timer delays each user request for the same amount of time. If there are no timers, Jmeter will send the next request in fractions of seconds.

Configuration Elements

Configuration Element enables us to declare variables, so Samplers can use data through these variables. 

How to add a Config element: Right Click on either of Test Plan/Thread Group/Logic Controller -> Hover over Add -> Hover Over Config Element -> Click on the required Config Element

Example:

1.Counter

The counter config element is used to create a variable that gets incremented by specified value in each iteration within a range of minimum and maximum values.

2. CSV Data Set Config

CSV Data Set Config element is used to read data from a text or CSV format file. For Example, If you need to perform a load test of a login scenario with 100 unique users. Prepare the data in CSV file with 100 user records with username and password, and you can use this file data in every thread through variables in your requests/samplers by using this configuration element.

Let’s take a look at how the CSV Data Set is configured:

  • Filename: the path to the CSV file containing the data,
  • File Encoding: can be UTF-8 for example. The character encoding affects how the file is read,
  • Variable Names: comma-delimited list of names, should be the equal number of names than columns in the CSV file. Example: login, password.
  • Recycle on EOF: true by default, should JMeter restart from the beginning when the End Of File is reached

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 can be added anywhere in the test, including directly under the test plan. They will collect data only from elements at or below their level.

For example, if we add a Listener to a Thread Group, they only collect information specific to that Thread Group. If you have 3 Thread Groups and a listener attached to each one, those three listeners will show three different sets of data.

How to add a Listener: Right Click on Test plan -> Hover over Add -> Hover Over Listener -> Click on the required Listener


Non-Test Element 

Example  :HTTP(S)TestScriptRecorder

HTTP(S) Test Script Recorder can be used to record all the requests which your web application is making to the server. 


Below is the process of using this recorder:

  1. Add Non-Test Element HTTP(s) Test Script Recorder 
  2. Enter the port number which is not in use.
  3. Apply proxy on the browser you want to record and use the same port number.
  4. Start the JMeter Proxy Server
  5. Record the Actions

Reducing resource requirements

Some suggestions on reducing resource usage.

  • Use the CLI mode: jmeter -n -t test.jmx -l test.jtl
  • Use as few Listeners as possible; if using the -l flag as above they can all be deleted or disabled.
  • Don’t use “View Results Tree” or “View Results in Table” listeners during the load test, use them only during the scripting phase to debug your scripts.
  • Rather than using lots of similar samplers, use the same sampler in a loop, and use variables (CSV Data Set) to vary the sample. [The Include Controller does not help here, as it adds all the test elements in the file to the test plan.]
  • Don’t use functional mode
  • Use CSV output rather than XML
  • Only save the data that you need
  • Use as few Assertions as possible

Jmeter Test Plan Result

How to resolve HTTP 400 Bad Request error?

Solution: Check payload, URL, headers, port number and path.

How to resolve HTTP 500 internal server error?

Solution: Execute the same request manually using browser also verify which URL out of the 10 under test is creating a bottleneck

This article was authored by Tejal Chaskar, who is a QA - Performance Tester at Zymr.

0 comments

Leave a Reply