Wilson Mar bio photo

Wilson Mar

Hello. Hire me!

Email me Calendar Skype call 310 320-7878

LinkedIn Twitter Gitter Google+ Youtube

Github Stackoverflow Pinterest

Load up a free Java-based tool to impose load on web sites, whether it needs it or not


Overview

This tutorial explains how to install JMeter … for fun and profit.

https://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.pdf

  • Sign up for the mailing list at: http://jmeter.apache.org/mail.html

  • https://github.com/apache/jmeter

  • https://twitter.com/ApacheJMeter

  • https://groups.google.com/forum/#!forum/jmeter-plugins

Install Java

JMeter is written in Java for cross-platform sweetness.

http://www.oracle.com/technetwork/java/javase/downloads/index.html

  1. Change the Java Heap appropriate to your machine:

    HEAP="-Xms512m -Xmx2148m"
    • http://java.dzone.com/articles/java-8-permgen-metaspace

    • http://www.infoq.com/news/2013/03/java-8-permgen-metaspace

  2. Verify whether the JAVA_HOME environment points to the JRE or JDK installation folder:

    echo $JAVA_HOME
    

    The response on my Mac:

    /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
    
  3. Verify whether the JAVA_HOME/bin folder has been properly added to the PATH environment variable.

    javac -version
    

    The response should be similar to the above:

    javac 1.8.0_102
    

Install JMeter

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.

Blazemeter

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

Docker container

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

Package managers

On a Mac:

brew update
   brew install jmeter --with-plugins
   

PROTIP: JMeter won’t appear in your Mac’s Applications folder.

  1. To open it:

    open /usr/local/bin/jmeter
    

    CAUTION: Package managers put bits into a different folder than installation by download.

  2. 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.

  1. Download binary installer from:

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

    apache-jmeter-3.2.zip

  2. In Finder, double-click the file to unzip to folder:

    apache-jmeter-3.2

  3. 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
    

    On Mac/Linux:

  4. Edit subl ~/.bash_profile

  5. Add the path, with a colon:

    export PATH="$HOME/jmeter:$PATH"
    
  6. Define $JMETER_HOME

    # Following https://wilsonmar/github.io/jmeter-install ::
    export JMETER_HOME=$HOME/jmeter
    
  7. Close existing terminals or refresh on each window:

    source ~/.bash_profile
    
  8. Verify $JMETER_HOME

    echo $JMETER_HOME
    

Configure

  1. Close existing terminals or refresh on each window:

    source ~/.bash_profile
    
  2. Verify $JMETER_HOME

    echo $JMETER_HOME
    
  3. Edit properties file:

    cd bin
    edit jmeter.properties
    
  4. Specify slave computers IP addresses, separated by commas. Example:

    remote_hosts=192.168.0.10,192.168.0.11,192.168.0.12,192.168.0.13,192.168.0.14
    

    All on the same subnet?

    CAUTION: All instances of JMeter should have the same version.

    DEFINITIONS:

    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.

    JMeter folders

  5. List folders and top-level files:

    ls -al
    

    The folders:

    • bin contains executables, jar, and properties files
    • docs
    • 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:

  1. Go to $JMETER_HOME/bin and run:

    chmod 555 jmeter.sh
    ./jmeter.sh
    

    Alternately, if you are using Windows:

    jmeter.bat
    

    In response, a DOS window should appear with

    jre\[version]\bin\rmiregistry.exe
    

    [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.

    Help

  2. To view information:

    
    jmeter -h
    

    The response:

    Writing log file to: /Users/mac/jmeter.log
    

  3. To view all possible command line options:

    
    jmeter -?
    

    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

  1. Substituting script with your script name:

    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 <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 %*
   
  1. Gracefully shutdown using these scripts the installer puts in the JMeter /bin directory.

    Shutdown.cmd
    

    Alternately, shutdown immediately:

    StopTestNow.cmd
    

    The commands will only be accepted if the script is run from the same host.

Plug-ins

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:

  • ApacheJMeter_core.jar
  • jorphan.jar
  • avalon-framework-4.1.4.jar
  • ApacheJMeter_http.jar
  • commons-logging-1.1.1.jar
  • logkit-2.0.jar
  • oro-2.0.8.jar
  • commons-io-2.2.jar
  • commons-lang3-3.1.jar

Integrate JMeter with Apache Ant

  1. Install the JMeter Ant Task

http://ant.apache.org/

http://www.programmerplanet.org/projects/jmeter-ant-task/

http://ant.apache.org/manual/install.html

http://www.programmerplanet.org/projects/jmeter-ant-task/

Prepare sample test.jmx

JMeter tests are defined in an XML-format file.

  1. View JMeter example files that comes with the installer in

    script/extras/

    This path is shown as “…” below.

  2. Remove graphic data writers for batch.

  3. 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.

  4. 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.

  5. Add Timers

    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.

  6. 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.

    See this.

  7. Add Assertions

    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.

  8. Add Listeners

    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.

  9. 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.

Certificates

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.

Report review

The Ant task creates a report like this:

jmeter ant html blazemeter

Record Custom Script

  1. Install the JMeter Chrome Extension which filters only the URL’s to be load tested.

    http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.html

    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.

this

Resources

What others have written:

  • http://biscminds.blogspot.fr/2011/12/quick-jmeter-setup-on-mac.html

  • http://zacster.blogspot.com/2008/03/quick-howto-to-setup-jmeter.html

Generate JMeter Code from Swagger