views:

266

answers:

3

First of all, I lie, it's not really a plain jsp website. It has a couple of pages with database access and a lucene based search engine... and around 400 standalone jsp pages.

The problem is that the admins on a production server we've not access to, say that the site is consuming too much memory (200+ Megs), and we are probably facing a memory leak, because it forces them to reboot it.

I'm not a jsp expert, but I suspect that it's not really a memory leak, and that the database pages and the lucene search have nothing to do with this issue. I understand that each jsp page is compiled to a java class, then executed, and kept in memory for later access.

The real question is: Can this elevated (for 400, i think yes) number of standalone jsp pages cause the memory usage to grow up to 200M?

And if yes, how would you lower the memory usage? Using SSIs for includes (avoiding the use of jsp pages for that purpose) could be an option?

Thanks in advance

+1  A: 

The only way to know what consumes the memory is to use a profiler. What we do is to take a heap dump and then analyse it, in the following manner:

  • Use the jmap utility (comes with the JDK) to get the heap dump. It should be run as root!
  • Download the file to a locale machine
  • Download and install the Eclipse Memory Analyser - There are others (like jhat) but I personally like it.
  • Open the file with it
  • See which classes takes most of the memory.

Regardless, it is always good to pre-compile the JSPs before the server boots.

David Rabinowitz
+1  A: 

Half a megabyte per JSP is not what I'd usually expect. Obviously, one can write any code one likes in a JSP so a compiled jsp can be huge and can allocate huge amounts of memory, but assuming that these are conventional JSPs then I'd me most suspicious of run-time behaviours rather than the shear number of JSPs.

One possibility is that you have a lot of session data. As users move from page to page the session size might be increasing. It's quite common to see data retrieved from a database temprarily place in a session so that it can be used in another page. If theat doesn't get tidied up you can rapidly consume lots of memory.

djna
Ok, so half a meg for each jsp is not something usual. There are some JSPs that are consuming around 1.5M, and are only composed of text (around 15k) and include statements, with no session garbage sitting around. That's strange, as no jsp page weights less than 600k.
azkotoki
All I can suggest is to take one such JSP and gradually remove pieces until you find what is happening. Perhaps some large data structure is being created? Consider perhaps JDBC result sets are not being closed quickly enough?
djna
A: 

You need to determine where that memory is spent. The statement that 200MB is too much is really useless, as it depends on the usage, how the application is using memory (e.g. session data as David mentioned). You need to analyse heap dumps and verbose gc logs from various times in the application's lifecycle to understand the usage and whether you do in fact have a memory leak (if the application is stable at 200MB you don't. If it increases every x hours with no sign of decreeasing, you probably do).

dovetalk