Apache Velocity 性能缺陷?
我们使用 Apache Velocity 作为网站模板,其中一些模板变得越来越复杂。您是否注意到某些 Velocity 功能存在任何性能问题?你是如何绕过他们的?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先使用最新的速度库(1.7或1.6.4)。
1.5 版本包含一些严重的性能问题!
另外,这里是您必须在生产环境中调整的参数列表:
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:
人们经常忽视的最重要的功能是资源加载器缓存(默认情况下关闭),它可以大大提高性能(
file.resource.loader.cache
)。#parse
指令也具有明显的性能影响,尝试仅使用它来避免代码重复,而不是仅仅将模板拆分为逻辑部分。如果您的模板在逻辑方面变得相当复杂,也许可以将该逻辑转移到控制器并提供准备渲染数据结构的模板。
我没有注意到 Velocity 的任何性能下降,当我在从 JSP 切换之前测试 Velocity 速度时,它们在我扔给它们的任何模板上始终快 50%。目前,我们生成的网站包含从 Velocity 模板呈现的数千个页面,速度快如闪电,对性能非常满意。
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.
我们尝试将
byte[]
缓存在ASTText
节点中,以避免对输出文本进行过多编码。We try to cache the
byte[]
in theASTText
node to avoid encoding the output text too much times.