Apache Velocity 性能缺陷?

发布于 2024-08-22 12:31:31 字数 88 浏览 3 评论 0原文

我们使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

讽刺将军 2024-08-29 12:31:31

首先使用最新的速度库(1.7或1.6.4)。
1.5 版本包含一些严重的性能问题!

另外,这里是您必须在生产环境中调整的参数列表:

  1. velocimacro.library.autoreload - 应设置为false
  2. file.resource.loader.cache - 应设置为true
  3. file.resource.loader.modificationCheckInterval - 应设置为-1
  4. 如果默认值不够大,则应增加parser.pool.size(默认值为20

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)
沦落红尘 2024-08-29 12:31:31

人们经常忽视的最重要的功能是资源加载器缓存(默认情况下关闭),它可以大大提高性能(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.

回忆凄美了谁 2024-08-29 12:31:31

我们尝试将 byte[] 缓存在 ASTText 节点中,以避免对输出文本进行过多编码。

We try to cache the byte[] in the ASTText node to avoid encoding the output text too much times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文