tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tino Schwarze <tino.schwa...@tisc.de>
Subject Improving memory efficiency
Date Thu, 15 Dec 2005 18:53:17 GMT
Hi there,

while hunting down a memory leak (it turned out that some servlets
didn't release PageContexts after use) I came across some places in
tomcat which are a bit memory inefficent.

(I'm talking about Tomcat 5.5 SVN as of tuesday or yesterday.)

The root cause (but not the problem) is that PageContexts are pooled in
JspFactoryImpl. The first interesting spot is the BodyContentImpl[] outs
member of PageContextImpl. It will only grow over time and it will never
release the BodyContentImpls stored in there. As PageContexts are
pooled, a single PageContext instance gets used by a lot of different
JSPs (possibly all JSPs present in the app).

The next interesting spot is the char[] cb member of BodyContentImpl it
will also only grow over time and never release the space occupied by
the buffer.

Let's consider a JSP with a single BodyTag which will buffer a
significant amount of data (say 1 MB). Over time, all
PageContextImpls.out[0].cb-s will grow to this size. The
JspFactoryImpl's PageContext pool contains up to 100 PageContexts, so I
may end up with 100 MB of memory which is basically unused.

I patched Tomcat to re-initialize PageContextImpl.outs on release().
This should increase memory efficiency significantly.

Second, I re-initialized BodyContentImpl.cb[] on clear() - this seems
superfluous but I found tags in the pools which still held
BodyContentImpls as bodyContent therefore possibly locking lots of
memory. Third, I let JspWriterImpl null it's cb on recycle() since I
also found some of these lingering around and still holding parts of the
output. The last two steps might be unneccessary if we could prevent
that tags in the pools still hold BodyContents (as far as
BodyTagSupport.bodyContent is involved).

What do you think about this issue?

Bye, Tino.

PS: Proposed patch attached.


Mime
View raw message