Skip to the page

Mobile, performance and coding · mid

Load testing with k6 and JMeter

A load test needs a goal, thresholds and real user behaviour. Read results by errors and percentiles, not by the average.

The notes

What you must know

  • k6 test shape: options with stages (ramp up, hold, ramp down) and thresholds such as http_req_failed: ["rate<0.01"] and http_req_duration: ["p(95)<800"].
  • Without thresholds a run always passes.
  • Use a SharedArray of test users and pick one by virtual user number, so each has its own account. Log in once per virtual user, not on every iteration. Add think time and tags on requests.
  • The init stage cannot make HTTP requests. setup() runs once for the whole test, which suits one shared token but not 300 logins.
  • Read a result: errors at 4% break a 1% target even if p95 is good. The average hides the tail; use p95 and p99. A fixed 30 s maximum looks like a timeout from a server or gateway.
  • Break errors down by status code and endpoint, and compare with server logs and monitoring for the same minutes.
  • JMeter recording replays values that were valid only in that session: CSRF tokens, session ids, JWTs. Correlation means extracting the value from a response (JSON Extractor, Regular Expression Extractor) and reusing it as ${var}.
  • JMeter also needs a Cookie Manager, a Header Manager for Authorization, and a CSV Data Set Config for users. Debug with one thread and View Results Tree, and run the real test from the command line, not the GUI.

The red pen

Common traps: mistake → fix

  • Mistake: p95 is under 500 ms so ship it

    Fix: check the error rate and the cause of errors.

  • Mistake: One shared user for 300 virtual users

    Fix: the server sees one account and may lock it.

  • Mistake: Run 100 threads in the JMeter GUI

    Fix: the GUI is for debugging; use the command line.

  • Mistake: A recorded JMeter script works as recorded

    Fix: dynamic values must be correlated.

Easy to hard

Questions interviewers ask, easy to hard

  1. Here is a k6 result with 4% errors and p95 of 471 ms. Is the system ready?
  2. Write the options of a k6 test for 300 users with thresholds.
  3. A recorded JMeter script fails for every user after login. Why?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview