Performance Testing with JMeter

Performance Testing with JMeter: A Working Guide

0 Comments

JMeter is the tool most teams reach for first, and the one most often used badly. This is the path from a recorded script to a result you can defend.

In this article

  • The pieces, in the order you meet them
  • Recording a script, then fixing it
  • Correlation with a JSON Extractor
  • Parameterisation with a CSV Data Set
  • Think time and the workload model
  • Running it properly, and reading the output

The pieces, in the order you meet them

  • Test Plan – the container. Everything lives under it.
  • Thread Group – your virtual users: how many, how fast they arrive, how long they stay.
  • Samplers – the requests. HTTP Request is the one you will use most.
  • Logic Controllers – loops, if-conditions, transaction grouping.
  • Config Elements – CSV Data Set, HTTP Header Manager, Cookie Manager, defaults.
  • Pre/Post Processors – where correlation happens, usually a JSON or Regex Extractor.
  • Assertions – the part people skip, and the reason their results are wrong.
  • Listeners – results. Use them in the GUI only; remove them before a real run.

Never run a load test from the JMeter GUI. The GUI is for building; run from the command line, or the tool becomes your bottleneck.

Recording a script, then fixing it

Record with the HTTP(S) Test Script Recorder and a browser pointed at JMeter's proxy. What you get back is not a test – it is a transcript. Three jobs turn it into one:

  • Delete the noise: images, fonts, analytics, favicons. They inflate the load and teach you nothing.
  • Correlate the dynamic values. Anything the server generated has to be extracted and re-used rather than replayed.
  • Parameterise the data, so fifty users are fifty people.

Correlation with a JSON Extractor

Say the login response returns a token your later requests need:

// Post Processor: JSON Extractor on the login sampler
Names of created variables : authToken
JSON Path expressions      : $.data.token
Default Values             : NOT_FOUND

// then in the HTTP Header Manager of every later request
Authorization: Bearer ${authToken}

Set the default to something obviously wrong like NOT_FOUND, then add a Response Assertion that fails on it. A silent extraction failure is the commonest reason a run reports brilliant response times that mean nothing.

Parameterisation with a CSV Data Set

Filename            : users.csv
Variable Names      : username,password
Delimiter           : ,
Recycle on EOF      : False      <- stop rather than silently repeat the same user
Stop thread on EOF  : True
Sharing mode        : All threads

Think time and the workload model

Add a Uniform Random Timer or a Gaussian Random Timer inside the thread group so each user pauses the way a person does. Then write the model down in the test plan: journeys, their mix as a percentage, ramp-up, steady state and ramp-down. A result with no model beside it cannot be reproduced or argued with.

Running it properly, and reading the output

jmeter -n -t checkout.jmx -l results.jtl -e -o report/ 
       -Jusers=200 -Jrampup=120 -Jduration=1800

# -n  no GUI
# -l  raw results
# -e -o  generate the HTML dashboard into report/
  • Open the dashboard and read the APDEX table and the error percentage before anything else.
  • In Response Times Over Time, look for a line that climbs while throughput is flat – that is saturation.
  • Check the load generator's own CPU. Above roughly 70% you are measuring JMeter.

Key points

  • Build in the GUI, run with -n from the command line.
  • An extraction that fails silently produces beautiful, meaningless numbers – assert on it.
  • Delete static resources from a recorded script before you do anything else.
  • Publish the workload model with the result, or the result cannot be defended.

Practise this on the free applications at jstestingacademy.co.in/qa-apps – no account needed.