This is the last article in the series of articles exploring the tools and techniques for analyzing, monitoring, and improving the performance of Java applications.
The Art of Java Application Performance Analysis and Tuning-Part 1 The Art of Java Application Performance Analysis and Tuning-Part 2 The Art of Java Application Performance Analysis and Tuning-Part 3 The Art of Java Application Performance Analysis and Tuning-Part 4 The Art of Java Application Performance Analysis and Tuning-Part 5 The Art of Java Application Performance Analysis and Tuning-Part 6
In this blog we are going to discuss performance analysis during development/QA and common Java performance problems.
Performance Analysis During during Development/QA
Many of us developers/QA engineers only test for functionality at low load and miss the performance issues at higher load. During higher load, application may experience the performance issues like slowness, OutOfMemory, Memory/Thread Leaks.
Development
Developers should be aware all the tools mentioned above. Thread dump analysis, JConsole, Jmap are must. Running Profilers like YourKit, IBM Health Monitor will give more insights of your program.
All the existing major features and new features must be profiled to identify the performance problems early in the development.
QA
QA members should be aware of tools like JConsole, JMap, Profilers/IBM HealthMonitor, Linux Commands like (top, ps, iostat, vmstat). All the existing/new features must be profiled to identify the performance problems early in the testing.
Common Java Performance Problems
OutOfMemory
Symptoms:
- OutOfMemoryError in logs
- Program stops responding
- JConsle/Jmap shows full memory usage
Analysis:
- Use Thread dump analysis to identify the cause of memory leak.
- Use JMap (Oracle)/IBM Health Monitor(IBM)-Memory to identify the leaked objects.
- Use Thread dump/JConsole for possible thread leak.
- Use Yourkit profiler to identify the leaked objects/caused classes/methods.
Thread Leaks
Symptoms:
- OutOfMemoryError in logs
- OS hangs
- OS related errors like
"Unable to fork new process" "Cannot allocate memory: fork: Unable to fork new process"
Analysis:
- Use Thread dump/JConsole to confirm possible Thread leak.
- Use Thread dump analysis/Method Profiling to identify the cause of thread leak method.
Command to find out number of the threads in Linux
# ps -elfT | wc -l
If Java process is leaking threads then this number increases. This can cause your system to reach maximum allowed threads/processes.
To see the number of threads one specific process is using you can do the following.
# ps -p PID -lfT # ps -p 2089 -lfT
If the above number is increasing then we can suspect thread leak.
The common causes of are thread leaks are
- Blocked threads
- Infinite loops in Thread.run()
- Not closing ExecutorService/ThreadPoolExecutor
Deadlocks
Symptoms:
- Program stops responding
- Application hangs
Analysis:
- Use Thread dumps/JConsole to confirm possible thread leak.
Reference :
Summary
Performance analysis and tuning is an art and is a iterative process. Performance tuning exercises should be accompanied by concrete performance requirements and measurement programs. Tools like Java thread dump , JConsole and IBM Health monitor
can help us in analyzing the applications. Analyzing Java thread dumps are critical for understanding what’s really going inside Java application server. Caching is important to reduce the load on database and to improve the performance.
Must Read Book
[1] “Java Concurrency In Practice” by Brian Goetz”, David Holmes, Doug Lea, Tim Peierls, Joshua Bloch