title: Very slow network response times for TomEE/Primefaces App
body: <p>We have developed a web application using TomEE 1.5.2 Plus (myfaces 2.1.13) and Primefaces 3.5. Performance is acceptable with typical server response times of about 70ms. When moving to TomEE 7.0.0-M3 Plus (myfaces 2.2.9) and Primefaces 5.3, these response times are now up to 900ms. Using the Firefox Web Console on the Network tab, these timings are all Waiting with 0ms Receive time. These appear to be <code>p:remoteCommand</code> server requests. Our app has many <code>p:dialog</code> user interfaces with managed View Scoped Beans. The more dialogs with <code>p:remoteCommands</code> the worse the performance. </p>
  
  <p>I have tried TomEE 7.0.1 Plus (myfaces 2.2.10 and Primefaces 6.0 with no better results. Test apps have shown that a simple dialog using a button and a p:remoteCommand to increment a counter and update the form and scaled from 20 dialogs, beans and buttons to 40 doubles the wait times (50ms to 100ms) using TomEE 7.0.0 and Primefaces 5.3. The same code run on TomEE 1.5.2 and Primefaces 3.5 shows no difference (30ms). </p>
  
  <p>When building with <code>facesContext.application.projectStage = Development</code> or Production in the TomEE 1.5.2/Primefaces 3.5 environment there is no difference. Production times are about 10% better in Production mode using TomEE 7.0.0/Primefaces 5.3. Sample test app code below:</p>
  
  <p>Main App
      </p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;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"&gt;
  
  &lt;h:head&gt;
    &lt;title&gt;COUNTER&lt;/title&gt;
  &lt;/h:head&gt;
  
  
  &lt;h:body&gt;
    &lt;ui:include src="/Dialogs/counterDialog.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog2.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog3.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog4.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog5.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog6.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog7.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog8.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog9.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog10.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog11.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog12.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog13.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog14.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog15.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog16.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog17.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog18.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog19.xhtml" /&gt;
    &lt;ui:include src="/Dialogs/counterDialog20.xhtml" /&gt;
  
  &lt;h:form id="countForm"&gt;
    &lt;input id="clickMe" type="button" value="clickMe" onclick="openCounterDialog();" /&gt;
    &lt;h:outputText id="count" value="#{counter.count}" /&gt;
    &lt;input id="clickMe2" type="button" value="clickMe2" onclick="openCounterDialog2();" /&gt;
    &lt;h:outputText id="count2" value="#{counter2.count}" /&gt;
    &lt;input id="clickMe3" type="button" value="clickMe3" onclick="openCounterDialog3();" /&gt;
    &lt;h:outputText id="count3" value="#{counter3.count}" /&gt;
    &lt;input id="clickMe4" type="button" value="clickMe4" onclick="openCounterDialog4();" /&gt;
    &lt;h:outputText id="count4" value="#{counter4.count}" /&gt;
    &lt;input id="clickMe5" type="button" value="clickMe5" onclick="openCounterDialog5();" /&gt;
    &lt;h:outputText id="count5" value="#{counter5.count}" /&gt;
    &lt;input id="clickMe6" type="button" value="clickMe6" onclick="openCounterDialog6();" /&gt;
    &lt;h:outputText id="count6" value="#{counter6.count}" /&gt;
    &lt;input id="clickMe7" type="button" value="clickMe7" onclick="openCounterDialog7();" /&gt;
    &lt;h:outputText id="count7" value="#{counter7.count}" /&gt;
    &lt;input id="clickMe8" type="button" value="clickMe8" onclick="openCounterDialog8();" /&gt;
    &lt;h:outputText id="count8" value="#{counter8.count}" /&gt;
    &lt;input id="clickMe9" type="button" value="clickMe9" onclick="openCounterDialog9();" /&gt;
    &lt;h:outputText id="count9" value="#{counter9.count}" /&gt;
    &lt;input id="clickMe10" type="button" value="clickMe10" onclick="openCounterDialog10();" /&gt;
    &lt;h:outputText id="count10" value="#{counter10.count}" /&gt;
  &lt;div&gt;
    &lt;input id="clickMe11" type="button" value="clickMe11" onclick="openCounterDialog11();" /&gt;
    &lt;h:outputText id="count11" value="#{counter11.count}" /&gt;
    &lt;input id="clickMe12" type="button" value="clickMe12" onclick="openCounterDialog12();" /&gt;
    &lt;h:outputText id="count12" value="#{counter12.count}" /&gt;
    &lt;input id="clickMe13" type="button" value="clickMe13" onclick="openCounterDialog13();" /&gt;
    &lt;h:outputText id="count13" value="#{counter13.count}" /&gt;
    &lt;input id="clickMe14" type="button" value="clickMe14" onclick="openCounterDialog14();" /&gt;
    &lt;h:outputText id="count14" value="#{counter14.count}" /&gt;
    &lt;input id="clickMe15" type="button" value="clickMe15" onclick="openCounterDialog15();" /&gt;
    &lt;h:outputText id="count15" value="#{counter15.count}" /&gt;
    &lt;input id="clickMe16" type="button" value="clickMe16" onclick="openCounterDialog16();" /&gt;
    &lt;h:outputText id="count16" value="#{counter16.count}" /&gt;
    &lt;input id="clickMe17" type="button" value="clickMe17" onclick="openCounterDialog17();" /&gt;
    &lt;h:outputText id="count17" value="#{counter17.count}" /&gt;
    &lt;input id="clickMe18" type="button" value="clickMe18" onclick="openCounterDialog18();" /&gt;
    &lt;h:outputText id="count18" value="#{counter18.count}" /&gt;
    &lt;input id="clickMe19" type="button" value="clickMe19" onclick="openCounterDialog19();" /&gt;
    &lt;h:outputText id="count19" value="#{counter19.count}" /&gt;
    &lt;input id="clickMe20" type="button" value="clickMe20" onclick="openCounterDialog20();" /&gt;
    &lt;h:outputText id="count20" value="#{counter20.count}" /&gt;
  &lt;/div&gt;
  
  &lt;/h:form&gt;
  
  &lt;/h:body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Dialog</p>
  
  <pre><code>&lt;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"&gt;
  
    &lt;p:dialog
      id="counterDialog1"
      header="Counter Form"
      widgetVar="counterWidget"
      closeOnEscape="true" &gt;
  
      &lt;p:ajax
        event="close"
        listener="#{counter.buttonHit()}"
        update="counterForm"
        resetValues="true" /&gt;
  
      &lt;h:form id="counterForm"&gt; 
  
        &lt;p:panel id="counterPanel"&gt;        
            &lt;input id="countMe" type="button" value="countMe" onclick="customfunction();" /&gt;
            &lt;p:remoteCommand name="increment" actionListener="#{counter.increment}" update=":countForm" /&gt;
        &lt;/p:panel&gt;
  
        &lt;div
          align="center"
          style="padding: 5px"&gt;
  
          &lt;p:commandButton
            id="counterOK"
            value="Ok"
            cache="false"
            ajax="true"
            style="valign:bottom;float:left;padding-left:10px"
            onclick="closeCounterDialog()" /&gt;
  
          &lt;p:commandButton
            id="counterCancel"
            value="Cancel"
            style="valign:bottom;float:center;padding-right:10px"
            onclick="closeCounterDialog()"
            process="@this"&gt;
  
          &lt;/p:commandButton&gt;
  
          &lt;p:commandButton
            id="counterHelp"
            value="Help"
            style="valign:bottom;float:right;padding-right:10px"
            disabled="true"&gt;
          &lt;/p:commandButton&gt;
  
          &lt;p:defaultCommand
            target="counterOK" /&gt;
  
        &lt;/div&gt;
      &lt;/h:form&gt;
    &lt;/p:dialog&gt;
  
    &lt;script type="text/javascript"&gt;
              //&lt;![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
              }
  
         //]]&gt;
       &lt;/script&gt;
  
  
  
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>Managed Bean Class</p>
  
  <pre><code>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()" );
    }
  
  }
  </code></pre>
  
  <p>Any ideas? Thank you in advance!</p>