Featured image of post Stress Testing with JMeter

Stress Testing with JMeter

There are many stress testing tools, and ab is also a commonly used one. This time, let's try JMeter.

I previously used ab (ApacheBench), the built-in stress testing tool from Apache, but found it less convenient. After some research, I discovered a tool called JMeter.

Installing JDK

Since JMeter is developed in Java, we need a Java Runtime Environment (JRE). For simplicity, we’ll install the full JDK (Java Development Kit):

  1. Visit the official Oracle download page:
    https://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. Select JDK download:
  3. Accept the license agreement and download the appropriate version for your OS (Windows in this case):
  4. Run the installer with default settings (note the installation directory):

Configuring Environment Variables

  1. Locate the JDK’s bin directory (e.g., C:\Program Files\Java\jdk-11.0.1\bin) and copy the path.
  2. Add to System Path:
    • Right-click ComputerPropertiesAdvanced system settings
    • Environment Variables → Select PathEdit
  3. Paste the JDK bin path into the Path variable:
  4. Verify by running java --version in Command Prompt:

Installing JMeter

  1. Download JMeter from the official site:
    http://jmeter.apache.org/download_jmeter.cgi
  2. Extract the ZIP file to your preferred directory (JMeter is portable).
  3. Launch JMeter by running bin/jmeter.bat:
  4. Set Chinese localization (optional) by editing jmeter.properties:
    language=zh_CN
    

Usage Guide

  1. Create a new test plan: File → New
  2. Add a Thread Group:
    • Right-click Test Plan → Add → Threads (Users) → Thread Group
  3. Configure Thread Group:
    • Number of Threads (users): 200 (concurrent users)
    • Ramp-Up Period: 2 seconds (100 users per second)
    • Loop Count: 5 (total requests = 200 × 5 = 1000)
  4. Add an HTTP Request:
    • Right-click Thread Group → Add → Sampler → HTTP Request
  5. Configure HTTP Request:
    • Server Name/IP: example.com
    • Path: /api/test
  6. Add listeners for results:
    • View Results Tree
    • Summary Report
  7. Run the test (Run → Start) and save the test plan when prompted:
  8. View results in listeners:


Aggregate Report Metrics Explained

Metric Description
Label Name of the request (e.g., HTTP Request)
# Samples Total requests sent to the server
Average Average response time per request
Median 50th percentile response time
90% Line 90th percentile response time
95% Line 95th percentile response time
99% Line 99th percentile response time
Min Minimum response time
Max Maximum response time
Error % Error rate = (Failed requests / Total requests) × 100
Throughput Requests per second (RPS)
Received KB/sec Data received per second from the server
Sent KB/sec Data sent per second from the client