3

I am working on a JSF application which is supposed to support a big scale of users logged in at the same time. And when we tried with our stress testing, we have observed that a large portion of CPU time is spent on rebuilding and traversing through the component tree.

My first thought was to try to make specific parts of the page stateless and thus be excluded from the component tree. But if I wrap a form element with the f:view being marked as transient:

<f:view transient="true">
    <h:form>
        ....
    </h:form>
</f:view>

, all my other forms on the page are also stateless (the hidden input field that is supposed to hold the state has for 'value' attribute value 'stateless': ).

Is there a way to make only specific forms on the page stateless, or the whole page can be either stateless or stateful?

Thanks for any kind of help!

EDIT:

For implementation we are using Mojarra 2.2.7, along with Primefaces 4.0 as a component library and Omnifaces 1.7 for some utility functionalities.

Nikola
  • 1,406
  • 2
  • 16
  • 20
  • Which JSF implementation are you using? which JSF component libraries are you using? – lu4242 Jul 03 '14 at 17:55
  • I have added it in an edit to the initial question. Thanks! – Nikola Jul 04 '14 at 08:40
  • I ignore how Mojarra works, but some tests I did some time ago shows that use f:view transient="true" has an effect. With MyFaces the algorithm has been designed in a way that state saving is really fast, so there is no difference between mark the whole view as stateless or not. Instead, from performance perspective, EL Caching, Html space compression and other improvements available in MyFaces are more effective. Try use MyFaces 2.2.4 and you'll see a big performance improvement, which is what you are looking for. – lu4242 Jul 04 '14 at 15:32
  • Take a look at this article that can help you with your stress tests: [Understanding JSF 2.0 Performance – Part 3](http://content.jsfcentral.com/c/journal/view_article_content?cmd=view&groupId=35702&articleId=73398&version=1.8#.U7bLaLFyVJg). The code is in [Github](https://github.com/lu4242/performance-comparison-java-web-frameworks) if you want to take a look. – lu4242 Jul 04 '14 at 15:47

1 Answers1

0

Based on what Balusc has said on this link, applying the transient on a view tag will make the entire view (i.e page) stateless which makes sense because setting transient to true calls the setTransient() on the UIViewRoot object. This can not be accomplished with your current setup. I'm not sure if there is a hack or work around to achieve a single page with multiple states some alternative way.

Community
  • 1
  • 1
Marquis Blount
  • 7,585
  • 8
  • 43
  • 67
  • It can be done if you write a custom component, but the point is if there is a real advantage of doing so. It depends on the JSF implementation and version. – lu4242 Jul 03 '14 at 22:35
  • This is not entirely true, at least not with Myfaces 2.3. After upgrade from Myfaces 2.2, transient views stop to work raising "unable to create views" exceptions. This drove me crazy a few hours, so in case it helps anyone: In myfaces 2.3, transient attribute of a template seems not to be inherited by the final page correctly. On page restoring, transient appears as false. The solution is to set transient="true" on the final page too. Other option is to use a block on the final page (f:metadata doc says it shouldn't be used in templates). – Aníbal Nov 23 '18 at 16:50
  • For future reference, we fixed the transient attr template/inheritance problem mentioned in the comment above in MyFaces 2.2.13 and 2.3.3: https://issues.apache.org/jira/browse/MYFACES-4267 – wtlucy Apr 23 '19 at 13:05