为什么JSF 2.2需要更多时间在Wildfly上部分呈现ajax请求
我正在努力将项目从(JSF 1.2,Richfaces 3.3.4在JBoss 4.2.3上运行)迁移到(JSF 2.2,Richfaces 4.5在Wildfly 8.1.0上运行).在部分迁移一些视图后,我发现使用JSF 2的应用程序的性能非常糟糕.
当发送ajax请求时,我注意到了这个问题,尽管render属性指向一个outputText,但JSF 2正在呈现整个视图 示例(可从HERE下载) 在我的示例中,我将对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: 给定以下index2.XHTML使用JSF 2.2和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> 多次单击“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示例,我得到平均20ms.我猜这个问题是由Wildfly方引起的. 不幸的是我无法改变服务器.我应该找到一个JSF 2的解决方案来处理wildfly. 我试图升级到wildfly 8.2.0 – >性能问题仍然相同. 我在google搜索后找到的最接近的问题是POST 所以我将JDK升级到jdk1.7.0_71 – >性能问题仍然相同. 更新2 这是发送到Wildfly服务器的ajax请求(一次点击)的日志. (LOG) 为什么JSF构建整个视图,虽然我只是重新呈现一个特定的ID? **注意:我不知道这是JSF假设的工作方式,或者我只是在滥用它. ** 提前致谢, 解决方法
我终于找到了为什么ajax对Wildfly的反应对我来说很慢.
事实证明,这个性能问题与JSF版本或mojarra版本无关.它实际上与Wildfly配置有关(Weld具体) 我的wildfly服务器中禁用了“org.jboss.as.weld”.默认情况下,当您下载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响应 我不知道为什么禁用焊接导致这个问题,但这是与当前问题无关的不同问题. 希望这可以帮助某人 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |