`
txidol
  • 浏览: 54556 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

【便利贴】Struts性能优化

 
阅读更多

Performance tuning

转载官网,少许翻译

The following are some tips and tricks to squeeze the most performance out of Struts 2.

Important OGNL update
For Struts 2 versions before 2.3: the OGNL version 3.0.3 library is a drop-in replacement for older OGNL jars, and providesmuchbetter performance. See the following Jira issue for more information:https://issues.apache.org/jira/browse/WW-3580

Turn off logging and devMode. 关掉日志与开发模式

devModeallows reloading of configuration and validation related files, but because they happen on each request, this setting will totally kill your performance.
When using logging, make sure to turn off logging (esp. Freemarker generates a LOT of logging), and check if a level is enabled before printing it, or you will get the cost of the String parsing/concatination anyways.

Use the Java Templates 使用Java模板

If you use the simple theme, and do not overwrite any of the FreeMarker templates, consider using thejava templates, which provide a drop in replacement for most tags, and are a lot faster than the regular tags.

Do not use interceptors you do not need. 不要使用拦截器,除非你真的需要

If you do not require a full stack of interceptors for an Action, then try using a different one (basicStack), or remove interceptors you do not need. Remove the I18nInterceptor interceptor if you don't need it, as it can cause a session to be created.

Use the correct HTTP headers (Cache-Control & Expires). 返回使用正确的HTML头部

When returning HTML views, make sure to add the correct headers so browsers know how to cache them.

Copy the static content from the Struts 2 jar when using the Ajax theme (Dojo) or the Calendar tag.拷贝struts jar包静态文件出来

Struts 2 uses some external javascript libraries and cascading stylesheets for certain themes and tags. These by default are located inside the Struts 2 jar, and a special filter returns them when requesting a special path (/struts). Although Struts 2 can handle these requests, an application/servlet container is not optimized for these kind of requests. Consider moving these .js and .css files to a seperated server (Lighttpd, Apache HTTPD, ..).

Create a freemarker.properties file in your WEB-INF/classes directory. 设置freemarker.properties模板更新延时时间

Create the freemarker.properties file and add the following setting (or whatever value you deem fitting):

template_update_delay=60000

This value determines how often Freemarker checks if it needs to reloads the templates from disk. The default value is 500 ms. Since there is no reason to check if a template needs reloading, it is best to set this to a very large value. Note that this value is in seconds and freemarker will convert this value to milliseconds.

See also:Freemarker configuration properties

Enable Freemarker template caching 关闭Freemarker模板缓存

As of Struts 2.0.10, setting the propertystruts.freemarker.templatesCacheto true will enable the Struts internal caching of Freemarker templates. This property is set to false by default.

In Struts versions prior to 2.0.10, you had to copy the /template directory from the Struts 2 jar in your WEB_APP root to utilize Freemarker's built in chaching mechanism in order to achieve similar results.

The built in Freemarker caching mechanism fails to properly cache templates when they are retrieved from the classpath. Copying them to the WEB_APP root allows Freemarker to cache them correctly. Freemarker looks at the last modified time of the template to determine if it needs to reload the templates. Resources retrieved from the classpath have no last modified time, so Freemarker will reload them on every request.

When overriding a theme, copy all necessary templates to the theme directory. 覆盖主题时,拷贝所以模板(含父模板)

There's a performance cost when a template cannot be found in the current directory. The reason for this is that Struts 2 must check for a template in the current theme first before falling back to the parent theme. In the future, this penalty could be eliminated by implementing a missing template cache in Struts 2.

Do not create sessions unless you need them.不要创建Session,除非你需要,国际化拦截器会创建Session

Struts 2 does not create sessions unless asked to (for example, by having the createSession interceptor in your interceptor stack). Note that when you use SiteMesh however, a session willalwaysbe created (Seehttp://forums.opensymphony.com/thread.jspa?messageID=5688for details). The I18nInterceptor interceptor can create sessions, so make sure you remove it, if you don't need it.

When using Freemarker, try to use the Freemarker equivalent rather than using the JSP tags.使用模板时采用${}方式

Freemarker has support for iterating lists, displaying properties, including other templates, macro's, and so on. There is a small performance cost when using the S2 tags instead of the Freemarker equivalent (eg. <s:property value="foo"/> should be replaced by ${foo}).


分享到:
评论

相关推荐

    桌面便利贴桌面便利贴桌面便利贴

    桌面便利贴桌面便利贴桌面便利贴桌面便利贴桌面便利贴桌面便利贴桌面便利贴桌面便利贴桌面便利贴

    桌面美丽便利贴

    记住这些事就交给简单的便利贴吧,你还在用传统纸质便利贴吗?从现在开始你可以丢掉传统便利贴,改用完全免费的桌面便利贴软件!把您的便笺“粘”在您的电脑桌面上,随时都能够在电脑屏幕上看到您的重要信息,既节约...

    javascript愿望便利贴七夕代码

    JavaScript愿望便利贴七夕代码是将浪漫节日与编程技术相结合的一种创意表现形式。在这个项目中,开发者使用JavaScript语言编写代码,以实现一个互动式的“愿望便利贴”功能,用户可以在网页上发布自己的七夕愿望,...

    PHP性能优化方式

    1. **魔法函数**:虽然魔法函数如`__get`, `__set`等提供了便利,但它们在背后会带来额外的性能开销。在不必要的情况下,应尽量避免使用。 2. **错误抑制符“@”**:虽然“@”符号可以用于抑制错误消息,但它会降低...

    微信读书 iOS 性能优化总结 | WeRead团队博客1

    合理分配线程是另一个重要的优化手段,尤其是在GCD的便利性可能导致过度使用子线程的情况下。项目团队设定了明确的线程使用规则,确保UI操作和DataSource操作在主线程,数据库操作、日志记录和网络回调在各自固定...

    JS日历便利贴.rar

    此外,为了保证跨浏览器兼容性和性能优化,开发者可能还需要引入一些库,如jQuery或Vue.js等。这些库简化了DOM操作,提供了丰富的插件和工具,让开发变得更加高效。例如,jQuery的`$.ajax()` 方法封装了Ajax操作,...

    便利贴小程序

    便利贴小程序

    电子便利贴,电子标签

    标题中的“电子便利贴”和“电子标签”指的是在数字环境中使用的类似传统便利贴的工具,它们可以帮助用户方便地记录和组织信息。这些工具通常具有轻量级、易用和可自定义的特点,使得在电脑或移动设备上管理待办事项...

    WPF便利贴程序

    这是一个用WPF编写的便利贴程序,可以给自己留便利贴,也可以向局域网上的其他人发送便利贴。虽然代码没有经过规范化的整理,但可读性也不低。其中涉及到WPF、动画、C#局域网通信、WPF样式、模板、Windows托盘程序等...

    便利贴-V1.0.exe

    便利贴-V1.0,适用于全系列的Windows操作系统,是您桌面便利贴的绝佳工具。

    Struts2与Struts1区别

    Struts2 和 Struts1 是两个著名的 Java Web 开发框架,它们都出自 Apache Software ...尽管 Struts2 在某些方面仍存在挑战,如性能优化和学习曲线,但其综合优势使其成为很多开发者在构建企业级应用时的首选框架之一。

    IOCP完成端口之性能优化

    4. **优化客户端映射**:使用如STL `map`等数据结构来存储和查找客户端信息,虽然提供了便利,但也可能带来额外的性能开销。为了优化这一过程,可以考虑直接使用客户端套接字(socket)作为键值,避免了复杂的查找...

    delphi 版 便利贴

    《Delphi版便利贴:一款全能的桌面小助手》 Delphi是一款强大的对象 Pascal 编程语言,以其高效、易用的特点在软件开发领域占据一席之地。利用Delphi进行开发的“便利贴”程序,是一款集多功能于一体的桌面工具,为...

    asp.net性能优化大全

    2. **减少Server Control的使用**:虽然Server Control提供了便利,但它们可能导致更多的服务器往返,影响性能。在不必要时,优先选择HTML控件或轻量级的Web控件。 3. **管理ViewState**:ViewState存储控件状态,...

    HTML5 – 创建一个Web网页便利贴

    在这个博文中,作者可能详细介绍了如何利用`contenteditable`属性创建一个简单的Web便利贴应用。首先,我们需要一个基本的HTML结构,包含一个具有`contenteditable`属性的元素作为便利贴的主要编辑区。此外,可能还...

    jquery 创意便利贴

    《jQuery创意便利贴》 在IT领域,JavaScript库如jQuery极大地简化了网页开发中的交互设计。本项目“jQuery创意便利贴”就是一个很好的实例,它利用jQuery的灵活性和强大的功能,为用户提供了类似便利贴的可拖动、可...

    Apache Pig的性能优化.pdf

    根据给定的文件信息,我们可以深入探讨Apache Pig的性能优化及其在大数据处理中的角色与优势。首先,让我们从Apache Pig的基本概念入手。 ### Apache Pig概述 Apache Pig是一种高生产力的数据流语言和执行框架,...

    任务管理便利贴PPT素材.pptx

    任务管理便利贴PPT素材.pptx,任务管理便利贴PPT,适用于分析任务状态更新等等各种情况,可以用在销售行业PPT中,项目汇报PPT中,任务管理PPT中,一个简单的任务管理便利贴,可以很清楚的罗列任务管理的完成情况

    桌面便笺--桌面便笺,方便快速的便利贴

    桌面便笺,方便快速的便利贴 桌面便笺,方便快速的便利贴 桌面便笺,方便快速的便利贴 桌面便笺,方便快速的便利贴

    超级实用的桌面便利贴

    标题“超级实用的桌面便利贴”指的是在个人计算机上使用的软件工具,它模拟了现实生活中贴在桌面上的便利贴,为用户提供了一种简单快捷的方式来记录和查看待办事项、提醒或其他重要信息。这类软件通常具有直观的用户...

Global site tag (gtag.js) - Google Analytics