I have a considerably large business application that consists of JSPs and Java class which connects to a database.
The application runs off a Tomcat server. Some information about the application is as follows:
Application contains: - 4490 JSP files - 1492 Java Classes
Application Server: - Tomcat 4.1.31 - JDK 1.4.2_11
Database: - Microsoft SQL Server JDBC 2000 - Microsoft SQL Server 2000 SP4
Other JAR files: - Cryptix 32 - jxl - CeWolf - 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 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 (-Xms) 250MB and a maximum of (-Xmx) 750MB of RAM. Tomcat is running under NT services.
I noticed that the Tomcat memory utilization increases after a period of using the application.
Here are some dates and the memory utlization we have recorded
December 19, 2006 - Started Tomcat January 3, 2007 - Physical Memory (106,012 KB), VM Size (304,560 KB) January 10, 2007 - Physical Memory (119,636 KB), VM Size (329,536 KB) January 17, 2007 - Physical Memory (132,776 KB), VM Size (335,248 KB) January 24, 2007 - Physical Memory (133,684 KB), VM Size (340,500 KB) January 31, 2007 - Physical Memory (196,972 KB), VM Size (344,204 KB) February 8, 2007 - Physical Memory (165,556 KB), VM Size (347,828 KB) February 12, 2007 - Physical Memory (135,764 KB), VM Size (350,004 KB) February 13, 2007 - Physical Memory (173,308 KB), VM Size (350,316 KB) February 14, 2007 - Physical Memory (263,840 KB), VM Size (384,778 KB) February 15, 2007 - Physical Memory (259,952 KB), VM Size (407,424 KB) February 16, 2007 - Physical Memory (211,450 KB), VM Size (450,492 KB) February 21, 2007 - Physical Memory (319,960 KB), VM Size (504,256 KB) February 22, 2007 - Physical Memory (230,956 KB), VM Size (549,568 KB) February 23, 2007 - Physical Memory (371,788 KB), VM Size (594,148 KB) February 26, 2007 - Physical Memory (approximately 800MB), VM Size (approximately 800MB)
The server was reported to be slow (high page fault delta) on Feb 26, 2007 and we had to restart Tomcat.
We suspect that we had a memory leak within our application and bought JProbe to perform some tests. We discovered that each user that logged in had a Java class in the session that held an open database connection. We have also discovered a number of places in our application that did not close the database connection. Btw, we are not using connection pooling
We have fixed our code to close the connections, statements and resultsets and deployed it to our production environment.
The patch was placed in production on May 30, 2007. On June 6, 2007 the Physical Memory was reported to be at 304MB. On June 20, 2007, the Physical Memory is at 320MB and the VM Size is at 335MB. The highest Physical Memory reported up to now is at 342MB.
Prior to this Tomcat was running well from March 29, 2007 to May 30, 2007 (approximately 2 months uptime - we had to restart Tomcat when we installed the patch).
Here are some of my questions:
- Does unclosed connection actually cause memory leak?
- Based on the information on Physical Memory and the VM Size above can anyone tell me how do they correlate with each other? I noticed that the Physical Memory can fluctuate, however, the VM Size will always keep increasing.
- Since this machine has only 2GB of RAM with 1GB used by SQL Server, is it a good idea to set the maximum memory to 750MB? Should I set the initial memory to 750MB also or to set both the minimum and maximum heap to let say 500MB?
- Do you think I still have memory leak in my application?
- Would this problem be solved if I upgrade Tomcat to 6.0 and JDK to 1.6?
- Would JRockIT be a better alternative since I noticed the memory management is different from Sun JVM? However, I noticed that JRockit starts with a higher initial memory even with the same settings.
|