为什么 JSF 2.2 在 Wildfly 上部分渲染 ajax 请求需要更多时间

2023-12-21

我正在努力将项目从(JSF 1.2,在 JBoss 4.2.3 上运行的 Richfaces 3.3.4)迁移到(JSF 2.2,在 Wildfly 8.1.0 上运行的 Richfaces 4.5)。在部分迁移一些视图后,我发现使用 JSF 2 的应用程序的性能非常糟糕。

当发送 ajax 请求时,我注意到这个问题,JSF 2 正在渲染整个视图,尽管 render 属性指向一个 outputText

Example(可以从下载HERE https://github.com/tefaa89/JavaServerFacesPerformanceSample)

在我的示例中,我将为 JSF 1.2 和 2.2 使用相同的代码示例。之后,我将多次单击 ajax 按钮,并使用 chrome 检查工具测量每个请求的响应时间。

给定以下使用 JSF 1.2 和 Richfaces 3.3.4 的 index1.XHTML

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

多次点击“TestBtn”,平均时间为15ms:

给出使用 JSF 2.2 和 Richfaces 4.5.0 的以下 index2.XHTML

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

多次点击“TestBtn”,平均时间为18ms:

嗯,到目前为止一切顺利。现在,当我添加以下 outputText 元素时,性能问题就出现了

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

我在index1.xhtml和index2.xhtml中添加了这些元素300次,并重复相同的测试

使用index1.xhtml(JSF 1.2)的结果,我得到的平均时间为19ms

使用index2.xhtml(JSF 2.2)的结果,我得到的平均时间为150ms(!!!!!)

比 JSF 1.2 慢 8 倍

有人可以解释为什么 JSF 2 比 JSF 1 慢吗?我怎样才能提高性能?

UPDATE

在 tomcat 服务器上使用元素测试 JSF 2 示例,我得到平均 20 毫秒。我猜问题是由 Wildfly 方面引起的。

不幸的是我无法更改服务器。我应该找到一个让 JSF 2 在 Wildfly 上工作的解决方案。

我尝试升级到 Wildfly 8.2.0 --> 仍然存在相同的性能问题。

谷歌搜索后我能找到的最接近的问题是这个

所以我将我的JDK升级到了jdk1.7.0_71 --> 还是同样的性能问题。

UPDATE 2

以下是发送到 Wildfly 服务器的 ajax 请求(单击一次)的日志。(LOG) http://www.mediafire.com/download/68fpowabwyw0g5w/wildfly820.log

为什么 JSF 构建了整个视图,而我只是重新渲染了一个特定的 ID?

** 注意:我不知道这是否是 JSF 的工作方式,或者我只是误用了它。 **

提前致谢, 特法


我终于发现为什么 Wildfly 的 ajax 响应只对我来说很慢。

事实证明,这个性能问题与JSF版本或mojarra版本无关。它实际上与Wildfly配置有关(具体是Weld)

“org.jboss.as.weld”在我的 Wildfly 服务器中被禁用。默认情况下,当您下载 Wildfly 时,它是启用的。这就是为什么没有人遇到任何性能问题。

要在 Wildfly 中启用/禁用焊接,只需从“{JBOSS_HOME}/standalone/configuration”(扩展和子系统)中的standalone.xml 添加/删除以下两行:

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

如果您删除焊接并尝试我在问题中提到的示例,则 ajax 响应应该会出现延迟

我不知道为什么禁用焊接会导致此问题,但这是与当前问题无关的不同问题。

希望这可以帮助某人

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 JSF 2.2 在 Wildfly 上部分渲染 ajax 请求需要更多时间 的相关文章

随机推荐