Load up a free Java-based tool to impose load on web sites, whether it needs it or not
- Install Java
- Install JMeter
- Start JMeter Batch run
- Shutdown and Abort run
- Install Sample Apps under Test
- Integrate JMeter with Apache Ant
- Prepare sample test.jmx
- 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
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.
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 practically don’t need a local machine if you use the cloud service
A Docker image contains bits.
There are many on DockerHub. But the most popular is:
https://hub.docker.com/r/cirit/jmeter, which runs Jmeter 2.13 + Debian OS + Java Server JRE 8
On a Mac:
brew update brew install jmeter --with-plugins
PROTIP: JMeter won’t appear in your Mac’s Applications folder.
To open it:
CAUTION: Package managers put bits into a different folder than installation by download.
Open ~/.bash_profile to add:
# Following https://wilsonmar/github.io/jmeter-install :: export JMETER_HOME=/usr/local/Cellar/jmeter/3.1/libexec # if installed using Homebrew
WARNING: Package managers may install older versions than what is available for direct download.
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.2 ~/jmeter cd jmeter
Edit subl ~/.bash_profile
Add the path, with a colon:
# Following https://wilsonmar/github.io/jmeter-install :: export JMETER_HOME=$HOME/jmeter
Close existing terminals or refresh on each window:
Close existing terminals or refresh on each window:
Edit properties file:
cd bin edit jmeter.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.
List folders and top-level files:
- 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, 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.
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>
Start JMeter Batch run
Substituting script with your script name:
jmeter -n -t .../Test.jmx -l .../test.jtl -e -o [Path to output folder]
-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 <pre>–propfile</pre> to 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 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.
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
Prepare sample test.jmx
JMeter tests are defined in an XML-format file.
View JMeter example files that comes with the installer in
This path is shown as “…” below.
Remove graphic data writers for batch.
Set Up at Least One Thread Group and Sampler
Unlike LoadRunner, a JMeter thread group contains both the automated script (URLs, etc.) and the load scenario.
In thread groups is defined the number of users to simulate. Each user is emulated by each 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.
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 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: