velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nbu...@gmail.com>
Subject Re: how to reduce memory usage and still use the cache?
Date Thu, 03 Aug 2006 16:12:11 GMT
On 8/3/06, bruno <brunocarle@yahoo.com> wrote:
> Hello,
> We are using velocity for our web application, it is working pretty fine
> but now we have a problem because it consumes too much memory.
>
> When I run the application with the property
> webapp.resource.loader.cache=true
> after running a sample of 20 request of different pages, the memory used
> is about 300 Mb . (after garbage collector calls)
>
> After running the same sample with
> webapp.resource.loader.cache=false ,
> the memory consumption is only about 30Mb!
>
> We need to use the cache because of speed (the pages are processed more
> than ten times faster!) but on the other hand, we also would like to run
> several instances of the application on the same computer, so the memory
> usage is now a limitation for us.
>
> I tried using the file resouce loader and I get the same results.
>
> I have the impression that the velocity performs a kind of compilation
> of the templates, that are then interpreted and optionally cached in memory.
> Is it possible to cache this 'compiled' templates on disk instead of memory?

Actually, the cache is holding on to the AST (abstract syntax tree)
generated by the parsing of the template file.  These are just java
objects.  Many years ago there was some work done on compiling
templates, but this was abandoned as it grew apparent that the
benefits of that were not that great compared to the effort of
developing it.

So, no, i'm not aware of any way to save the templates on disk unless
it is possible to serialize them (i haven't checked, but i'm skeptical
that it would be).

> We are using jdk1.5.0_07 and velocity 1.4. I get the same results on
> Windows and Linux.
>
> Any suggestions?

Perhaps you could play around with the cache settings until you find
something more useful.  I don't remember what the default cache impl
is in 1.4, but in 1.5 it is an LRUMap if the following property is set
to a value > 0.  This lets you control the number of templates cached:

resource.manager.defaultcache.size=

You could also implement your own ResourceCache and tell the resource
manager to use that.


> Thanks in advance
> Bruno
>
> Here is our velocity.properties:
>
>
> # velocity.properties
> #--------------------
>
>
>
> velocimacro.library = \
> WEB-INF/velocimacros/Global.vm,\
> WEB-INF/velocimacros/Debug.vm,\
> WEB-INF/velocimacros/Menu.vm,\
> WEB-INF/velocimacros/Layout.vm,\
> WEB-INF/velocimacros/Buttons.vm,\
> WEB-INF/velocimacros/Fields.vm,\
> WEB-INF/velocimacros/List.vm,\
> WEB-INF/velocimacros/CRUD.vm,\
> WEB-INF/velocimacros/Filters.vm,\
> WEB-INF/velocimacros/Report.vm,\
> WEB-INF/velocimacros/Misc.vm,\
> WEB-INF/velocimacros/Ams.vm
>
>
> runtime.log.logsystem.class =
> org.apache.velocity.runtime.log.SimpleLog4JLogSystem
> runtime.log.logsystem.log4j.category = Velocity
>
>
>
> # Default name of the loop counter variable reference.
> directive.foreach.counter.name = velocityCount
> # Default starting value of the loop counter variable reference.
> directive.foreach.counter.initial.value = 0
>
> resource.loader = webapp
> webapp.resource.loader.class =
> org.apache.velocity.tools.view.servlet.WebappLoader
>
>
> ## -- PRODUCTION setup
> ----------------------------------------------------------------------------------
>
>
> velocimacro.library.autoreload=false
> webapp.resource.loader.cache=true
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


Mime
View raw message