问题描述
我正在将项目从(在JBoss 4.2.3上运行的JSF 1.2,Richfaces 3.3.4)迁移到(在Wildfly 8.1.0上运行的JSF 2.2,Richfaces 4.5).在部分迁移了一些视图之后,我发现使用JSF 2的应用程序的性能很糟糕.
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.
发送ajax请求时,我注意到了这个问题,尽管render属性指向一个outputText,但JSF 2正在呈现整个视图
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
示例(可以从 HERE 下载)
在我的示例中,我将对JSF 1.2和2.2使用相同的代码示例.然后,我将多次单击ajax按钮,并使用Chrome检查工具测量每个请求的响应时间.
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.
使用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:
Clicking on "TestBtn" multiple times, the average time is 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:
Clicking on "TestBtn" multiple times, the average time is 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次,并重复了相同的测试
I added these element 300 times in both index1.xhtml and index2.xhtml and repeated the same tests
使用index1.xhtml(JSF 1.2)的结果,我得到的平均时间为19ms
The results using index1.xhtml (JSF 1.2), I got average time of 19ms
使用index2.xhtml(JSF 2.2)的结果,我得到的平均时间为150ms(!!!!!)
The results using index2.xhtml (JSF 2.2), I got average time of 150ms (!!!!!)
比JSF 1.2慢8倍
Which is 8 times slower than JSF 1.2
有人可以解释一下为什么JSF 2比JSF 1慢吗?以及如何提高性能?
Could someone explain please why JSF 2 is slower than JSF 1? and how can I improve the performance?
更新
用tomcat服务器上的元素测试JSF 2示例,我平均得到20ms的时间.我想这个问题是从Wildfly方面引起的.
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.
不幸的是,我无法更改服务器.我应该找到让JSF 2在Wildfly上运行的解决方案.
Unfortuanlty I can't change servers. I should find a solution for JSF 2 to work on wildfly.
我试图升级到wildfly 8.2.0->仍然是相同的性能问题.
I tried to upgrade to wildfly 8.2.0 --> Still the same performance issue.
在谷歌搜索后我能找到的最接近的问题是这个 POST
The closest problem I could find after googling is this POST
因此我将JDK升级到jdk1.7.0_71->仍然存在相同的性能问题.
So I upgraded my JDK to jdk1.7.0_71 --> Still the same performance issue.
更新2
这是发送到Wildfly服务器的ajax请求(单击一次)的日志. (LOG)
Here is a log for an ajax request (for one click) sent to Wildfly server. (LOG)
尽管我只是重新渲染特定的ID,为什么JSF仍要构建整个视图?
Why is JSF building the whole view although I am only re-rendering a specific ID?
**注:我不知道这是JSF假定的工作方式,还是我只是在滥用它. **
** Note: I don't know if this is how JSF suppose to work or I am just misusing it. **
在此先感谢您,特法(Tefa)
Thanks in Advance,Tefa
推荐答案
我终于发现了为什么Wildfly的ajax响应仅对我缓慢.
I finally found out why the ajax response with Wildfly is slow for me only.
事实证明,此性能问题与JSF版本或mojarra版本无关.它实际上与Wildfly配置有关(需要具体说明)
在我的wildfly服务器中禁用了"org.jboss.as.weld".默认情况下,当您下载wildfly时,它已启用.这就是为什么没有人遇到任何性能问题的原因.
"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.
要在Wildfly中启用/禁用焊接,只需从"{JBOSS_HOME}/standalone/configuration"(扩展名和子系统)中的standalone.xml中添加/删除以下两行:
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>
如果删除焊缝并尝试我在问题中提到的示例,则应该延迟ajax响应
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
这篇关于为什么JSF 2.2需要花费更多时间在Wildfly上部分呈现ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!