Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Velocity performance pitfalls? [closed]

We are using Apache Velocity for website templates and some of them are getting complex. Have you noticed any performance issues with certain Velocity features? And how did you get around them?

like image 967
Petteri H Avatar asked Feb 25 '10 14:02

Petteri H


People also ask

What is VelocityContext?

VelocityContext(Context innerContext) Chaining constructor, used when you want to wrap a context in another. VelocityContext(Map<String,Object> context) Creates a new instance with the provided storage (and no inner context).

What is velocity .VM file?

Velocity is a Java-based templating engine. It's an open source web framework designed to be used as a view component in the MVC architecture, and it provides an alternative to some existing technologies such as JSP. Velocity can be used to generate XML files, SQL, PostScript and most other text-based formats.

What is Apache Velocity used for?

Apache Velocity first released in April 2001, is a Java-based template engine that provides a template language to reference objects defined in Java code. It aims to ensure clean separation between the presentation tier and business tiers in a Web application (the model–view–controller design pattern).

What is Apache Velocity Engine?

The Apache Velocity Engine is a free open-source templating engine. Velocity permits you to use a simple yet powerful template language to reference objects defined in Java code.


2 Answers

First of all use the latest velocity library(1.7 or 1.6.4). Version 1.5 contains some serious performance issues!

Also here is the list of parameters that you must tweak on production environment:

  1. velocimacro.library.autoreload - should be set to false
  2. file.resource.loader.cache - should be set to true
  3. file.resource.loader.modificationCheckInterval - should be set to -1
  4. parser.pool.size should be increased if default value is not big enough(default value is 20)
like image 61
yurilo Avatar answered Sep 25 '22 21:09

yurilo


The most important feature people often overlook is resource loader caching (off by default) which boosts performance quite a bit (file.resource.loader.cache).

#parse directive also has noticeable performance impact, try to use it only to avoid code duplication, not to just split templates into logical parts.

If your templates becoming quite complex in terms of logic maybe it would be possible to shift that logic to a controller and provide a template with ready to render data structure.

I didn't notice any performance drops from Velocity, when I was testing Velocity speed before switching from JSP they were constantly 50% faster on any template I threw at them. Currently we generate sites with thousands of pages rendered from Velocity templates and it is lightning fast, very satisfied with performance.

like image 24
serg Avatar answered Sep 23 '22 21:09

serg