Why JSF 2.2 takes more time partial rendering an a

2019-04-08 12:19发布

问题:

I am working on migrating a project from (JSF 1.2, Richfaces 3.3.4 running on JBoss 4.2.3) to (JSF 2.2, Richfaces 4.5 running on Wildfly 8.1.0). After partially migrating some views I found that the performance of the application using JSF 2 is terrible.

I noticed this issue when an ajax request is sent, JSF 2 is rendering the whole view although the render attribute is pointing to one outputText

Example (Can be downloaded from HERE)

In my example I will use the same code sample for both JSF 1.2 and 2.2. Afterwards I will click on the ajax button multiple times and measure the response time for each request using chrome inspection tool.

Given the following index1.XHTML using JSF 1.2 and Richfaces 3.3.4

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a="http://richfaces.org/a4j">
    <head>
    </head>

    <body id="body">
        <!-- Later the outputText elements below will be included here-->
        <h:form>
            <a:commandButton value="TestBtn" reRender="output"/>
        </h:form>
        <h:outputText value="test" id="output"/>
    </body>
</html>

Clicking on "TestBtn" multiple times, the average time is 15ms:

Given the following index2.XHTML using JSF 2.2 and Richfaces 4.5.0

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a="http://richfaces.org/a4j">
    <h:head>
    </h:head>

    <h:body id="body">
        <!-- Later the outputText elements below will be included here-->
        <h:form>
            <a:commandButton value="TestBtn" render="output"/>
        </h:form>
        <h:outputText value="test" id="output"/>
    </h:body>
</html>

Clicking on "TestBtn" multiple times, the average time is 18ms:

Well, so far so good. Now the performance issue comes when I add the following outputText elements

<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
<h:outputText value="testingElement"/>
 ............. (300 times, of course this is just for testing purposes)

I added these element 300 times in both index1.xhtml and index2.xhtml and repeated the same tests

The results using index1.xhtml (JSF 1.2), I got average time of 19ms

The results using index2.xhtml (JSF 2.2), I got average time of 150ms (!!!!!)

Which is 8 times slower than JSF 1.2

Could someone explain please why JSF 2 is slower than JSF 1? and how can I improve the performance?

UPDATE

Testing out JSF 2 example with elements on a tomcat server, I got average 20ms. I guess the problem is caused from the Wildfly side.

Unfortuanlty I can't change servers. I should find a solution for JSF 2 to work on wildfly.

I tried to upgrade to wildfly 8.2.0 --> Still the same performance issue.

The closest problem I could find after googling is this POST

So I upgraded my JDK to jdk1.7.0_71 --> Still the same performance issue.

UPDATE 2

Here is a log for an ajax request (for one click) sent to Wildfly server. (LOG)

Why is JSF building the whole view although I am only re-rendering a specific ID?

** Note: I don't know if this is how JSF suppose to work or I am just misusing it. **

Thanks in Advance, Tefa

回答1:

I finally found out why the ajax response with Wildfly is slow for me only.

It turns out that this performance issue has nothing to do with JSF version or mojarra version. It is actually related to Wildfly configuration (Weld to be specific)

"org.jboss.as.weld" was disabled in my wildfly server. By default, when you download wildfly it is enabled. That's why no one was getting any performance issues.

To enable/disable weld in Wildfly just add/remove the following 2 lines from the standalone.xml found in "{JBOSS_HOME}/standalone/configuration" (the extension and the subsystem):

<extensions>
    ..............
    <extension module="org.jboss.as.weld"/>
    ..............
</extensions>
<profile>
     ..............
    <subsystem xmlns="urn:jboss:domain:weld:2.0"/>
</profile>

If you remove weld and try out the example I mentioned in my question, you should have a delay in ajax responses

I don't know why disabling weld causing this issue but this is different question not related to this current question.

Hope this might help someone



回答2:

I ran your example without Richfaces using an h:commandButton and 300 outputTexts that bind to a bean property, wrapped with a panelGroup. While there was a difference, it's not earth chattering. It may, however, be worthwhile to create a JIRA issue for the Mojarra team to look into it.

Here are my results. I threw away the first request to rule out any initialization effect. Perhaps the most visible difference is with the last 5 requests average since the response time stopped fluctuating by that time (perhaps some optimization kicked in).

Using Mojarra 2.2.6:

Sample size: 20
Total time:  2111 ms
Average time: 105.55 ms
STDDEV: 22.01
Last 5 average: 85.40 ms

Using Mojarra 2.1.28:

Sample size: 20
Total time:  1331 ms
Average time: 66.55 ms
STDDEV: 29.94
Last 5 average: 39.60 ms


回答3:

I tested your example but using well-known Primefaces instead of Richfaces. It came up with 12ms for response time for every button click. I doubt that there might be something wrong with Richfaces command button javascript code. You may download Primefaces, carrying out the same test then come back here to tell me whether it's faster or slower.