JSF性能改进 [英] JSF Performance improvement

查看:88
本文介绍了JSF性能改进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF 2.2 + Primefaces ...开发一个WebApp,该项目正在快速发展,并且首次性能测试非常糟糕(由于我对JSF LifeCylce的了解不足,并结合了非功能性要求-即完全ajax网站),那么我们可以有所改善,但结果仍然不尽人意. (根据动作的不同,我们需要300到1500毫秒的时间,想法是要有500毫秒左右的性能,可以接受或接受).主要是还原视图阶段和渲染响应是消费者花费的时间(其他原因,花费的时间毫无价值).对于某些操作,调用复制也需要时间(由于数据库调用).

I'm working on a WebApp using JSF 2.2 + Primefaces... project is growing fast, and first performance test was very poor (due to my poor knowledge on JSF LifeCylce in combination to non functional requirements - i.e. fully ajax website), then we could improve a little but results still, are not as expected. (We are having a time of 300~1500 ms depending on the action, idea is to have a performance around 500ms, give or take). Mainly the Restore View phase and the Render Response are the time consumers (on other fases, time spent is worthless). For some actions, Invoke Aplication also takes time (due to DB calls).

在网络上阅读了很多文章之后,有很多很棒的技巧需要考虑(当然很多是来自stackoverflow的),例如:

After reading lots of articles on the web, there were a lot of awesome tips to be taken into account (many of course from stackoverflow) such as:

  • 改善数据库查询
  • Improving DB queries

我们有一些复杂的问题,这些问题是通过两个Hibernate Criterias查询完成的,因此我们在这里进行了工作. (也许使用纯SQL查询,而在复杂查询上使用子查询?)

we have some complex ones which are done with two Hibernate Criterias queries so we have work here. (maybe use pure SQL queries, and on complex ones use sub-quering?)

  • 永远不要在Bean的getter上定义业务逻辑
  • Never defining business logic on Bean's getters

知道了!

  • 为bean设置适当的范围,并在其中存储必要的内容
  • Setting the appropriate scopes to bean and storing on them nothing more than the necessary stuff

我们有一个完整的ajax网站,因此View Scoped几乎和Session Scope一样,我们使用SessionBeans作为一种缓存"来存储我们不想每次都从DB获取的关键数据+在这里定义业务逻辑.

We have a full ajax site, so View Scoped are almost as Session Scoped to us, we are using the SessionBeans as a sort of 'Cache' to store key data which we don't want to get from DB every time + define businesses logic here.

  • 选择正确的JSF状态保存方法-Client Vs Server
  • Choosing the right State saving method of JSF - Client Vs Server

为此,我必须进行更多研究,检查其优点和缺点的可能性,然后在每个方面测试性能.

For this I have to research some more, check on the possibilities with their pros and cons, then test performance on each one.

到目前为止非常清楚,现在我有些疑惑.

So far very clear, now some extra tips on which I have some doubts.

  • 尽可能使用普通HTML,最好使用h:标记而不是p:标记
  • Use vanilla HTML as much as possible, and preferably use h: tags rather than p: tags

纯HTML清晰易懂,现在介于h:和p:之间有多少价值?例如.

Plain HTML is clear and make sense, now beetween h: and p: how much is it worthy? For example.

<p:commandButton value="Value" 
             styleClass="class" 
             actionListener="#{myBean.doStuff()}"
             ajax="true" process="@form" update="@form" 
             onsuccess="jsFunction()" />

vs

<h:commandButton value="Value" 
             styleClass="class" 
             actionListener="#{myBean.doStuff()}" >
       <f:ajax execute="@form" render="@form" event="onclick" />
</h:commandButton>

<ui:fragment... vs <p:fragment...

<p:outputLabel value="#{myBean.value}" rendered="#{myBean.shouldRender}" />

vs

<ui:fragment rendered="#{myBean.shouldRender}">
    <label>#{myBean.value}</label>
</ui:fragment>

