Java Code Performance Analysis


Based on my experience and the maturity of tools and processes around Java applications, I can say that performance analysis of a Java code-base is a four prong process. One needs to perform all the four tasks to bring completeness to performance analysis on a code. Each of the steps in this process carries different weight based on its contribution towards improving the performance of the system. Lets look at the tasks involved.

Task 1: Static analysis of the code

This task involves a tool based generic check on the code for code quality, best practices and potential problematic code snippets. The tools can be customized to just check for the rules that impact the performance of the system. There are a lot of good open source tools available in this area which can run both as standalone and as Eclipse/Netbeans plugin. We recommend PMD, TPTP and FindBugs. I feel this task has a small contribution towards improvement of the performance of the system. Below i have attached a rule file that i derived from PMD which consists of rules that only check performance issues in the code.

PMD Rules

Task 2: Manual Code Review

This task involves a manual review of the code based on the best practices of the specific technology used in the code base, e.g Struts, there are best practices around Struts to make a Struts based application execute faster. One can create checklists of items that are industry accepted problematic areas in the framework and run it through the code. One should also try to automate this process by enhancing any of the tools mentioned in task 1 above. I feel this process also has a small contribution towards improvement of the performance of the system.

Task 3: Code Profiling

This task involves using a code profiler which keeps a watchful eye on a running code and keeps recording facts about it. The facts in turn help in analyzing the performance bottleneck areas in the code. There are quite a few open source tools in this area like Netbeans Profiler and Eclipse TPTP. Out of the commercial ones JProbe is recommended. We feel the results and findings of a profiler has a big impact on the overall performance improvement of the system. This task has significant contribution towards performance improvement of a code.

Task 4: Load / Stress test

This involves checking if the application really meets the defined performance requirements. There are good open source tools which assist in load testing both standalone and web based java applications. They enable us to simulate the load scenario expected in production application and hence tune the application to meet the expectations. I recommend JMeter. Again I feel this task also contributes significantly towards the performance improvement of the system.

If an application has external interfaces like database, queues, file system, third party systems etc the above process can still help us identify the impact due to the interfaces but there will be separate processes and tools to mitigate such impact.

One should look out for automating these tasks by integrating them into the IDE and/or build environment. The static analysis can be a IDE plugin running everytime the code changes. This helps detecting the issues early on. Similarly the code profiler should be integrated to IDE to help detect issues early on. The load tests can be automated and easily integrated with continuous integration tools.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s