Wilson Mar bio photo

Wilson Mar

Hello!

Email me Calendar Skype call

LinkedIn Twitter Gitter Instagram Youtube

Github Stackoverflow Pinterest

to emulate HTTP requests testing load/capacity

US (English)   Español (Spanish)   Français (French)   Deutsch (German)   Italiano   Português   Cyrillic Russian   中文 (简体) Chinese (Simplified)   日本語 Japanese   한국어 Korean

Overview

This tutorial introduces how to install and run JMeter by explaining each setp of an automated script for imposing artificial load on a server created to run RabbitMQ.

Java based!

The “J” in JMeter refers to the Java Virtual Machine (JVM). JMeter is written in Java. That makes JMeter multi-platform on Windows, MacOS, Linux.

  1. Install Java and verify according to my steps (with commentary) at:

    https://wilsonmar.github.io/java-on-apple-mac-osx/

    The Meter in JMeter

    “Meter” refers to being akin to parking meters that measure time. It is said that “Time is money” because when a user waits for the system to respond, he or she is not productive getting work done. And the longer that a transaction takes to respond, the more servers are needed to server everyone.

    Each JMeter program running can emulate hundreds of human users typing and clicking through a web application because JMeter mimics just the network traffic exchanged between clients and servers.

    JMeter is more than response time. Using JMeter enables us to measure how the application server will likely behave under load when running in production. The amount of load imposed by JMeter is often described in terms of the number of “users” JMeter emulates.

    JMeter can submit requests more frequently than real users because JMeter is not a browser – it works at the protocol level. The HTTP requests that JMeter sends to web services listeners look like they came from ordinary browsers. But JMeter does not normally render JavaScript DOM to create HTML nor execute the Javascript in HTML pages.

  2. In an internet browser (Google Chrome, Mozilla Firefox, Apple Safari, etc.), open

    https://github.com/apache/jmeter

    JMeter is offered free because it’s open-sourced as an Apache Foundation project.

    BTW: Historically, JMeter first became available December 2003 as the “Jakarta” project until it became the full-fledged product. Its previous URL is automatically routed from http://jakarta.apache.org/jmeter

  3. Wikipedia lists the version history:

    https://www.wikiwand.com/en/Apache_JMeter


JMeter Installation options

There are several ways to obtain a running instance of JMeter, listed from easiest to most difficult:

A) You don’t need a local machine if you run JMeter within a cloud service such as at Blazemeter.com or Flood.io

But customers at some companies do not trust public clouds. So…

B) Manually download installer to install locally.

C) Manually download installer to install locally.

This is the approach shown by many tutorials (see below)

D) Pull an image from Docker Hub within a Google Compute or AWS cloud instance.

E) Use the Dockerfile to build your own Docker image containing JMeter.

F) Run a Bash script to install JMeter natively on you Mac.

G) Manually type in Terminal commands executed in the automated script.

CAUTION: If you are in a large enterprise, confer with your security team before installing. They often have a repository such as Artifactory or Nexus where installers are available after being vetted and perhaps patched for security vulnerabilities.

Blazemeter SaaS

You don’t need a local machine if you use the cloud service
blazemeter.com

You can’t use blazemeter if your server is behind a firewall because blazemeter is a Saas service running on the public internet.

The SaaS vendor was purchased by CA in 2017.

Users of Blazemeter can use their add-on test framework.

Blogs about this:

  • https://www.blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui
  • https://www.artofsoftwaredevelopment.com/performance/performance-testing-in-the-cloud-with-jmeter-aws

