You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Will Glass-Husain (JIRA)" <de...@velocity.apache.org> on 2008/07/14 01:05:31 UTC

[jira] Resolved: (VELOCITY-223) VMs that use a large number of directives and macros use excessive amounts of memory - over 4-6MB RAM per form

     [ https://issues.apache.org/jira/browse/VELOCITY-223?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Will Glass-Husain resolved VELOCITY-223.
----------------------------------------

    Resolution: Fixed

Ok, never mind my previous two comments.  After doing some testing with YourKit, it's apparent  that memory usage for templates is drastically lower in the current 1.6-dev version (svn head) than in version 1.5.  And specifically, repeated macro calls in templates do not boost memory usage.

It turns out that the major refactoring to the macro system last summer by Supun took care of this issue.  Macros are now stored in a common macro library instead of a template by template basis.  They are still stored as a String (this is what confused me when I was reading the code).  But they are not duplicated for each template that is loaded.

Alexey's example generates two template objects that are just a few bytes in size.  The macros are stored in the VelocimacroManager, which is basically the size of the macro body plus a little overhead.

Resolving this old issue without applying Lei's patch.  (Thanks very much to all for the analysis and very reasonable solution).  If anyone has comments or still sees problems, reopen this bug or discuss on the dev list.



> VMs that use a large number of directives and macros use excessive amounts of memory - over 4-6MB RAM per form
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-223
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-223
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.3.1
>         Environment: Operating System: All
> Platform: All
>            Reporter: Christian Nichols
>             Fix For: 1.6
>
>         Attachments: 223-patch.txt, AllVelocityMemoryByClass.html, StringImagePool.java, VelocityCharStream.java, VelocityMemory.JPG
>
>
> Our application FinanceCenter is based on Velocity as the template engine.  We 
> have a library of about 200 macros and about 400 VM files.  Because the 
> velocity parser copies the macro body into the VM during parsing, macros that 
> are frequently used (even though identical and using local contexts) use up 
> large amounts of memory.  On our Linux server (running Redhat 7.2 with Sun JDK 
> 1.4.1_04) we can easily use up over 1GB of RAM simply by opening up many forms 
> (about 150) - the server starts out using 60MB after startup.  This memory 
> times out after 5 minutes and is returned which tells me that it is screen 
> memory.  Our problem is that the NT JVM and Linux JVM (32 bit) are currently 
> limited to about 1.6 - 2.0 GB of ram for heap space.  Thus, using a fair number 
> of forms in the application leaves little space for user session data.
> We have implemented a caching mechanism for compiled templates and integrated 
> it into Velocity so that cached objects are timed out of the cache but the 
> server is still using large amounts of memory.  We finally had to rewrite many 
> of our macros into Java so that memory usage would be reduced (note that these 
> macros were doing complex screen formatting not business logic).  Doing this 
> has reduced our memory by about 30%.  This is currently our biggest issue with 
> Velocity and is causing us to review our decision to stay with Velocity going 
> forward.  This is because we will likely end up with close to 1,000 forms by 
> the end of next year and need to know that Velocity can deal with this.  Is 
> there any work underway to share compiled macro AST's?  This would greatly 
> reduce the amount of memory used.  I have reviewed the parser code that is 
> doing this but it seems that this is an embedded part of the design and not 
> easily changed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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