Struts2.1.8性能问题

在对系统做性能测试时,从Jprofiler CPU Views上看出,Struts2的OGNL和Freemarker非常耗时。

 

 我们当前使用的是struts2-core-2.1.8.1。在网上搜索一番后,找到如下的解决方案:

1. 减少Struts tag的使用,尽量使用JSTL,号称速度快一个数量级左右。

2. 升级Struts版本或OGNL版本, Struts2.3后的性能有较大的提升

3.  参考如下的官方说明,详情可参考:https://cwiki.apache.org/WW/performance-tuning.html


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 provides much better performance. See the following Jira issue for more information: https://issues.apache.org/jira/browse/WW-3580

Turn off logging and devMode.

devMode allows 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

If you use the simple theme, and do not overwrite any of the FreeMarker templates, consider using the java 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).

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 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.

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

As of Struts 2.0.10, setting the property struts.freemarker.templatesCache to 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.

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 will always be created (See http://forums.opensymphony.com/thread.jspa?messageID=5688 for 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}). 


其他提高Struts2性能的帖子:

  1. 提高Struts2性能:http://niyunjiu.iteye.com/blog/337840 
  2. OGNL, JSTL, MVEL, Aviator2 性能比较:http://www.cnblogs.com/coolhwm/archive/2011/11/25/2263519.htmlhttp://jindw.iteye.com/blog/732354
  3. Groovy,MVEL, OGNL性能比较:http://www.iteye.com/topic/361794 
  4. OGNL介绍:http://blog.csdn.net/chenjian198819/article/details/6638186  

转载于:https://www.cnblogs.com/ivanfu/archive/2012/03/14/2397038.html

基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值