我们使用TomEE 1.5.2 Plus(myfaces 2.1.13)和Primefaces 3.5开发了一个Web应用程序。典型的服务器响应时间约为70毫秒,性能可以接受。当转移到TomEE 7.0.0-M3 Plus(myfaces 2.2.9)和Primefaces 5.3时,这些响应时间现在高达900ms。使用“网络”选项卡上的“Firefox Web控制台”,这些计时都是等待,接收时间为0毫秒。这些似乎是p:remoteCommand
服务器请求。我们的应用程序具有许多p:dialog
用户界面和托管View Scoped Beans。 p:remoteCommands
对话越多,性能越差。
我尝试过TomEE 7.0.1 Plus(myfaces 2.2.10和Primefaces 6.0没有更好的结果。测试应用已经显示使用按钮和ap:remoteCommand的简单对话框来增加计数器并更新表单并缩放使用TomEE 7.0.0和Primefaces 5.3,20个对话框,bean和按钮使等待时间(50ms到100ms)加倍。相同的代码在TomEE 1.5.2上运行,Primefaces 3.5显示没有区别(30ms)。
在TomEE 1.5.2 / Primefaces 3.5环境中使用facesContext.application.projectStage = Development
或Production构建时,没有任何区别。使用TomEE 7.0.0 / Primefaces 5.3,在生产模式下,生产时间大约增加10%。示例测试应用程序代码如下:
主要应用程序
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite/components">
<h:head>
<title>COUNTER</title>
</h:head>
<h:body>
<ui:include src="/Dialogs/counterDialog.xhtml" />
<ui:include src="/Dialogs/counterDialog2.xhtml" />
<ui:include src="/Dialogs/counterDialog3.xhtml" />
<ui:include src="/Dialogs/counterDialog4.xhtml" />
<ui:include src="/Dialogs/counterDialog5.xhtml" />
<ui:include src="/Dialogs/counterDialog6.xhtml" />
<ui:include src="/Dialogs/counterDialog7.xhtml" />
<ui:include src="/Dialogs/counterDialog8.xhtml" />
<ui:include src="/Dialogs/counterDialog9.xhtml" />
<ui:include src="/Dialogs/counterDialog10.xhtml" />
<ui:include src="/Dialogs/counterDialog11.xhtml" />
<ui:include src="/Dialogs/counterDialog12.xhtml" />
<ui:include src="/Dialogs/counterDialog13.xhtml" />
<ui:include src="/Dialogs/counterDialog14.xhtml" />
<ui:include src="/Dialogs/counterDialog15.xhtml" />
<ui:include src="/Dialogs/counterDialog16.xhtml" />
<ui:include src="/Dialogs/counterDialog17.xhtml" />
<ui:include src="/Dialogs/counterDialog18.xhtml" />
<ui:include src="/Dialogs/counterDialog19.xhtml" />
<ui:include src="/Dialogs/counterDialog20.xhtml" />
<h:form id="countForm">
<input id="clickMe" type="button" value="clickMe" onclick="openCounterDialog();" />
<h:outputText id="count" value="#{counter.count}" />
<input id="clickMe2" type="button" value="clickMe2" onclick="openCounterDialog2();" />
<h:outputText id="count2" value="#{counter2.count}" />
<input id="clickMe3" type="button" value="clickMe3" onclick="openCounterDialog3();" />
<h:outputText id="count3" value="#{counter3.count}" />
<input id="clickMe4" type="button" value="clickMe4" onclick="openCounterDialog4();" />
<h:outputText id="count4" value="#{counter4.count}" />
<input id="clickMe5" type="button" value="clickMe5" onclick="openCounterDialog5();" />
<h:outputText id="count5" value="#{counter5.count}" />
<input id="clickMe6" type="button" value="clickMe6" onclick="openCounterDialog6();" />
<h:outputText id="count6" value="#{counter6.count}" />
<input id="clickMe7" type="button" value="clickMe7" onclick="openCounterDialog7();" />
<h:outputText id="count7" value="#{counter7.count}" />
<input id="clickMe8" type="button" value="clickMe8" onclick="openCounterDialog8();" />
<h:outputText id="count8" value="#{counter8.count}" />
<input id="clickMe9" type="button" value="clickMe9" onclick="openCounterDialog9();" />
<h:outputText id="count9" value="#{counter9.count}" />
<input id="clickMe10" type="button" value="clickMe10" onclick="openCounterDialog10();" />
<h:outputText id="count10" value="#{counter10.count}" />
<div>
<input id="clickMe11" type="button" value="clickMe11" onclick="openCounterDialog11();" />
<h:outputText id="count11" value="#{counter11.count}" />
<input id="clickMe12" type="button" value="clickMe12" onclick="openCounterDialog12();" />
<h:outputText id="count12" value="#{counter12.count}" />
<input id="clickMe13" type="button" value="clickMe13" onclick="openCounterDialog13();" />
<h:outputText id="count13" value="#{counter13.count}" />
<input id="clickMe14" type="button" value="clickMe14" onclick="openCounterDialog14();" />
<h:outputText id="count14" value="#{counter14.count}" />
<input id="clickMe15" type="button" value="clickMe15" onclick="openCounterDialog15();" />
<h:outputText id="count15" value="#{counter15.count}" />
<input id="clickMe16" type="button" value="clickMe16" onclick="openCounterDialog16();" />
<h:outputText id="count16" value="#{counter16.count}" />
<input id="clickMe17" type="button" value="clickMe17" onclick="openCounterDialog17();" />
<h:outputText id="count17" value="#{counter17.count}" />
<input id="clickMe18" type="button" value="clickMe18" onclick="openCounterDialog18();" />
<h:outputText id="count18" value="#{counter18.count}" />
<input id="clickMe19" type="button" value="clickMe19" onclick="openCounterDialog19();" />
<h:outputText id="count19" value="#{counter19.count}" />
<input id="clickMe20" type="button" value="clickMe20" onclick="openCounterDialog20();" />
<h:outputText id="count20" value="#{counter20.count}" />
</div>
</h:form>
</h:body>
</html>
对话框
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite/components">
<p:dialog
id="counterDialog1"
header="Counter Form"
widgetVar="counterWidget"
closeOnEscape="true" >
<p:ajax
event="close"
listener="#{counter.buttonHit()}"
update="counterForm"
resetValues="true" />
<h:form id="counterForm">
<p:panel id="counterPanel">
<input id="countMe" type="button" value="countMe" onclick="customfunction();" />
<p:remoteCommand name="increment" actionListener="#{counter.increment}" update=":countForm" />
</p:panel>
<div
align="center"
style="padding: 5px">
<p:commandButton
id="counterOK"
value="Ok"
cache="false"
ajax="true"
style="valign:bottom;float:left;padding-left:10px"
onclick="closeCounterDialog()" />
<p:commandButton
id="counterCancel"
value="Cancel"
style="valign:bottom;float:center;padding-right:10px"
onclick="closeCounterDialog()"
process="@this">
</p:commandButton>
<p:commandButton
id="counterHelp"
value="Help"
style="valign:bottom;float:right;padding-right:10px"
disabled="true">
</p:commandButton>
<p:defaultCommand
target="counterOK" />
</div>
</h:form>
</p:dialog>
<script type="text/javascript">
//<![CDATA[
// Keep script tag outside of any component tag that may need to get updated
// so JavaScript objects are not recreated. E.g. removing event handlers
// won't work after update since handler function is a different intance
function openCounterDialog ( event )
{
counterWidget.show();
}
/**
* Remove all the relevant event listeners, re-enable normal behavior and
* hide the dialog
*/
function closeCounterDialog ()
{
counterWidget.hide();
}
function customfunction()
{
//your custom code
increment(); //makes a remote call
}
//]]>
</script>
</ui:composition>
Managed Bean Class
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.context.RequestContext;
@ManagedBean(name = "counter")
@ViewScoped
public class Counter implements Serializable
{
/** Prevents compiler generating brittle one */
private static final long serialVersionUID = -2L;
int count;
public Counter()
{
count = 0;
}
public void increment()
{
count++;
}
public int getCount()
{
return count;
}
public void buttonHit()
{
RequestContext.getCurrentInstance ().execute ( "closeCounterDialog()" );
}
}
有什么想法吗?提前谢谢!
答案 0 :(得分:0)
某些版本的primefaces为每个请求创建一个bean验证Validator。如果它是自定义的 - 通常是JSF环境的情况 - 它将真正减慢应用程序。确保使用一个没有此问题的版本。
以下是相关问题:https://github.com/primefaces/primefaces/issues/1119