This project showcases an example Java web application (EAR-based) benchmarked using Apache HTTP Server’s
ab
, VisualVM, and Apache JMeter. Developers will learn how to set up the environment, execute load tests, and collect performance metrics.
While the application is packaged as an EAR (Enterprise Archive) with standard modules (Core, EJB, Web), the primary focus here is benchmarking request performance under different tools. You'll learn:
- How to download and install required software 🛠️
- Where to unpack project files 📂
- Load testing with Apache
ab
🚀 - Profiling with VisualVM 🔍
- Advanced load testing with Apache JMeter 🎛️
- Generating & analyzing JMeter results 📈
Tool | Download Link | Notes |
---|---|---|
Java JDK 11+ | https://adoptium.net/ | Install and set JAVA_HOME . |
Apache HTTP Server (Apache24) | https://www.apachelounge.com/download/ | Needed for ab (Apache Bench). |
VisualVM | https://visualvm.github.io/download.html | For JVM profiling and monitoring. |
Apache JMeter | https://jmeter.apache.org/download_jmeter.cgi | Extract and configure .jmx tests. |
Steps:
- Download the ZIP or installer for each.
- Follow on-screen instructions or extract to a folder of your choice.
- Ensure executables (
java
,ab
,visualvm
,jmeter
) are on yourPATH
.
-
Clone or download this repository:
git clone https://github.com/Tharindu714/Perfomance-Testing-Guide-Project.git
-
Extract (if ZIP) to:
C:\Projects\BenchmarkingExample
-
Deploy the EAR to your application server (e.g., GlassFish, Payara, WildFly):
asadmin deploy C:/Projects/BenchmarkingExample/ear/BenchmarkApp.ear
-
Verify the web module is running (e.g.,
http://localhost:8080/app
).
Apache Bench is a simple CLI tool for HTTP request benchmarking.
# Single concurrency test:
ab -n 1000 -c 10 http://localhost:8080/app/api/hello
-n 1000
: Total requests.-c 10
: Concurrent clients.
# High-load test with custom header:
ab -n 5000 -c 50 -H "Authorization: Bearer token123" http://localhost:8080/app/api/data
Typical Output Fields:
- Requests per second: Throughput.
- Time per request: Latency.
- Transfer rate: Bandwidth.
Save results:
ab -n 10000 -c 100 http://localhost:8080/app/api/hello > ab_results.txt
VisualVM helps visualize heap, threads, and CPU usage.
-
Launch VisualVM:
visualvm
-
In Applications pane, locate your JVM (e.g.,
GlassFish Server
). -
Monitor:
- CPU: Real-time CPU load.
- Monitor: Heap usage and GC activity.
- Threads: Thread counts and states.
-
Profile:
- Switch to Sampler or Profiler.
- Start a CPU or Memory profiling session.
-
Run load tests concurrently (e.g., using
ab
or JMeter) to see live metrics.
📋 Tip: Take snapshots before and after tests to compare.
-
Open JMeter GUI:
jmeter
-
Design test plan:
- Thread Group: Set number of threads (users), ramp-up, and loop count.
- HTTP Request sampler: Configure server, port, and path.
- Listeners: Add View Results Tree, Summary Report, Aggregate Report.
-
Save your test as
benchmark_test.jmx
:File ▶ Save Test Plan As ▶ benchmarking/benchmark_test.jmx
jmeter -n -t C:/Projects/BenchmarkingExample/jmeter/benchmark_test.jmx \
-l C:/Projects/BenchmarkingExample/jmeter/results.jtl \
-e -o C:/Projects/BenchmarkingExample/jmeter/reports
-n
: Non-GUI mode.-t
: Test plan file.-l
: Log file (.jtl
).-e
: Generate dashboard report.-o
: Output folder for HTML report.
-
After test execution, open the HTML dashboard in your browser:
C:/Projects/BenchmarkingExample/jmeter/reports/index.html
-
Review metrics:
- Throughput: Requests per second.
- Average & 90th percentile response times.
- Error %: Failed requests.
- Graphs: Response times over time.
-
Export specific tables as CSV for reports.
- Network Emulation: Use tools like tc (Linux) or Clumsy (Windows) to simulate latency/packet loss.
- Distributed Testing: Run JMeter in master-slave mode for large-scale tests.
- CI Integration: Automate benchmarks in Jenkins or GitHub Actions.
- Baseline Comparisons: Always compare against a known baseline to detect regressions.
Your benchmarking journey starts here! 🚀 Adapt these steps to your environment and share your findings. Good luck! Cheers! 🎉