1 2 Previous Next 21 Replies Latest reply on Nov 5, 2007 8:28 AM by pmuir

    JSF performance tips in Seam applications

      Improving JSF performance in Seam Applications

      JSF performs best with server side state saving

      So in your web.xml you should have

      <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>server</param-value>
       </context-param>


      Improving render phase performance
      You should increase response buffer (to reduce reallocations at render time)
      (Experimentally I've seen 2 times better render times on larger pages esp with data tables)

      With Sun RI
      <context-param>
       <param-name>com.sun.faces.responseBufferSize</param-name>
       <param-value>500000</param-value>
       </context-param>


      If you using facelets add also
      <context-param>
       <param-name>facelets.BUFFER_SIZE</param-name>
       <param-value>500000</param-value>
       </context-param>



      With Seam chances are you are using Ajax4Jsf. Ajax4Jsf adds additional filter which parses XHTML output
      before sending to to browser.

      Use this filter definition
      <filter>
       <display-name>Ajax4jsf Filter</display-name>
       <filter-name>ajax4jsf</filter-name>
       <filter-class>org.ajax4jsf.FastFilter</filter-class>
       <init-param>
       <param-name>forceparser</param-name>
       <param-value>false</param-value>
       </init-param>
       </filter>
       <filter>
       <filter-mapping>
       <filter-name>ajax4jsf</filter-name>
       <url-pattern>*.seam</url-pattern>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       </filter-mapping>
      

      NOTE (IN newer Seam versions same settings are done via components.xml file; check docs)

      Or (better) turn off Ajax4Jsf filter completely if your XHTML is valid.

      There are 2 independent settings
      1) forceparser=false (prevents Ajax4Jsf parser from executing on non Ajax requests)
      2) filter-class=org.ajax4jsf.FastFilter (uses nekko parser which is faster than org.ajax4jsf.Filter)

      In production environment use (see https://facelets.dev.java.net/nonav/docs/dev/docbook.html#config-webapp-init)

      <context-param>
       <param-name>facelets.DEVELOPMENT</param-name>
       <param-value>false</param-value>
       </context-param>
       <context-param>
       <param-name>facelets.REFRESH_PERIOD</param-name>
       <param-value>-1</param-value>
       </context-param>
      


      In production JBoss server turn off Seam DEBUG level logging which is turned on by default in JBoss log4j configuration
      It is quite excessive and goes into JBoss server log (you do not see it on console)

      Use Native I/O on your application server. You usually need to install additional DLLs or shared libraries for that,
      check app server documentation and warnings on start-up.

      Check your JVM setting make sure memory settings are adequate for your application.
      JRockIt JVM should perform better than Sun's one.

      Make sure that your jar files contain XSD schemas and DTDs you refer in you XML configuration files
      especially Seam XSD (to prevent fetching them from Internet)

      Javassist performance optimization settings for Seam [TODO:]

      Performance of third party JSF component libraries

      1. Tomahawk (check their recommendation about StreamingAddResource, t:documentBody, t:documentHead, t:document)
      2. RichFaces (see ajax4sf filter tips)
      3. IceFaces [TODO]
      4. Trinidad [TODO]
      5. QuipuKit [TODO]
      6. Woodstock [TODO]

      General UI Design TIPS
      1. Avoid displaying large tables to user. Use pagination
      2. With many components on the page <ui:remove> will help you to identify which one is performance killer
      3. Try different methods to render same content (Ex: rendering tables with ui:repeat vs h:dataTable)
      4. Avoid components which use have JavaScript on client side unless you tested them carefully for
      their client side performance. Very often those render slow in browser cause of JavaScript in them, and
      not because of JSF server side RENDER phase. Fancy ones are usually very slow especially in IE.
      5. When using ajax4jsf you can sometimes reduce APPLY REQUEST VALUES JSF phase (which might be
      significant when large form with many inputs is submitted). Check documentation on ajaxOnly and relevant attributes
      6. Consider immediate=true attributes on elements where you do not need validation
      7. Choose wisely between client side and server side in components such as tabs, collapsible panels, etc
      8. Profile javascript with FireBug
      9. Choose appropriate java collection based on access method (direct, sequential, by key)
      10. Use java StringBuilder vs StringBuffer and + operator
      11. Consider using Web Remoting in some cases vs ajax4jsf for simple things (ex: dependable dropdowns)
      12. Do not over complicate EL expressions, code them in Java in backing bean
      13. Avoid constructing and destroying objects in a loop. Create once and re-use.
      14. Review your code you might be calling same functions repeatedly which could have been called only once


      Hibernate, EJB and back-end performance tips
      [Not covered in details but to mention a few]
      1. Use indexes on database tables appropriately
      2. Reduce number of round trips to database to fetch data (Ex: RowFetchSize in JDBC, join queries,
      insert batch and retrieve generated keys via result sets in one round trip, etc)
      3. USE CACHING (caching is easy to set up with hibernate)
      4. Do not use many transactions while serving one HTML page
      5. Be careful with excessive logging
      6. Understand Seam concept of conversations


      See below details about tips for server and client state savings scenarios


      For server side state with Sun RI see:

      http://wiki.glassfish.java.net/Wiki.jsp?page=JavaServerFacesRI#section-JavaServerFacesRI-WhatContextParametersAreAvailableAndWhatDoTheyDo

      <context-param>
       <param-name>com.sun.faces.numberOfViewsInSession</param-name>
       <param-value>50</param-value>
       </context-param>
       <context-param>
       <param-name>com.sun.faces.numberOfLogicalViews</param-name>
       <param-value>50</param-value>
       </context-param>



      For server side state with MyFaces see:

      http://wiki.apache.org/myfaces/Performance

      <context-param>
       <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
       <param-value>false</param-value>
       </context-param>
       <context-param>
       <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
       <param-value>false</param-value>
       </context-param>
       <context-param>
       <param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
       <param-value>50</param-value>
       <description>
       Only applicable if state saving method is "server" (= default).
       Defines the amount (default = 20) of the latest views are stored in session.
       </description>
       </context-param>
      
      
      If you are not using server state saving
      you still can gain some better results by using JBoss serialization

      for MyFaces follow steps for Client http://wiki.apache.org/myfaces/Performance:

      <context-param>
       <param-name>org.apache.myfaces.SERIAL_FACTORY</param-name>
       <param-value>org.apache.myfaces.JbossSerialFactory</param-value>
       </context-param>


      for Sun RI set (see http://jira.jboss.com/jira/browse/JBAS-3529)

      <context-param>
       <param-name>com.sun.faces.serializationProvider</param-name>
       <param-value>org.jboss.web.jsf.integration.serialization.JBossSerializationProvider</param-value>
       </context-param>
      

      Code can be found here
      http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/trunk/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossSerializationProvider.java


      Please, comment if you have more suggestion to add. This is for Seam Wiki.

      Thanks


        1 2 Previous Next