Apache Jmeter - RamonPradoMoreno/learned-at-work GitHub Wiki

Apache Jmeter

The Apache JMeterโ„ข application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

Install

  1. First of all, we need to get the release:

    wget http://apache.mirrors.spacedump.net//jmeter/binaries/apache-jmeter-5.2.tgz
    
  2. Then we need to extract it:

    sudo tar -xzf apache-jmeter-5.2.tgz -C ~/tools/jmeter
    
  3. create the symlink to the jmeter -binary:

    sudo ln -s ~/tools/jmeter/apache-jmeter-5.2/bin/jmeter /usr/local/bin/jmeter
    
  4. create a desktop shortcut:

    nano ~/.local/share/applications/jmeter.desktop
    
  5. Paste the following text:

    [Desktop Entry]
    Type=Application
    Encoding=UTF-8
    Name=JMeter
    Comment=JMeter
    Exec=/usr/local/bin/jmeter
    Icon=~/tools/jmete/rapache-jmeter-5.2/docs/images/jmeter_square.png
    Terminal=false
    

Configuration

We will use the Html Report tool of Jmeter. This makes generating a report completely automatic. Before changing the configuration make sure that you are the owner of all the jmeter directories. If root is the owner we might not be able to generate the reports:

  1. Go to the new folder:

    cd ~/tools/jmeter/apache-jmeter-5.2
    
  2. Check ownership:

    ls -als
    
  3. if root is the owner, go to ~/tools/jmeter/ and:

    sudo chown -R $USER apache-jmeter-5.2
    

We are going to check some config in: ~/tools/apache-jmeter/apache-jmeter-5.2/bin/

We need to edit the user.properties based on what is in reportgenerator.properties. Everything is explained in the official documentation but it is extremely detailed. In order to "just make it work" we will follow this section:

  1. Copy this text:

    # Configure this property to change the report title
    #jmeter.reportgenerator.report_title=Apache JMeter Dashboard
    
    # Change this parameter if you want to change the granularity of over time graphs.
    # Granularity must be higher than 1000 (1second) otherwise Throughput graphs will be incorrect
    # see Bug 60149
    #jmeter.reportgenerator.overall_granularity=60000
    
    #Change this parameter if you want to change the granularity of Response time distribution
    # Set to 100 ms by default
    #jmeter.reportgenerator.graph.responseTimeDistribution.property.set_granularity=100
    
    # Change this parameter if you want to override the APDEX satisfaction threshold.
    jmeter.reportgenerator.apdex_satisfied_threshold=1500
    
    # Change this parameter if you want to override the APDEX tolerance threshold.
    jmeter.reportgenerator.apdex_tolerated_threshold=3000
    
    # Sets the destination directory for generated html pages, it is better to change it for every generation
    # This will override the value set through -o command line option
    # jmeter.reportgenerator.exporter.html.property.output_dir=/tmp/test-report
    
    # Indicates which graph series are filtered (regular expression)
    # In the below example we filter on Search and Order samples
    # Note that the end of the pattern should always include (-success|-failure)?$
    # Transactions per second suffixes Transactions with "-success" or "-failure" depending 
    # on the result
    #jmeter.reportgenerator.exporter.html.series_filter=^(Search|Order)(-success|-failure)?$
    
    # Indicates whether series filter apply only on sample series
    jmeter.reportgenerator.exporter.html.filters_only_sample_series=true
    
  2. Edit the user.properties file:

    nano ~/tools/apache-jmeter/apache-jmeter-5.2/bin/user.properties
    
  3. Paste text at the end.

Basic Use

Jmeter has two modes:

  1. UI: This mode is supposed to be used to create the test plan. A file that describes how the test is going to be performed and the data to be measured and stored.
  2. Terminal: This mode is for the actual testing. You should not trow a real test from the UI because it may interfere in the results.

Creating a basic test plan

  1. Open JMeter's UIโ†’ Thanks to the desktop file we created we can just press super and type jmeter and the system will find it.
  2. Customize the testplan that pops up and right click on it, then choose: Add โ†’ Threads(Users) โ†’ Thread Group. A thread group is like a group of users that will perform requests to the tested service.
  3. Setting Loop Count to infinite and Duration to any number of seconds will make the test run for that amount of seconds. The Startup delay (seconds) option is the time between a thread start and the next one.
  4. We still need to tell this "users" what request to send. In order to do so right click the Thread Group and Add โ†’ Sampler โ†’ HTTP Request. In that element we can specify where to send the requests.
  5. The last thing we will need is an Summary Report. This report will save in a .csv all the data that the HTML report extension will use to generate the full report we want. Go to: Add โ†’ Listener โ†’ Summary Report. In the summary report you need to specify a path to save the .csv. Ignore any "does not exist error".
  6. There are tons of other things that could be added such as HTTP status code assertions. We will create a separate section for more complete test plans.

Execute the test

Go to a terminal and execute:

# jmeter -n -t <test JMX file> -l <test log file> -e -o <Path to output folder>
jmeter -n -t HelloEndpointTest.jmx -l log.log -e -o report

In the /report directory you will find a index.html file that you can click to see the report.