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
- Launch JMeter
- Select "File" -> "New" to create a new test plan
- Name your test plan
Step 2: Add Thread Group
- Right-click on the test plan
- Select "Add" -> "Thread (Users)" -> "Thread Group"
- Set number of threads (e.g., 10), ramp-up time (e.g., 5 seconds), loop count (e.g., 1)
Step 3: Add HTTP Request
- Right-click on the thread group
- Select "Add" -> "Sampler" -> "HTTP Request"
- Set server name or IP, port number, request path, etc.
Step 4: Add Listener
- Right-click on thread group or HTTP request
- Select "Add" -> "Listener" -> "View Results Tree"
- Add "Aggregate Report" to view performance statistics
Step 5: Run Test
- Click the "Start" button on the toolbar
- Observe the result data displayed in the listener
Parameterization and Data-Driven Testing
Using CSV Data Files
- Add "CSV Data Set Config" element
- Set filename and variable names
- Use ${variableName} in requests to reference data
Using User Defined Variables
- Add "User Defined Variables" element
- Define variable names and values
- Use ${variableName} in requests
Correlation Handling
Using Regular Expression Extractor
When requests require dynamic data (like Session ID):
- Add "Regular Expression Extractor"
- Set regex pattern to match
- Use the extracted variable in subsequent requests
Using JSON Extractor
For JSON responses:
- Add "JSON Extractor"
- Set JSON Path expression
- Extract required JSON field values
Distributed Testing
When a single machine cannot generate enough load, distributed testing can be used:
Master Configuration
- Edit jmeter.properties in master bin directory
- Set remote_hosts to point to slave addresses
- Start JMeter
Slave Configuration
- Run jmeter-server on each slave machine
- Ensure firewall allows communication on specified ports
Starting Distributed Test
- Select "Remote Start" on master
- 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
