0

我们使用 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 时,这些响应时间现在高达 900 毫秒。使用网络选项卡上的 Firefox Web 控制台,这些时间都是 Waiting with 0ms Receive time。这些似乎是p:remoteCommand服务器请求。我们的应用程序有许多p:dialog带有托管 View Scoped Bean 的用户界面。对话越多p:remoteCommands,性能越差。

我已经尝试过 TomEE 7.0.1 Plus(myfaces 2.2.10 和 Primefaces 6.0 没有更好的结果。测试应用程序显示一个简单的对话框使用按钮和 ap:remoteCommand 来增加计数器并更新表单并从 20 个对话框缩放,使用 TomEE 7.0.0 和 Primefaces 5.3 的 beans 和 button 将等待时间加倍(50ms 到 100ms)。在 TomEE 1.5.2 和 Primefaces 3.5 上运行相同的代码显示没有差异(30ms)。

在 TomEE 1.5.2/Primefaces 3.5 环境中构建facesContext.application.projectStage = Development或生产时,没有区别。在使用 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>

托管 Bean 类

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()" );
  }

}

有任何想法吗?先感谢您!

4

1 回答 1

0

某些版本的 primefaces 会为每个请求创建一个 bean 验证 Validator。如果它是定制的——JSF 环境通常就是这种情况——它真的会减慢应用程序的速度。确保您使用没有此问题的版本。

这是相关问题:https ://github.com/primefaces/primefaces/issues/1119

于 2016-07-21T18:27:40.033 回答