我正在努力将项目从(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 的工作方式,或者我只是误用了它。 **
提前致谢,
特法