You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2007/11/21 15:23:58 UTC

DO NOT REPLY [Bug 43925] New: - org.apache.jasper.runtime.BodyContentImpl causing huge memory allocations

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43925>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43925

           Summary: org.apache.jasper.runtime.BodyContentImpl causing huge
                    memory allocations
           Product: Tomcat 5
           Version: 5.5.24
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P3
         Component: Jasper
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: brian.remmington@celestialservices.co.uk


BodyContentImpl buffers all output from a custom tag ready to be written when
the tag execution ends. However, the way in which it grows this buffer is
extremely inefficient and has two undesirable effects:

- garbage collection is triggered very frequently to tidy up the waste.
- CPU load ramps up as large, unnecessary array copies take place.

All that's needed is a more intelligent buffer-management algorithm. I have
rewritten this class and can forward it if that would be useful (can't see a way
of attaching it here).

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 43925] - org.apache.jasper.runtime.BodyContentImpl causing huge memory allocations

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43925>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43925





------- Additional Comments From brian.remmington@celestialservices.co.uk  2008-02-08 07:33 -------
Created an attachment (id=21500)
 --> (http://issues.apache.org/bugzilla/attachment.cgi?id=21500&action=view)
Proposed changes to BodyContentImpl

The attachment "buzilla43925.jar" contains a new implementation of the
BodyContentImpl class (named "NewBodyContentImpl") and a new class on which it
depends named "CharBuffer". I have also included two JUnit test cases.

This new implementation performs 45% faster than the current implementation on
my test machine and is substantially more efficient in memory usage, causing no
character arrays to be left to the garbage collector unnecessarily.

I would greatly appreciate it if people would review this code, and let me have
any comments or suggestions.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 43925] - org.apache.jasper.runtime.BodyContentImpl causing huge memory allocations

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43925>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43925





------- Additional Comments From remm@apache.org  2008-02-14 05:35 -------
About the upper memory bound, I had missed the clear method. I thought the
original purpose was to keep the list of buffers around, now it looks to me the
memory usage is equivalent to the LIMIT_BUFFER mode.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 43925] - org.apache.jasper.runtime.BodyContentImpl causing huge memory allocations

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43925>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43925





------- Additional Comments From brian.remmington@celestialservices.co.uk  2008-02-12 01:44 -------
Thanks very much, Remy.

> - I don't see where memory usage is bounded in the code (if it's not, you should
> compare performance with the unbounded mode of Jasper, which will never
> reallocate anything); that's a problem

Perhaps you could help me here. The memory usage doesn't appear to be bounded in
the current implementation of BodyContentImpl which *always* appears to
reallocate exponentially-larger blocks (in the reAllocBuff method at the
bottom). I must be missing something, but am not sure what. I'm looking at the
head of 5.5, which is the version affected by this change.


> - The opportunity is the ability to share the buffer list per thread, so the
> CharBuffer.bufList should be ThreadLocal<LinkedList> (and should be limited in
> size, which should solve item 1); as a configuration option, it could be a
> concurrent static structure, for use with thread intensive connectors

This would require CharBuffer objects to be pooled to be of use. At the moment
they aren't (and neither are BodyContentImpl objects, as far as I can see). If I
understand you correctly, this would have the undesirable effect of holding onto
blocks of memory once allocated rather than making them available for garbage
collection. This would certainly require a bounded memory pool approach, but its
debatable whether that would be preferable. It would certainly be a bigger change.

> - CharBuffer.toArray is expensive (no other option, though), so you should try
> to show a (real) test result

I will put together a suitable test case for this. Is there a set of test cases
for the current implementation? If so I could just add new ones to it.


Regards
Brian

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 43925] - org.apache.jasper.runtime.BodyContentImpl causing huge memory allocations

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43925>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43925





------- Additional Comments From remm@apache.org  2008-02-10 18:20 -------
Ok, so I not sure I got everything, but:
- I don't see where memory usage is bounded in the code (if it's not, you should
compare performance with the unbounded mode of Jasper, which will never
reallocate anything); that's a problem
- The opportunity is the ability to share the buffer list per thread, so the
CharBuffer.bufList should be ThreadLocal<LinkedList> (and should be limited in
size, which should solve item 1); as a configuration option, it could be a
concurrent static structure, for use with thread intensive connectors
- CharBuffer.toArray is expensive (no other option, though), so you should try
to show a (real) test result

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 43925] - org.apache.jasper.runtime.BodyContentImpl causing huge memory allocations

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43925>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43925


markt@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement




------- Additional Comments From markt@apache.org  2007-11-23 12:11 -------
There is an option to attach patches just above comment box on the bugzilla page
for each bug.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org