Comprehensive Guide to Performance Testing and Monitoring with JMeter, JConsole, and JVisualVM
This article explains how to conduct stress testing using JMeter, monitor Java applications with jconsole and jvisualvm, optimize gateway and microservice performance, improve database query speed with indexing, and tune garbage collection by enlarging the Eden space, providing step‑by‑step instructions and results.
This article provides a detailed, step‑by‑step tutorial on performance testing and monitoring of Java backend services.
1. What Is Stress Testing
1.1 Simple Explanation
Stress testing evaluates the maximum load a software and hardware environment can handle and identifies bottlenecks.
1.2 Performance Metrics
Response Time (RT)
Hits Per Second (HPS)
Queries Per Second (QPS)
MaxRT, MinRT, 90% response time
Throughput, error rate, etc.
2. JMeter Performance Testing Tool
2.1 Installation
Download JMeter from https://jmeter.apache.org/download_jmeter.cgi and use version apache-jmeter-5.3 .
2.2 Running JMeter
Execute \apache-jmeter-5.3\bin\jmeter.bat to launch the GUI.
2.3 Creating a Thread Group
Configure 200 threads to start within 1 s, loop 100 times, resulting in 20 000 requests.
2.4 Adding HTTP Request
Set protocol to HTTP, server to www.baidu.com , port 80 .
2.5 Adding Listeners
Include View Results Tree, Summary Report, and Aggregate Report.
2.6 Executing the Test
Start the test, then examine individual request results, summary report (average response time 151 ms, throughput 880 req/s), and aggregate report (median 59 ms, 90% ≤ 271 ms, error rate 0.41%).
3. Performance Monitoring with jconsole
Launch jconsole from the command line, select the passjava-question microservice, and view real‑time metrics such as heap usage, thread count, class loading, and CPU usage.
3.1 Overview
Shows memory, threads, classes, and CPU trends.
3.2 Memory, Threads, Classes, VM Summary, MBean
Detailed charts for each aspect, including loaded/unloaded class counts and VM parameters.
4. Performance Monitoring with jvisualvm
jvisualvm offers richer UI and plugin support.
4.1 Overview
Displays JVM version, startup parameters, and basic metrics.
4.2 Monitoring
Shows CPU, heap, class, and thread usage with more attractive charts.
4.3 Thread Details
Lists thread states: running, sleeping, waiting, parked, and blocked.
4.4 Sampler
Allows sampling of CPU or memory usage.
4.5 Plugins (Visual GC)
Install via Tools → Plugins → Visual GC to visualize garbage‑collection activity.
5. Gateway Performance Testing
Configure JMeter to target the API Gateway at port 8060 , send 200 requests per second continuously, and observe throughput of 2422 req/s, 90% response time 142 ms, 99% response time 281 ms.
6. Microservice Performance Testing
Add a simple test endpoint to passjava-question , verify with Postman or browser, then run JMeter against it, achieving throughput 3542 req/s, 90% response time 100 ms, 99% response time 152 ms.
7. Combined Gateway + Microservice Testing
Test the full request chain via http://localhost:8060/api/question/v1/admin/question/test , resulting in throughput 982 req/s, 90% response time 437 ms, 99% response time 790 ms, demonstrating a performance drop due to the additional network hop.
8. Database Query Optimization
Measure query latency for http://localhost:11000/question/v1/admin/question/list?type=5 . Initial latency 43 ms; after adding a regular index on the type column, latency drops to 18 ms.
9. Garbage‑Collection Optimization
Observe frequent GC in the Eden space (32 MB) causing 480 stop‑the‑world events per minute and low throughput (275 req/s). Increase heap to -Xmx1024m -Xms1024m -Xmn512m , reducing GC events to 92 per minute and raising throughput to 347 req/s.
10. Summary
The article demonstrates how to use JMeter for load testing, jconsole and jvisualvm for monitoring, and practical optimization techniques such as reducing middleware hops, adding database indexes, and enlarging the Eden space to improve Java application performance.
Wukong Talks Architecture
Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.