JMeter User Manual

This manual provides detailed instructions on how to use Apache JMeter to create and execute load tests.

Test Plan Structure

A JMeter test plan consists of the following core components:

1. Test Plan

The Test Plan is the root node of all tests, containing configuration information for the entire test. It can include:

  • User-defined variables
  • Global property settings
  • Thread Group configuration

2. Thread Group

Thread Groups are the execution units of tests, defining:

  • Number of Threads: Simulated number of users
  • Ramp-up Time: Time required to start all threads
  • Loop Count: Number of times each thread executes the test
  • Scheduler: Set test start time and duration

3. Samplers

Samplers send requests to servers. Common samplers include:

  • HTTP Request: Send HTTP/HTTPS requests
  • FTP Request: Test FTP servers
  • JDBC Request: Test database connections
  • LDAP Request: Test LDAP directories
  • JMS Message: Test message queues
  • TCP Sampler: Test TCP services

4. Logic Controllers

Logic Controllers control the execution order of requests:

  • Simple Controller: Group requests together
  • Loop Controller: Repeat execution of requests
  • Once Only Controller: Execute only once during the test
  • Interleave Controller: Alternate between requests
  • Random Controller: Randomly select requests to execute
  • Throughput Controller: Control request execution frequency

5. Listeners

Listeners view and analyze test results:

  • View Results Tree: View detailed response for each request
  • Aggregate Report: View aggregated performance statistics
  • Graph Results: Display test data graphically
  • Response Time Graph: Show response time trends

6. Config Elements

Config Elements set default values and shared data:

  • HTTP Request Defaults: Set default parameters for HTTP requests
  • User Defined Variables: Define reusable variables
  • CSV Data Set Config: Read test data from CSV files
  • HTTP Cookie Manager: Manage Cookies
  • HTTP Header Manager: Set request header information

7. Timers

Timers set delays between requests:

  • Fixed Timer: Set fixed delay
  • Gaussian Random Timer: Set random delay
  • Synchronizing Timer: Simulate concurrent requests
  • Throughput Timer: Control request throughput

8. Pre-processors and Post-processors

  • Pre-processors: Execute operations before request is sent
  • Post-processors: Extract data after receiving response

Creating Your First Test Plan

Step 1: Create Test Plan

  1. Launch JMeter
  2. Select "File" -> "New" to create a new test plan
  3. Name your test plan

Step 2: Add Thread Group

  1. Right-click on the test plan
  2. Select "Add" -> "Thread (Users)" -> "Thread Group"
  3. Set number of threads (e.g., 10), ramp-up time (e.g., 5 seconds), loop count (e.g., 1)

Step 3: Add HTTP Request

  1. Right-click on the thread group
  2. Select "Add" -> "Sampler" -> "HTTP Request"
  3. Set server name or IP, port number, request path, etc.

Step 4: Add Listener

  1. Right-click on thread group or HTTP request
  2. Select "Add" -> "Listener" -> "View Results Tree"
  3. Add "Aggregate Report" to view performance statistics

Step 5: Run Test

  1. Click the "Start" button on the toolbar
  2. Observe the result data displayed in the listener

Parameterization and Data-Driven Testing

Using CSV Data Files

  1. Add "CSV Data Set Config" element
  2. Set filename and variable names
  3. Use ${variableName} in requests to reference data

Using User Defined Variables

  1. Add "User Defined Variables" element
  2. Define variable names and values
  3. Use ${variableName} in requests

Correlation Handling

Using Regular Expression Extractor

When requests require dynamic data (like Session ID):

  1. Add "Regular Expression Extractor"
  2. Set regex pattern to match
  3. Use the extracted variable in subsequent requests

Using JSON Extractor

For JSON responses:

  1. Add "JSON Extractor"
  2. Set JSON Path expression
  3. Extract required JSON field values

Distributed Testing

When a single machine cannot generate enough load, distributed testing can be used:

Master Configuration

  1. Edit jmeter.properties in master bin directory
  2. Set remote_hosts to point to slave addresses
  3. Start JMeter

Slave Configuration

  1. Run jmeter-server on each slave machine
  2. Ensure firewall allows communication on specified ports

Starting Distributed Test

  1. Select "Remote Start" on master
  2. Choose which slaves to start or start all

Performance Optimization Tips

  • Use command-line mode to reduce GUI resource consumption
  • Set appropriate thread count and ramp-up time to avoid instant high load
  • Turn off unnecessary listeners, only view results when needed
  • Use assertions to verify response content
  • Clean up unused test plans regularly
  • For large-scale testing, consider distributed testing