一段时间以来,我一直在混合使用带有Jsf标签的Primefaces和一些普通的HTML.(主要是PF,由于其组件的功能)我现在普通的HTML总是会更快,但是在JSF和另一个框架?如果我这样做,更改它将花费大量时间,而且我不希望知道它根本不会带来任何相关变化的结果.

I've been using a mix of Primefaces with Jsf tags and some plain HTML here and there for a while now.(mainly PF due to their component's features) I now that plain HTML will always be faster, but between JSF and another Framework? If I go for this, changing it will take plenty of time and I wouldn't like the outcome of knowing it doesn't make a relevant difference at all.

  • 自定义Facelets标签与复合组件
  • Custom Facelets tags vs Composite Components

我认为这是关键.对于它们的差异还存在一些疑问,在两者的实现上, CC 都非常简单易用,但缺点是它们完全包含在ViewTree中,并且JSF为每个请求重新生成(如果我没记错的话,虽然自定义标签的使用似乎有点复杂(不是很多),但是它的优点是ViewTree仅包含实际呈现的内容,仅此而已,使RESTORE VIEW的时间减少.我们有几个复合组件,而没有Facelets标签,因此这将是很多工作.我仍然找不到一篇很好的文章来解释它们之间的差异,何时应该使用它们以及何时应该使用另一个(阅读过用于输入,消息使用TAGS以及用于更复杂事物的CC).如果您的想法是使用标签而不是CC,那么在这种情况下,我将没有选择而不是使用CC?是否可以在CC中使用自定义标签,使它们比JSF轻巧以便处理它们?

I think here's the key. Still have some doubts about their differences, on the implementation of both, CC are pretty simple and flexible to use but have the disadvantage that they are fully included on the ViewTree and JSF re-generates for each request (if I'm not mistaken), while custom tags seems a little bit more complex to use (not that much) but has the advantage that only what is actually rendered is included on the ViewTree and nothing more, making the RESTORE VIEW less time consuming. We have several composite components and none Facelets Tags, so here it will be much of the work to do. I still haven't found a good article explaining differences on them, when one should be used and when the other one (have read that for inputs, messages use TAGS and for more complex things CC). If the idea is to prefer tags vs CC, which would be the case on which I would have no option rather than using CC? Is it ok to use custom tags inside CC to make them lighter to JSF for processing them?

为了获得更好的性能,我将进入修改孔项目的旅程,这将花费我几天的时间,想法是这次要获得更好的结果;因此,每一个技巧,建议和建议都非常受欢迎!谢谢您的宝贵时间!

I'm about to get into a journey of modifying hole project in order to get a better performance which will take me a coulpe of days, idea is to get better results this time; so every tip, advice and suggestion is very welcomed! Thanks for your time guys!

推荐答案

半年前,我遇到了同样的问题.大多数时间都花在 RestoreView RenderResponse 阶段.如果你的问题是相同的,那么 您无能为力:

I faced the same problem half a year ago. Most of the time spent in RestoreView and RenderResponse phase. If your problem is the same then there is no much you can do:

  1. 尽可能使用partialSubmit="true"
  2. 使用execute(或PrimeFaces process)属性来减少服务器端的处理
  3. 减少组件数量
  4. 不要大量使用复合组件
  1. Use partialSubmit="true" as much as possible
  2. use the execute (or PrimeFaces process) attribute to reduce processing on the server side
  3. Reduce the number of components
  4. Do not use composite components a lot

在我的特殊情况下,我有很多没有输入控件的动态html, 我使用复合组件作为条件渲染的模板. 为了提高性能,我使用了 freemarker 来生成动态html.

In my particular case I had a lot of dynamic html without input controls and I used composite component as a template for conditional rendering. To increase performance I used freemarker to generate dynamic html.

PS.如果您拥有包含许多组件的复杂页面,我的观点是不使用JSF.我认为 Tapestry 为此进行了优化.它不会像JSF那样在每个请求上都重新创建组件.

PS. My opinion is not to use JSF if we you have complex pages with many components. I think Tapestry is more optimized for this. It doesn't recreate components on every request as JSF does.

这篇关于JSF性能改进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