Alejandro Echeverri
Alejandro Echeverri

Reputation: 1358

Java Webapp Performance Issues

I have a Web Application, Made entirely with Java. The Webapp doesn't use any Graphical / Model Framework, instead, the webapp uses The Model-View Controller. It's made only with Servlet specification (Servlet ver. 2.4). The webapp it's developed since 2001, and it's very complex. Initially, was built for work with Tomcat 4.x/5.x. Actually, runs on Tomcat 6.x. But, we still having memory Leaks.

In Depth, the specifications of The Webapp can resumed as:

Infrastructure Specification

Actually, the webapp works in three environments:

First

Second

Third

Database specification

The webapp uses SQL Server 2008 R2 Express Edition as a DBMS, except for the user of the first server-specification, that uses SQL Server 2008 R2 Standard Edition. For the connection pools, the app uses Apache DBCP.

Problem

Well, it has very serious performance issues. The webapp slow down continually, and, many times Denies the Service. The only way to recover the app is restarting The Apache Tomcat Service. During a performance Audit, i've found several programming issues (Like database connections that never closes, excesive use of Vector collection [instead of ArrayList]).

I want to know how can improve the performance for the app, which applications can help me to monitoring the Tomcat performance and the Webapp Memory usage.

All suggestions are gladly accepted.

Upvotes: 2

Views: 2646

Answers (5)

Felix
Felix

Reputation: 6104

You could also try stagemonitor. It is an open source performance monitoring library. It records request response times, JVM metrics, request details including a call stack (profile) of the called methods during the request and more. Because of the low overhead, you can also use it in production.

The tuning procedure would be the following.

  • Identify slow requests with the Request Dashboard request dashboard
  • Analyze the stack trace of the request with the Request Detail Dashboard to find out about slow methods
  • Dive into your code and try to optimize those slow methods
  • You can also correlate some metrics like the throughput or number of sessions with the response time or cpu usage
  • Analyze the heap with the JVM Memory Dashboard

Note: I am the developer of stagemonitor.

Upvotes: 3

Anthony O.
Anthony O.

Reputation: 24297

You can try the open source tool Webapp Watcher in order to identify where in the code is the performance issue.

You have first to add a filter in the webapp (as explained here) in order to record metrics, and then import the logs in the WAW Analyzer tool and follow the steps described in the doc to know where is the potential performance issue in the code.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533472

The general solution is to use a profiler e.g. YourKit, with a realistic workload which reproduces the problem.

What I do first is a CPU only profile, a memory only profile and finally a CPU & Memory profile on at once (I then look at the CPU profile results)

YourKit can also monitor your high level operations such a Java EE resources and JDBC connections. I haven't tried these as I don't use them. ;)

It can be a good idea to improve the efficiency even if its not the cause of the problem as it will reduce the amount of "noise" in these profiles and make your issues more obvious.

You could try increasing the amount of memory available but a suspect it will just delay the problem.

Upvotes: 1

Pushkar
Pushkar

Reputation: 7580

Ok. So I have seen huge Java applications run lesser configurations. You should try to do the following -

  1. First connect a Profiler to your application and see which part of your application takes the most time. You can use JProfiler or Eclipse MAT ( I personally prefer JProfiler). Also try to take a look at the objects taking the most memory. This will help you narrow down to the parts which you need to rewrite to improve the performance.

  2. Once you have taken a look at the memory leaks update your application to use 64bit JDK(assuming it already does not do so)

  3. Take a look at your JVM arguments and optimize them.

Upvotes: 0

ŁukaszBachman
ŁukaszBachman

Reputation: 33735

I would start with some tools that can help you profiling the application. Since you are developing webapp start with Lambda Probe and Java melody.

The first step is to determine the conditions under which the app starts to behave oddly. Ask yourself few questions:

  1. Do performance issues arise right after applications starts, or overtime?
  2. Do performance issues are correlated to quantity of client requests?
  3. What is the real performance problem - high load on the server or lack of memory (note that they are related, so check which one starts first)
  4. Are there any background processes which are performing some massive operations? Are they scheduled to run at some particular time period?

Try to find some clues before going deep into code. It will help you to narrow down possible causes.

As Joshua Bloch has stated in his book entitled "Effective Java" - performance issues are rarely the effect of some minor mistakes in source code (although, of course, misuse of Java constructs can lead to disaster). Usually the cause is bad system (API) architecture.

The last suggestion based on my experience - try not to think that high memory consumption is something bad. Tomcat will use as much memory as operating system and JVM will let him (not more than max settings) and just when it needs more - Tomcat will perform garbage collection. So a typical (proper!) graph of memory consumption looks like a saw. If you are dealing with memory leak, then the graph will be increasing constantly, but indefinitely. This is the most often misunderstood of memory leaks, so keep it in mind.

To be honest - we cannot help you much further. Those are just pointers, now you will have to make extensive research to figure out the cause :)

Upvotes: 2

Related Questions