0

I'm developing a Java Spring - Hibernate web app that runs on Tomcat. Due to the app nature I'm experiencing memory/heap issues I never had before on other apps I developed. My app is a kind of analysis web tool that manages huge amounts of data that most times end up plotted in the presentation layer using Highcharts (JavaScript library for web charts, reference here). When I started to test it on Tomcat for the first time it crashed after the second request, and since then I've been tracking the memory usage. I'm not an expert on Tomcat but I believe the problem could be around the garbage collector. NetBeans 8.1 brings a memory profiler that shows the following when running on my app:

enter image description here

As you can see the amount of memory consumed is really high, considering it deals with one user. You can clearly see the increase in memory every time I make a request. Once the request finishes and the page is laoded with all the charts the memory used drops a little bit, but it never goes down close to 0. What's more is that after every request the memory drops a higher point, making it unsustainable in the long term. As you can see in the following Firebug screenshot the amount of data sent to the browser through ajax calls is not that huge:

enter image description here

It took 4,5 seconds to send 1,7 MB from the server, involving database accesses and other domain operations. As you can see in Firebug there are several ajax calls, belonging each of them to a Highcharts chart. I believe the garbage collector is not working properly, but I'm not sure. All JVM and Tomcat configurations are the default. What do you think?

Edit: I've checked all my database accesses and I'm sure connections are handled appropiately. Regarding session data, there is not much data stored and it is over-written on each request (my app works as a report application, so all session data for each report execution is overwritten on the next request).

Hauri
  • 275
  • 1
  • 7
  • 22
  • I think we should evaluate how have you defined the project to see if you're storing data in a place where GC cannot free, thus you generated a memory leak. This info is not enough to determine if the problem is caused by your application or by Tomcat. – Luiggi Mendoza Mar 09 '15 at 15:28
  • If you tell me what you need I can post more info. I've editted my post, by the way. – Hauri Mar 09 '15 at 15:36
  • You are never telling the objects they are free so they think they are still being used and cant be garbage collected. Also on the administration panel of tomcat you can manually garbage collect so maybe try that to narrow if it is tomcat or your application causing the memory issue. – jgr208 Mar 09 '15 at 15:41
  • Java is supposed to be handling that. – Hauri Mar 09 '15 at 15:43
  • @Hauri what is "that"? if java thinks you are still using an object it will not collect the object. – jgr208 Mar 09 '15 at 15:51
  • Yes, I know that, that's why I'm posting a question. I need help on what or how can I track these kind of objects. – Hauri Mar 09 '15 at 15:54
  • What is the error? Did you increase your max permgen size? you can also check http://stackoverflow.com/questions/12688778/increase-tomcat-memory-settings – sgpalit Mar 09 '15 at 15:54
  • thats why you use the tomcat administration panel and other tools on tomcat to see what is going on. – jgr208 Mar 09 '15 at 15:57
  • Java heap error. The first time it happened I configured the app to use allow more memory allocation, but the error keeps happening (later, but still happening). There is either a configuration issue or a memory leak, but I don't know where to start looking... – Hauri Mar 09 '15 at 15:58
  • If it happens later that means it is still growing and not getting collected for some reason. Maybe put your code through a profiler or step through the code to find the error. – jgr208 Mar 09 '15 at 16:38

1 Answers1

0

After working on this issue for 48 hours I think I've found the problem: a memory leak due to bad management of static methods and variables. Although this is particular to my case, I think some references that helped me on using NetBeans profiler could help someone else:

NetBeans profile

Stackoverflow post with tutorial

Hope it helps somebody else!

Community
  • 1
  • 1
Hauri
  • 275
  • 1
  • 7
  • 22