Our company has one web application, provided by "X" vendor. this application has many JSPs and many TLDs used. The basic behaviour of the apoplication is to connect to the database (Oracle) get the information and show it to the user.
We deployed this web application in Tomcat 5.0.25 in the windows environment. One thing we observed here is, when we login to the application the tomcat5.exe process increses its memory. and when we logout, it does not come down to the original position. similar things happen when we search for some of the data using there provided searches.
We have some code developed which uses httpclient to login to this web application (created for performace testing). This code initially logs in 50 users which goes fine, then logs in 100 users which also goes fine but after this 100 users we ran the code for 50 users agian but this time it threw OutOfmemory exception:Java heap space error.
we are observing the memory in the Task Manager in windows.
Can anyone tell me what could be the cause of this? is it the web application causing problem or is tomcat caching some pages into the memory and is not releasing them?
1> Have you tweaked your jvm?
2> What are the values given for Xms and Xmx?
3> What is the size of XX:MaxPermGen?
4> How much RAM is available on the system where you have deployed your app?
5> Are you using pre-complied JSPs for faster response?
6> Which JDK are you using?
7> Have you tried using latest version of Tomcat?
8> If these doesnt help, use any profiler to find the leak. <JProfiler, JVMTI, YourKit profiler etc>
I hope answering these questions would help you :)
While all the questions are valid, the symptoms described by the original poster most likely indicate a memory leak in the application, which should be checked in the first place, instead of mitigating the problem by increasing the available memory with JVM params.
BTW. I prefer to call Java memory leaks as "memory thefts" since it better describes what happens in Java applications (the code takes the memory and "illegally" keeps it, its a bit different from memory leaks commonly known in C/C++ where a pointer to allocated memory is lost).
Yes, I agree that it could be a memory theft (leak). But before that we need to understand if the required memory is allocated to keep the user objects in memory is sufficient or not. if you give 256M heap memory and the user objects required for 150 users asks more than 256M, it is bound to throw memory error,
If at all,
1> heap memory allcoating is right,
2> the process still consume more memory than expected,
then we can say it is memory theft. For that we can use a profiler to see which objects are the culprits
Sounds like there is a memory leak based on your description.
There are pretty good tools available to detect memory leak. VisualVm is one of them. Attach VisualVm to the java process and monitor the used heap usage when users logs in.
If you suspect there is constant increase in memory. Take couple of heap dump and compare them. You can use visualvm or jmap tool to force heap. Use jhat/visualvm/net beans
or memory analyzer to find out which java objects are holding memory.