JMeter install

  1. Go to this URL to see the current version available for download:

    http://jmeter.apache.org/download_jmeter.cgi

    PROTIP: Rather than manually downloading (which takes several more steps), install using Homebrew:

    Manually install locally using HomeBrew

  2. On a Mac, with a Terminal at any folder:

  3. See if someone has created a Homebrew formula referencing the binaries so you can install using this command:

    brew info jmeter
    
    You should see something like:
    
    
    jmeter: stable 5.4.1 (bottled)
    Load testing and performance measurement application
    https://jmeter.apache.org/
    /usr/local/Cellar/jmeter/5.4.1 (2,645 files, 124.4MB) *
      Poured from bottle on 2021-06-10 at 12:28:08
    From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/jmeter.rb
    License: Apache-2.0
    ==> Dependencies
    Required: openjdk ✔
    ==> Analytics
    install: 5,558 (30 days), 16,856 (90 days), 75,270 (365 days)
    install-on-request: 5,552 (30 days), 16,842 (90 days), 74,846 (365 days)
    build-error: 0 (30 days)
    
  4. To install “silently”:

    brew install jmeter --with-plugins
    

    Response at time of writing:

    ==> Pouring jmeter--5.4.1.mojave.bottle.tar.gz
    🍺  /usr/local/Cellar/jmeter/5.4.1: 2,643 files, 124.4MB
    

    NOTE: Previously,

    🍺  /usr/local/Cellar/jmeter/3.3: 2,855 files, 101.7MB
    
  5. The script saves the file path other scripts will be using to invoke JMeter just installed:

    echo $JMETER_HOME
    

    At time of writing:

    /usr/local/Cellar/jmeter/5.0/libexec

    Tree JMeter folders and files

  6. To list what folders are in a folder, install the tree utility:

    brew install tree
    
  7. See the version folder located (at time of writing):

    ls /usr/local/Cellar/jmeter
    
  8. Construct a tree command to view folders under the version, at the second level (https://www.computerhope.com/unix/tree.htm):

    tree /usr/local/Cellar/jmeter/5.4.1 -L 2
    

    Sample output:

    /usr/local/Cellar/jmeter/5.4.1
    |-- INSTALL_RECEIPT.json
    |-- LICENSE
    |-- NOTICE
    |-- README.md
    |-- bin
    |   `-- jmeter
    `-- libexec
     |-- bin
     |-- docs
     |-- extras
     |-- lib
     |-- licenses
     `-- printable_docs
    

    The folders:

    bin contains the jmeter executable. Within libexec:

    • bin contains all other executatives, jars, and properties files.
    • docs
    • lib contains library utlity jar files
    • lib/ext contains JMeter components and add-ons
    • extras contains miscellaneous files including samples using the Apache Ant tool
    • licenses contains legal text
    • printable_docs contains the usermanual in html and a demos folder containing jmx files

    Alternately, if you are to be using JMeter on your machine, add the export in your Mac’s ~/.bash_profile file.

  9. Update the profile (and type your password again):

    source ~/.bash_profile
  10. Now skip to the Verify JMeter section below.

Manually JMeter install locally

Alternately, to install manually:

  1. Go to this URL to see the current version available for download:

    http://jmeter.apache.org/download_jmeter.cgi

  2. Define a variable identifying the tgz file to download within the Binaries section, such as:

    JMETER_VERSION_SPEC="apache-jmeter-5.4.1"

    Its URL, such as https://mirrors.gigenet.com/apache//jmeter/binaries/apache-jmeter-5.4.1.tgz uses the mirror server selected (by default) in the same webpage above.

    The “sha512” link provides the hash signature created so that you can determine whether download obtain all the bits by running the same hashing program. If you obtain the same hash value, no bits were changed during download.

  3. Click OK for default Save File:

    jmeter-install-save-file

    The file typically downloads to your “Downloads” folder.

    Instead of clicking the browser’s downloads icon and unzip the downloaded file by double-clicking it:

    jmeter-install-tgz

  4. Switch to a Terminal.

  5. Construct ~/Downloads/apache-jmeter-5.4.1.tgz”:

    DOWNLOADED_TGZ_FILEPATH="$HOME/Downloads/$JMETER_VERSION_SPEC.tgz"
    ls -al "$DOWNLOADED_TGZ_FILEPATH"
    

    A sample response is:

    -rw-r--r--@ 1 wilsonmar  staff  70704620 Jul 24 02:40 /Users/wilsonmar/Downloads/apache-jmeter-5.4.1.tgz
  6. Write the SHA256 hash to a file. Verify the integrity of the downloaded file by looking for “OK” in the second part of check response:

    sha256sum "${DOWNLOADED_TGZ_FILEPATH}" > checksum
    cat checksum
    if [ sha256sum --check checksum | awk '{print $2}' != "OK" ]; then
       echo "sha256 compare failed for ${DOWNLOADED_TGZ_FILEPATH}"
       exit 9
    fi
    

    The response:

    4edae99881d1cdb5048987accbd02b3f3cdadea4a108d16d07fb1525ef612cf3  /Users/wilsonmar/Downloads/apache-jmeter-5.4.1.tgz
    /Users/wilsonmar/Downloads/apache-jmeter-5.4.1.tgz: OK
    

    Alternately, verify the PGP signature of the author according to http://www.apache.org/info/verification.html.

  7. In your user home folder, construct a command to untar the downloaded file, then rename the versioned folder name to ~/jmeter

    tar xvfz "${DOWNLOADED_TGZ_FILEPATH}"
    mv "${JMETER_VERSION_SPEC}.tgz"  ~/jmeter
    cd ~/jmeter
    ls
    

    You should see a list of folders and files:

    LICENSE        README.md      docs           lib            printable_docs
    NOTICE         bin            extras         licenses
    

    PROTIP: Putting the folder in your home folder would avoid issues with permissions.

  8. Construct a command to remove the file to save disk space:

    rm -rf "${DOWNLOADED_TGZ_FILEPATH}"
    rm checksum
    
  9. Manually add the jmeter folder in your system path within file ~/.bash_profile among other Java specs:

    export PATH="$HOME/jmeter:$PATH"

    Verify JMeter

  10. Verify the install in a Terminal:

    jmeter

    You should see a JMeter GUI pop up:

    jmeter-gui-upon-install

  11. To stop the GUI, press command+Q or cursor to the top of the screen to click JMeter, then Quit.

Images from DockerHub.com

Videos about this topic:

  • https://www.youtube.com/watch?v=sl2mfyjnkXk
  • https://docs.docker.com/docker-cloud/builds/automated-build/

A Docker image would contain JMeter and be ready to run, after having Docker build it based on a Dockerfile.

There are many JMeter images on public DockerHub at https://cloud.docker.com.

WARNING: Don’t use the most popular because, as of this writing, it runs the older Jmeter 2.13 + Debian OS + Java Server JRE 8 at:

docker pull cirit/jmeter
   

Another image containing a JMeter server include:

docker pull justb4/jmeter
   

The Docker image used in the flood.io SaaS service is:

docker pull floodio/jmeter
   

If none of the above is appropriate for you, build your own in the next section.

Build by Dockerfile

PROTIP: Although it takes more time, this approach is often necessary to incorporate new security patches in all levels of the tech stack, from the operating system up. Building an image Dockerfile means that you have the very latest versions of all components.

Installing within a Docker container means you are not “cluttering up” you native operating system. In case a particular combination does not work, you can change it without jepordizing your laptop being in a working state.

Rather than repeating the instructions here, for AWS and Blue Ocean clouds, see https://gist.github.com/hhcordero/abd1dcaf6654cfe51d0b

The script below can be invoked to setup either a Docker image or your local laptop.

JMeter projects folder

  1. If you haven’t already, create a “projects” folder.

  2. Create within your projects folder, create a folder for each JMeter application project.

    git init

    Folder Description
    ./run_jmeter.sh bash shell script file to run jmeter
    ./lib supporting libraries that would usually go in {jmeter_home}/lib
    ./lib/ext external plugins that would usually go in {jmeter}/lib/ext
    ./properties jmeter property files (if used)
    ./scripts here's where you store your jmeter scripts (.jmx files)
    ./scripts/data payloads you might need
    ./scripts/lib custom helper scripts
    ./scenarios scenarios you create
    ./logs test logs created during runs
    ./jmeter symbolic link to the jmeter installation you want to use
    ./java symbolic link to the java installation you want to use

JMeter script recording

See https://www.youtube.com/watch?v=m4bxF756ZGw

Sample JMeter Bash script

#!/usr/bin/env bash
# From https://performance-engineering-solutions.com/2018/05/14/jmeter-basic-installation/
 
## Get the directory where this script is located
directory="$( cd "$( dirname $0)" && pwd )"
 
## Build the ${plugin} variable:
for files in `find ${directory}/lib/ext -maxdepth 1 -type f`; do
plugins="${plugins};${files}"
done
 
## Build libraries variable:
for files in `find ${directory}/lib -maxdepth 1 -type f`; do
libraries="${libraries}:${files}"
done
## Remove the first ; or :
plugins=`echo ${plugins} | sed -e 's/^;//'`
libraries=`echo ${libraries} | sed -e 's/^://'`
 
## Build jmeter options for plugins and libraries:
search_paths=`echo "-Jsearch_paths=${plugins}"`
class_path=`echo "-Juser.classpath=${libraries}"`
 
## Set JAVA location by adding it to the $PATH variable:
JAVA_HOME="${directory}/java"
export PATH="${JAVA_HOME}/bin:${PATH}"
## JVM_ARGS & JMETER_OPTS etc can be placed here. Just make sure that you
## add them to the command at the end
 
## Start jmeter
## The "$@" passes any arguments from the command line to the jmeter.sh script:
${directory}/jmeter/bin/jmeter.sh ${search_paths} ${class_path} \
-j ${directory}/logs/jmeter.log ${any_other_variables} "$@"

Videos on YouTube

Raghav Pal

Raghav Pal (since Jan 2, 2016) has an excellent JMeter Beginner Tutorial in his Automation Step by Step.com channel (supported by ads) in one

3.3 hour video

His previous:

  1. How to install Jmeter [6:54] Jun 30, 2016
  2. How to create first Jmeter test [16:21] Jul 1, 2016
  3. How to use assertions [18:25] Jul 6, 2016
  4. How to use Listeners [18:53] Jul 8, 2016
  5. How to record a UI (Web) test [13:28] Jul 9, 2016
  6. How to create a Database Test Plan [10:13] Jul 9, 2016
  7. How to run jmeter from Command Line (non GUI mode) [11:32] Jul 10, 2016
  8. How to test FTP upload and download [12:56] Jul 24, 2016
  9. Testing Web Services API [20:32] Jul 31, 2016
  10. How to create assertions for JDBC (Database) Test Plan [9:45] Aug 2, 2016
  11. How to create HTML Dashboard Reports from command line [20:09] Aug 4, 2016
  12. How to use Plugins Manager [7:23] Aug 6, 2016
  13. How to read data from csv file (Parameterisation) [14:47] Aug 11, 2016
  14. Functions and Variables [13:57] Aug 13, 2016
  15. How to setup realistic performance test-PACING [11:02] Aug 28, 2016
  16. TIMERS (How to add Think Time) [11:13] Aug 29, 2016
  17. How to parameterize FTP test [8:23] Sep 4, 2016
  18. How to run Scheduled + Sequential execution [13:48] Sep 14, 2016
  19. Correlation (with Regular Expression Extractor) [12:30] Jan 15, 2017
  20. How to use TEMPLATES [7:13] Apr 11, 2017
  21. How to use Test Script Recorder [9:23] Apr 12, 2017
  22. How to test File Upload [] Apr 14, 2017
  23. How to test File Download [6:25] Apr 14, 2017
  24. How to DEBUG [8:56] Apr 16, 2017
  25. How to record login test [8:14] Sep 11, 2017

Will Button

Perform Load Tests on an API Server using Apache JMeter in [8:25] tests a VIDEO: Sample Todo API on Node.js built with Swagger in GitHub repo.

Guru99

https://www.guru99.com/jmeter-tutorials.html


Social

Sign up for Blazemeter’s Slack channel JMeter

  • &#_questions_answers - A place to ask and answer JMeter questions
  • &#blog_posts - Share your JMeter blog posts here
  • &#plugins - Get and share info about JMeter’s plugins to customize your testing scripts
  • &#community_projects - A place to meet, plan and work together on JMeter load testing projects
  • &#meetups - Learn and share when there are JMeter meetups in your area.