Load up a free Java-based tool to impose load on web sites, whether it needs it or not
- Install Java Dependency
- Install JMeter
- JMeter folders
- Sample test.jmx
- JMeter commands
- Servers in user.properties
- Install Sample Apps under Test
- Integrate JMeter with Apache Ant
- Report review
- Record Custom Script
- Look into this
This tutorial explains how to install JMeter … for fun and profit.
Sign up for the mailing list at: http://jmeter.apache.org/mail.html
Install Java Dependency
JMeter is written in Java for cross-platform sweetness.
Change the Java Heap appropriate to your machine:
Verify whether the JAVA_HOME environment points to the JRE or JDK installation folder:
The response on my Mac:
Verify whether the JAVA_HOME/bin folder has been properly added to the PATH environment variable.
The response should be similar to the above:
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 use the cloud service Blazemeter or Flood.io
B) Pull an image from Docker Hub within a Google Compute or AWS cloud instance.
C) Use the Dockerfile to build your own Docker image containing JMeter.
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.
You don’t need a local machine if you use the cloud service
The SaaS vendor was purchased by CA in 2017.
Users of Blazemeter can use their add-on test framework.
Blogs about this:
Images from DockerHub.com
A Docker image is ready to run, after having Docker build it based on a Dockerfile.
There are many JMeter images on DockerHub.
The most popular:
docker pull cirit/jmeter
It runs Jmeter 2.13 + Debian OS + Java Server JRE 8 on https://cloud.docker.com/
Another image containing a JMeter server include:
docker pull justb4/jmeter
The image used in the flood.io SaaS service is:
docker pull floodio/jmeter
Use Homebrew package manager on Mac
Create a folder container.
brew update brew install jmeter --with-plugins
It downloads from:
🍺 /usr/local/Cellar/jmeter/3.3: 2,924 files, 131.4MB, built in 1 minute 14 seconds
Alternately, if it’s already installed:
brew upgrade jmeter
PROTIP: As with other package managers, Brew does not save JMeter in your Mac’s Applications folder.
Download installer from developers
Even if you’re not intending to download, go here to see the dates of each version.
Download binary installer from:
In Finder, double-click the file to unzip to folder:
Move the folder to a folder with a path containing no spaces, such as:
PROTIP: Putting the folder in your home folder would avoid issues with permissions.
cd ~/Downloads mv apache-jmeter-3.3 ~/jmeter cd jmeter
In a Text Editor, edit file ~/.bash_profile
Insert these lines to make JMeter within the Path sought for executables:
# Following https://wilsonmar/github.io/jmeter-install :: export PATH="/usr/local/Cellar/jmeter/3.3/libexec/bin:$PATH" export JMETER_HOME=/usr/local/Cellar/jmeter/3.3/libexec # if installed using Homebrew
WARNING: Package managers may install older versions than what is available for direct download.
Close existing terminals or refresh on each window:
cd $JMETER_HOME pwd
List folders and top-level files:
tree -L 1
- bin contains executables, jar, and properties files
- extras contains miscellaneous files including samples using the Apache Ant tool
- lib contains library utlity jar files
- lib/ext contains JMeter components and add-ons
- licenses contains legal text
- printable_docs contains the usermanual in html and a demos folder containing jmx files
Invoke Blank JMeter GUI
On a Mac:
Go to $JMETER_HOME/bin and run:
chmod 555 jmeter.sh ./jmeter.sh
Alternately, invoke the JMeter GUI program using the link:
Alternately, if you are using Windows:
In response, a DOS window should appear with
[version] is the jre version installed on the system.
If it does not happen, either the environment settings are incorrect, or there are several JREs installed on the system.
Either way, the response:
================================================================================ Don't use GUI mode for load testing, only for Test creation and Test debugging ! For load testing, use NON GUI Mode: jmeter -n -t [jmx file] -l [results file] -e -o [Path to output folder] & adapt Java Heap to your test requirements: Modify HEAP="-Xms512m -Xmx512m" in the JMeter batch file ================================================================================
The default JMeter GUI:
PROTIP: Press command+Q to Quit out of the JMeter GUI.
Open another Terminal and be at:
View JMeter example files that comes with the installer:
The response is:
PROTIP: JMeter test scripts are defined within XML-formatted files.
Remove graphic data writers for batch.
Set Up at Least One Thread Group:
PROTIP: A JMeter thread group contains both the automated script (URLs, etc.) and the load scenario. This is unlike LoadRunner, which has scripts in files folders separate from the Scenario (.lrs) file.
In thread groups is defined the number of users to simulate. Each user is emulated by a separate thread.
The ramp-up period tells JMeter how long it should take to reach the desired number of threads chosen.
Set the number of iterations to process each user in the group with the Loop Count.
Click on the thread group to see the load configurations. Expand a thread group to see the steps of the load script.
Set up Samplers:
Samplers emulate the actual work done within clients. When JMeter executes samplers, it writes down the results such as: start time, duration, success, response messages, etc.
Listeners are used to view results. The most commonly used sampler is the HTTP Request, which sends a HTTP or HTTPS request to a web server.
Set the duration of the delay from one request to the next. The specification is how many seconds JMeter waits before navigating from the homepage to the features page.
Add Configuration Elements:
This manages elements like the cache and the cookies, during test runs.
Adding the “HTTP Cache Manager” and the “HTTP Cookie Manager” simulates the browser’s behavior.
These define pass or fail criteria for the test.
Let’s say you want to make sure your site or app responds within 100 milliseconds.
You can set a Duration Assertion to specify that if any response lasts longer than 100 milliseconds, the sample will be marked as “failed.”
The most important assertion to know is the Response Assertion. This covers 99% of your needs - so no wonder it’s so popular! You can use it to test the URL, response body, messages, embedded resources, redirects, headers and more. This assertion gives you loads of flexibility as it lets you test regular expressions rather than text patterns. JMeter handles regular expressions in a very similar way to Perl - except you don’t enclose the expression in //’s.
Listeners display the results of a sampler.
Listeners can be viewed in various formats (table, graph, tree, or log file).
Listeners can be added anywhere in the test - but only collect data (listens) to elements on the same level or below.
The most commonly used listener is “View Results Tree”, which presents in the GUI all test plan results in a user-friendly tree structure.
Other listeners include Assertion Results, Aggregate Report and Beanshell Listener.
WARNING: Disable all your listeners as they use up a lot of memory.
Add a Thread Group component by right-clicking on the name of a test plan to select ‘Add’, then choose the component to set up and configure.
To view information:
Writing log file to: /Users/mac/jmeter.log
To view all possible command line options:
The response has the version at the right edge (3.1 at time of writing):
Writing log file to: /Users/mac/jmeter.log _ ____ _ ____ _ _ _____ _ __ __ _____ _____ _____ ____ / \ | _ \ / \ / ___| | | | ____| | | \/ | ____|_ _| ____| _ \ / _ \ | |_) / _ \| | | |_| | _| _ | | |\/| | _| | | | _| | |_) | / ___ \| __/ ___ \ |___| _ | |___ | |_| | | | | |___ | | | |___| _ < /_/ \_\_| /_/ \_\____|_| |_|_____| \___/|_| |_|_____| |_| |_____|_| \_\ 3.1 r1770033 Copyright (c) 1999-2016 The Apache Software Foundation --? print command line options and exit -h, --help print usage information and exit -v, --version print the version information and exit -p, --propfile <argument> the jmeter property file to use -q, --addprop <argument> additional JMeter property file(s) -t, --testfile <argument> the jmeter test(.jmx) file to run -l, --logfile <argument> the file to log samples to -j, --jmeterlogfile <argument> jmeter run log file (jmeter.log) -n, --nongui run JMeter in nongui mode -s, --server run the JMeter server -H, --proxyHost <argument> Set a proxy server for JMeter to use -P, --proxyPort <argument> Set proxy server port for JMeter to use -N, --nonProxyHosts <argument> Set nonproxy host list (e.g. *.apache.org|localhost) -u, --username <argument> Set username for proxy server that JMeter is to use -a, --password <argument> Set password for proxy server that JMeter is to use -J, --jmeterproperty <argument>=
Define additional JMeter properties -G, --globalproperty <argument>=<value> Define Global properties (sent to servers) e.g. -Gport=123 or -Gglobal.properties -D, --systemproperty <argument>=<value> Define additional system properties -S, --systemPropertyFile <argument> additional system property file(s) -L, --loglevel <argument>=<value> [category=]level e.g. jorphan=INFO or jmeter.util=DEBUG -r, --runremote Start remote servers (as defined in remote_hosts) -R, --remotestart <argument> Start these remote servers (overrides remote_hosts) -d, --homedir <argument> the jmeter home directory to use -X, --remoteexit Exit the remote servers at end of test (non-GUI) -g, --reportonly <argument> generate report dashboard only, from a test results file -e, --reportatendofloadtests generate report dashboard after load test -o, --reportoutputfolder <argument> output folder for report dashboard </pre> ## Run JMeter in Batch The format of command line:
jmeter -n -t .../Test.jmx -l .../test.jtl -e -o [Path to output folder]where: -n tells JMeter to run in non-GUI mode -t the path to source .jmx script to run the script that comes with the JMeter installation. -l test .jtl -j the name of JMeter run log file. -p or
--propfileto preced a JMeter property file to use -q or --addprop to precede JMeter property file(s) Aditionally, JMeter has several other parameters that can be used for running in non-GUI mode. -R lists remote servers to run. -H proxy server hostname or ip address. -P proxy server port. ### Shutdown and Abort run Running JMeter in non-GUI (batch) mode means there is no Menu which listens to keystrokes such as Control + '.'. However, JMeter in non-GUI mode listens for commands on port 4445 (set at default in the JMeter property jmeterengine.nongui.port). If that port is being used (i.e. by another JMeter instance), JMeter tries the next higher port, continuing until it reaches the port defined in JMeter property jmeterengine.nongui.maxport, which defaults to 4455 (10 more than the default). Since the JVM calls class files from ApacheJMeter.jar, the CLASSPATH variable needs to be in the PATH along with ApacheJmeter.jar, because inside these files is this string:
java -cp %~dp0ApacheJMeter.jar org.apache.jmeter.util.ShutdownClient StopTestNow %*
Gracefully shutdown using these scripts the installer puts in the JMeter /bin directory.
Alternately, shutdown immediately:
The commands will only be accepted if the script is run from the same host.
Servers in user.properties
Specify the various slave servers the master JMeter server uses.
Use your favorite text editor instead of vi to edit properties file:
cd $JMETER_HOME/bin vi user.properties
Specify slave computers IP addresses, separated by commas. Example:
All on the same subnet?
CAUTION: All instances of JMeter should have the same version.
Slave is the system running jmeter-server, which takes commands from the GUI and send requests to
Target servers, the web server under test
Master is the JMeter system running Jmeter GUI controlling the server which controls slaves.
There are many plug-ins various people have developed for JMeter:
Plugins Standard, Extras, ExtrasLibs, WebDriver, Hadoop, etc.
Install Sample Apps under Test
PROTIP: Learn to use JMeter targeting a sample app so you can follow tutorials step by step, to equip you for troubleshooting the unknown.
These are the bare mininum JARs required by JMeter 2.9+ and the HTTPSampler used.
Other samplers have different library JAR dependencies:
Integrate JMeter with Apache Ant
- Install the JMeter Ant Task
JMeter makes use of the keytool utility (available in JRE/JDK) so you need to ensure your configuration is correct, read this wiki page before starting.
The Ant task creates a report like this:
Record Custom Script
Install the JMeter Chrome Extension which filters only the URL’s to be load tested.
See How to Cut Your JMeter Scripting Time by 80% using Blazemeter’s “Smart JMX” to generate script files from proxy recordings.
The recording has Automatic Extractors that does auto-parameterization (also known as “auto-correlation” of values with variables it creates).
JMeter ThreadGroup and Samplers.
In a Continuous Integration environment, we would incorporate JMeter runs within a Jenkinsfile.
Blogs about this topic:
In addition to scanning code, SonarQube maintains a history of test runs. http://www.sonarplugins.com/jmeter
Look into this
Generate JMeter Code from Swagger
What others have written: