I recently purchased JProbe as it was recommended as a good tool to check for memory leaks in Java applications.
I have a considerably large business application that consists of JSPs and JavaBeans which connects to a database. The application runs off a Tomcat server. Some information about the application is as follows:
a. JDK version 1.4.2_11
b. Database used is MS SQL Server 2000 with Server pack 4
c. Running on Tomcat version 4.1.31. Tomcat is being run as services.
d. Third party libraries -
i-Net Crystal Clear
CeWolf and JFreeChart
I noticed that the Tomcat memory utilization increases after a period of using the application. Having purchased Jprobe, the team is now proceeding to investigate the cause of the problem.
I would like very much to seek the expertise of the community here as to some technique / steps the team should take during the course of the investigation.
We are currently following the following steps:
a. Startup JProbe
b. Set a JProbe J2EE memory session which points to Tomcat and JDK
c. Run the JProbe session
d. Do a Collect Stack Trace
e. Login to our application, execute a "single function" and then logout
f. Do an Include Heapdump in Snapshot
g. Save the snapshot
h. Stop the JProbe session
i. Investigate the output
j. Repeat (c) to (i) for other functions in our application
Would appreciate if the community here could advice if we are proceeding with the investigation correctly and whether we are missing out on any memory leaks. All suggestions are most welcome.
Re: Memory Leaks in Java2007-04-24T09:08:46ZThis is the accepted answer. This is the accepted answer.Kingston,
JProbe is a good tool to find memory leaks, but the approach you described is the hard one to find leaks.
First make sure that the applicatie has a memory leak, memory usage increases can indicate a memory leak but are sometimes created by pools of some sort.
I recommend to write a test script that puts a load on the system. i.e. a normal system load. Start monitoring the memory usage. After a period the memory usage must be stable. this can take some time.
If the usage grows, you have a leak. Just take a snapshot of the memory and seek the most used object in memory (ignore the basic class like string and string buffer).
When found a suspect try restart the test and focus on the suspects.
Re: Memory Leaks in Java2007-04-30T02:09:59ZThis is the accepted answer. This is the accepted answer.
I agree with PietervdM's response. Several snapshots will help give you a good idea where the size or number of objects is increasing. Try to eliminate any preconceived notions of the problem, because the source can be unexpected. I recently had a severe memory problem because of over a million unexpected rows in the data that served multiple purposes (unknown to us.)
Also be sure to double check the obvious, like the session time out period.
Re: Memory Leaks in Java2007-04-30T03:52:18ZThis is the accepted answer. This is the accepted answer.Hi,
Just a bit more information about the application:
- 4490 JSP files
- 1492 Java Classes
- Tomcat 4.1.31
- JDK 1.4.2_11
- Microsoft SQL Server JDBC 2000
- Microsoft SQL Server 2000 SP4
Other JAR files:
- Cryptix 32
- i-Net Crystal Clear
All items mentioned above is running on a Server with Microsoft Windows Server 2003 with 2GB of RAM.
The JSP communicates to the JavaBean which in turn will connect to the Database via JDBC. We are not using connection pooling at the moment.
The SQL Server takes around 1GB of ram and I have configured Tomcat with an Initial 250MB and a maximum of 750MB of RAM. Tomcat is running under NT services.
Tomcat memory slowly increases and it takes around 4-7 weeks before it reaches the maximum memory and we get the out of memory error.
We have done checking for memory leaks using JProbe but have not found any leaks in our program yet. We did find some of our classes were not closing the connection. I am not sure whether this could be the cause of the memory leak. We have also checked for static members in our classes and have not found anything wrong with them.
Can anyone tell me whether:
a) Is 2GB RAM sufficient for this type of configuration?
b) If we add more RAM will it be more beneficial?
c) Our Tomcat web.xml configuration. Reloadable = true, Development = true. Will this cause memory leaks?
d) Should we upgrade to Tomcat 5 or 6?
e) Should we upgrade the JDBC Driver to 2005?
f) Should we upgrade the version of JDK to 1.5 or 1.6?
g) Is it recommended to restart Tomcat every now and then?
Re: Memory Leaks in Java2007-05-01T07:49:27ZThis is the accepted answer. This is the accepted answer.
Upgrading to a more recent version is possible, the performance of Java5 is better then 1.4, don't know about tomcat but probally the same.
When classes are not closing connection i would bet some money that there are memory leaks, at least when using oracle is does. And when the memory grows at such a slow rate it's hard to find. Stress test the application and see what happens then.
And for restarting, is the problem stays sure why not. keep the production version running, but consider downsizing the application. and find the leak ;-)
Re: Memory Leaks in Java2007-05-02T01:47:48ZThis is the accepted answer. This is the accepted answer.
Again, I generally agree with PietervdM's comments. Given the relatively long time before you get OutOfMemory, not closing the connection could be exactly your problem. You should always close connections, and the defensive programmer will also close ResultSets and Statements as soon as you are done with them.
I would definitely recommend going to at least JDK 1.5. In addition to performance enhancements, quite a lot was done to improve garbage collection.
I would also recommend moving to Microsoft's latest driver. And, you should see better performance from connection pooling.
Re: Memory Leaks in Java2007-05-03T02:58:34ZThis is the accepted answer. This is the accepted answer.
Thanks very much for your responses.
Just a quick question, I'm from Malaysia and was wondering if there is anyone in the region with expertise in the issues that I'm having that I could approach for consultation? Would be great to hear from you.
Thanks once again.
Re: Memory Leaks in Java2007-05-03T05:59:30ZThis is the accepted answer. This is the accepted answer.
- SystemAdmin 110000D4XK
While I have a friend who has an operation in Malaysia, they are SAP and do little, if any, Java. But why limit yourself to local talent? For example, I have a "local" client that I haven't seen since last June. We do all our operations via email, VPN and telephone. I have an IP phone with rates at 3 (three) cents per minute to Malaysia. I see people asking for local talent all the time and don't understand it when you could have the best in the world for not much price differential.