QA Interview Hub · Knowledge base · Quizzes · Українська

Performance Testing

Tools and analysis

JMeter, k6 and finding the bottleneck

JMeter and k6 differ in how a test is written, not in accuracy: JMeter is a GUI with a .jmx plan, k6 is JavaScript code. A Thread Group and k6 constant-vus give a closed model, while the Open Model Thread Group and k6 arrival-rate executors give an open one. A CI test needs a failure criterion (k6 thresholds), and the bottleneck is found from resource metrics after ruling out the generator.

Performance · Tools

One test in JMeter, another in k6, and the numbers differ. How do the tools really differ?

A team inherited a JMeter test plan, while the new tests are written in k6. On the same scenario the numbers differ, and someone suggests "picking the right tool". The difference is usually not which tool is more accurate but the load model, the pauses, how the test is launched and what exactly a metric measures. This lesson covers how to choose a tool, how to run a test in CI and how to find the bottleneck once a test has shown a problem.

How it works and why. All four common tools do the same thing: create load with virtual users and collect metrics. They differ in how a test is described and in which load models they support. The descriptions below follow their documentation.

ToolHow a test is describedLoadThresholds, report
Apache JMeter 5.xGUI, plan in .jmx (XML), runs on JavaThread Group (threads, ramp-up), an Open Model Thread Group existsAssertions, HTML report from .jtl
Grafana k6JavaScript, launched with k6 runExecutors: constant-vus, ramping-vus (closed), constant-arrival-rate, ramping-arrival-rate (open)thresholds, exit code 99 when crossed
GatlingCode through a DSL (Java, Scala, Kotlin, JavaScript/TypeScript)injectOpen (constantUsersPerSec) and injectClosed (constantConcurrentUsers)Assertions, HTML report
LocustPython, user classes with @taskUsers with wait_time (in essence closed), a shape can be set with LoadTestShapeA web UI, a mode without it (--headless)

The choice is dictated by context, not by "which is better": who writes and maintains the tests (a JS team takes k6, a Python team Locust, a Java/Scala team Gatling), whether the test should be code in a repository and CI, whether the open model is needed, whether ready plans already exist. For JMeter a typical risk is that the GUI is handy for building and debugging, but a large test is run without it, and .jmx plans are hard to review as code.

Running and thresholds. A test in CI needs a criterion that breaks the build: in k6 that is thresholds, and a violation gives a non-zero exit code and a failed step. JMeter is run without the GUI (-n), results go to a file (-l), the report is generated from it (-e -o), and parameters are passed with -J and the __P function.

# JMeter without the GUI, report into the report/ directory
jmeter -n -t plan.jmx -l results.jtl -e -o report/
# parameters from the command line: -Jthreads=100
# in the plan: ${__P(threads,10)}

# k6: exit code 99 if a threshold is crossed
k6 run -e BASE_URL=https://staging.example.com script.js

Running JMeter

Typical

From a laptop, in the GUI, with listeners

The generator and the GUI eat CPU, results are rendered on the fly. The numbers reflect the state of the laptop, not of the system.

Better

Without the GUI on a separate generator

The -n mode writing to a file with a report after the test. The generator does not compete with the measurement for resources.

Figure 1. A test is run from somewhere other than where it was written. The load generator must not become the bottleneck.

Finding the bottleneck. A test showed that responses are slow but not where exactly. Look at the resource metrics next to response time, and first rule out the simplest thing: whether the bottleneck is truly in the system and not in the generator.

Where to look for the bottleneck

1. Load generatorCPU, network, whether it keeps the plan2. ApplicationCPU, memory, GC, threads, pools3. Database and dependenciesslow queries, locks, connections
Figure 2. Go top to bottom. First make sure the generator is not at its limit, then look at the application, then at the database and dependencies.
SymptomLikely causeWhat to check
Time grows, application CPU is low, database CPU is highSlow queries, missing indexesSlow query log, execution plans (EXPLAIN)
Time grows, CPU is low everywhere, connection wait errors appearExhausted connection or thread poolPool size, active count and the wait queue
Application CPU or memory at the limitCode, GC pauses, a lack of resourcesProfiling, GC metrics, container limits
Time grows in periodic jumpsGC pauses, locks, background jobsCorrelate time peaks with events in logs and metrics
Slow only on some operationsAn external service or a heavy queryTime breakdown per operation, tracing

Example: the fixed test from the previous lesson. A k6 scenario with an open model and thresholds that can run in CI (the function with the request is shortened):

import http from 'k6/http';

export const options = {
  scenarios: {
    checkout: {
      executor: 'constant-arrival-rate',
      rate: 150, timeUnit: '1s', duration: '10m',
      preAllocatedVUs: 200, maxVUs: 2000,
    },
  },
  thresholds: {
    http_req_failed: ['rate<0.01'],
    http_req_duration: ['p(95)<500', 'p(99)<1500'],
  },
};

export default function () {
  http.post(__ENV.BASE_URL + '/api/checkout', JSON.stringify({}));
}

If a threshold is crossed, the build fails. The next steps: check the generator (its CPU and network), then the system metrics for the same interval, and compare against the list above. After the fix the test is run again on the same version of data and configuration, so that the comparison is fair.

Limits and alternatives. JMeter has an Open Model Thread Group for open load, but an ordinary Thread Group is a closed model. Running in the cloud (Grafana Cloud k6, BlazeMeter and others) removes the generator capacity question but adds cost and network setup to the test environment. Server-side metrics (APM, Prometheus, Grafana) are needed by every tool: without them you see only the symptom, not the cause. Separate from load testing are front-end performance checks (Lighthouse, Web Vitals): they measure a different part of the experience.

Typical mistakes.

  • Running a large JMeter test through the GUI with a "View Results Tree" listener.
  • Comparing numbers from different tools without checking the model, think time and what a metric measures.
  • A test with no thresholds in CI: it "passed" because nothing checks the result.
  • A bottleneck conclusion from response time without system resource metrics.
  • Looking for the cause in the system when the generator itself is at its limit.
  • Repeating the test on a different data version or configuration and concluding "it got better".

Check yourself

How do you make CI fail in k6 when p95 exceeds 500 ms?

Answer

Declare a threshold in options: thresholds: { http_req_duration: ['p(95)<500'] }. If it is crossed, k6 exits with a non-zero code (99), and the CI step fails.

Response time grows, application CPU is low, and database CPU is high. Where do you look?

Answer

At the database queries: slow queries, missing indexes, execution plans (EXPLAIN), locks. A low application load while time grows suggests it is waiting for the database.

How do a JMeter Thread Group and k6 constant-arrival-rate differ in load model?

Answer

An ordinary Thread Group is a fixed number of threads that wait for responses (closed). constant-arrival-rate sets the rate of iteration starts regardless of responses (open), and VUs are drawn to match it within maxVUs.

In an interview. Junior: JMeter is a Java tool with a GUI, built around Thread Group, samplers, assertions and listeners, and a large test is run without the GUI. k6 writes tests in JavaScript, and thresholds let you break the build in CI. Middle/Senior: I choose the tool by the team, CI and open-model support: in k6 those are the arrival-rate executors, in Gatling injectOpen. I look for the bottleneck top to bottom: first the generator, then application and database metrics next to response time, and only then conclude about the cause.