Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Performance testing with JMeter

Practical study notes on performance testing using Apache JMeter: definitions, key concepts (Little's Law), JMeter test-plan elements and syntax, formulas, worked examples, common mistakes and exam guidance.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Performance testing checks how software behaves under expected and extreme loads. Engineers use tools such as Apache JMeter to measure response time, throughput, and reliability so that services meet required Service Level Agreements (SLAs) and do not fail in production.

Key ideas

Start from first principles and build the concepts an engineer must know.

  • Performance testing — the systematic activity of exercising a system with a controlled load to measure behaviour (response time, throughput, resource use). Assumption: tests run in a repeatable environment or results will mix environment noise with application behaviour.

  • Load testing — exercise the system at expected production load to verify it meets SLA. Assumption: workload model accurately represents production (concurrency, think-times, request mix).

  • Stress testing — increasing load until the system degrades or fails, to find breaking points and recovery behaviour. Assumption: test safely isolates the system under test to avoid harming production.

  • Soak (endurance) testing — running a realistic load for a long time to reveal resource leaks (memory, file handles) and performance degradation over time.

  • Throughput — number of requests (or transactions) the system completes per unit time. Unit: requests per second (req/s).

  • Response time — elapsed wall-clock time between sending a request and receiving a complete response. Unit: seconds (s) or milliseconds (ms).

  • Latency — delay before data starts arriving; sometimes used interchangeably with response time, but strictly: latency is time to first byte.

  • Concurrent users (virtual users) — number of independent clients active at the same moment.

  • Think time — delay that simulates real user “reading/typing” time between actions.

  • Ramp-up — time JMeter uses to start all virtual users gradually.

  • Warm-up — period at test start where caches and JIT compile; measurements during warm-up are usually discarded to reach steady state.

  • Steady state — a period where measured metrics fluctuate around stable averages; valid results should be taken from steady state.

  • SLA (Service Level Agreement) — a formally agreed requirement, e.g., 95% of requests under 500 ms.

  • Little’s Law (queueing law) — exact relation under steady-state conditions: average number in the system equals arrival rate times average time in the system. Statement: For a stable system observed over a long interval, N = X · R, where N is the average number of concurrent requests (customers), X is throughput (requests per second) and R is average response time (seconds). Assumptions: system in steady state, averages taken over the same interval, flow conservation (every arrival eventually departs). Derivation (standard): Observe arrivals over time T, let C be completed requests. Throughput X = C/T. Sum of residence times of each completed request = integral of instantaneous number in system over time = N_avg · T. Average response time R = (sum of residence times)/C = (N_avg · T)/C = N_avg / X => N_avg = X · R. For diagrams draw a timeline from 0 to T and rectangles for each request spanning its start and end; stack rectangles vertically to see area equals sum of response times.

  • JMeter-specific: JMeter implements load with a Test Plan containing Thread Groups (each Thread is a virtual user), Samplers (HTTP Request, JDBC Request, etc.), Timers (think time), Config Elements (HTTP Header Manager, CSV Data Set), Assertions (validate responses), Pre/Post-Processors (setup and extract data), Listeners (collect metrics and reports). JMeter can run in GUI mode for building tests and non-GUI (command-line) mode for actual load runs.

Architecture diagram to draw: a box labelled Test Plan; inside it draw a Thread Group box (label threads = N, ramp-up = R_up, loop count), then arrows to Samplers (HTTP Request), Config Elements attached to sampler, Timers between threads and samplers, and Listeners outside collecting results. Label the Controller (GUI) vs non-GUI worker thread processes if distributed testing is described.

Formulas

Throughput = total_requests / total_time — total_requests: number of completed requests (unit: requests), total_time: measured time (s). Applies when measuring average throughput over a period.

Average response time (Tavg) = sum(response_times) / n — response_times: list of individual request durations (s), n: number of requests. Unit: s.

Error % = (failed_requests / total_requests) · 100% — unit: percent. Use for correctness under load.

N = X · R — Little's Law. N: average concurrent requests (dimensionless count), X: throughput (requests/s), R: average response time (s). Applies under steady state.

Concurrent users ≈ Throughput · (Response time + Think time) — approximate when think time is part of user cycle (s). Use to estimate needed virtual users in a closed workload model.

PERCENTILE(p) — value v such that p% of response times ≤ v — commonly 90th, 95th percentiles reported in ms.

JMeter command-line syntax to remember for test runs (syntax, not guaranteed flags on all versions): jmeter -n -t test_plan.jmx -l results.jtl -e -o report_dir — -n non-GUI, -t test file, -l results log, -e generate report, -o output directory. Verify exact flags for your JMeter version.

Worked examples

Example 1 — numeric throughput and error rate Given: A JMeter run recorded 3000 completed requests in 10 minutes (600 s). Of these, 150 were failures. During the run, the sum of all response times (successful + failed) was 900 s. Steps:

  1. Throughput = total_requests / total_time = 3000 / 600 = 5 req/s.
  2. Average response time Tavg = sum(response_times) / n = 900 s / 3000 = 0.3 s = 300 ms.
  3. Error % = (failed_requests / total_requests)·100% = (150 / 3000)·100% = 5%. Final answers: Throughput = 5 req/s; Average response time = 300 ms; Error rate = 5%.

Example 2 — trace of a small test plan (step-by-step) Test plan: Thread Group with 3 threads, ramp-up 3 s, each thread executes two HTTP samplers in sequence with 1 s think time between them. Assume each HTTP sampler response time is 200 ms and starts immediately when the thread reaches it. Steps and timeline (time in seconds):

  1. Ramp-up 3 s for 3 threads means JMeter starts 1 thread per second: Thread A at t=0, Thread B at t=1, Thread C at t=2.
  2. Thread A at t=0 sends Request 1 (200 ms) completing at t=0.2, then waits 1 s think time until t=1.2, then sends Request 2 completing at t=1.4.
  3. Thread B starts at t=1, sends Request 1 finishing t=1.2, waits until t=2.2, sends Request 2 finishing t=2.4.
  4. Thread C starts at t=2, sends Request 1 finishing t=2.2, waits until t=3.2, sends Request 2 finishing t=3.4. Compute throughput in interval t=0 to 4 s: total requests = 6, total_time = 4 s => average throughput = 6 / 4 = 1.5 req/s. Compute average concurrent requests using Little's Law: measure average response time R = 0.2 s (both requests 200 ms) => N = X·R = 1.5·0.2 = 0.3 concurrent requests on average (matches low concurrency due to think-time). Final: throughput 1.5 req/s, average concurrency 0.3 requests.

Example 3 — using Little’s Law to size threads for SLA Given SLA: steady throughput required X = 20 req/s; average response time expected R = 0.25 s; average think time per user = 4 s. Estimate needed concurrent threads N_user. Use closed model: user cycle time = R + think = 0.25 + 4 = 4.25 s. Throughput per user ≈ 1 / cycle = 0.2353 req/s. Threads needed = required throughput / per-user throughput = 20 / 0.2353 ≈ 85 users. Using Little’s Law also: N ≈ X·(R + think) = 20·4.25 = 85. Final: ≈85 virtual users.

Common mistakes

  • Confusing latency and response time — state which you measure (time-to-first-byte vs end-to-end time).
  • Ignoring network overhead and client bottlenecks — ensure load generators are not CPU/IO bound; otherwise results reflect generator limits.
  • Using unrealistic workload (no think times, all users identical, no session data) — leads to wrong capacity estimates.
  • Forgetting to add assertions or to log failures — high throughput with high error rate is meaningless.
  • Misinterpreting percentiles — 95th percentile means 95% of requests are at or below that value, not average.

For your exam

Types of questions you will see:

  • Definitions: Define performance testing, throughput, latency, etc. A full-marks answer gives the formal definition, units, and one line on when it applies.
  • Short notes: JMeter components, Little’s Law, warm-up vs ramp-up. Include diagrams of test plan structure.
  • Derivations: Derive Little’s Law from first principles (use timeline and sum of residence times). State assumptions.
  • Numericals: Compute throughput, avg response time, error rate, thread sizing via Little’s Law. Show formulas, units, steps and bold final answers.
  • Programs / commands: Provide JMeter command-line sample and test-plan elements. Explain non-GUI execution and report generation.
  • Diagrams: Draw Test Plan box with Thread Group, Samplers, Timers and Listeners; label ramp-up, thread count.

A full-mark numerical answer shows given data with units, the formula used, substitution with units, working and a final answer with units.

Quick check

  1. State Little’s Law formula and name its variables.
  2. In JMeter, which element simulates a real user’s pause between requests?
  3. How do you compute error percentage from results (write the formula)?

Answers: 1) N = X · R where N = average concurrent requests, X = throughput (req/s), R = average response time (s). 2) Timer (think time) — e.g., Constant Timer or Uniform Random Timer. 3) Error % = (failed_requests / total_requests) · 100%.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?