Performance tuning of Seam, JSF, Richfaces for webapps | Prashant P Java Specialist’s Blog | Planet JBoss Community.

 

Apart from following best practices while coding an application, we often come across the need to tune it up just a bit further to get that peek performance going.

On a recent project we faced some challenges in trying to increase the performance of our web application. We finally ended up optimizing the app and got very promising results. Here I put together some of the information used by us in one location, which is scattered over the web.

The frameworks used were, Seam 2.2 and JSF 1.2 with Richfaces 3.2 and also Spring 2.5 . Now without further delay here you go..

Some pointers on using JSF beans mapped in your view layer (JSP/XHTML when using facelets).

  1. Don’t put code in a getter (accessor method) of a managed bean

    The getters are invoked frequently to get the data. You could use some other method to fetch data and simply update the property.

    But if you did end up with few getters which hit the database for data loading, then consider putting a condition around that code to load data only if required.

    Example: Change code like the below;

    To load data conditionally as given below;

  2. Check scope of your beans. Seam provides a Conversation Scope use it instead of Session Scope if practical enough for your requirement.
  3. Richfaces does provide a huge set of components which are Ajax based.

    But many of those components also add to the processing overhead. Use them judiciously or it can affect your page load time pretty badly.

    Consider these points when trying to optimize a JSF/Richfaces application.

    • Avoid using rich:dataGrid or rich:dataTable whenever you can. The h:dataTable of JSF usually provides good enough options.
    • Do not use rich:tooltip inside a data table or grid. It’s very expensive and can lead to very slow rendering especially on IE.

      Also avoid nesting too many rich:xxx components inside a dataTable.

    • Use ajaxSingle=true attribute and a4j:region tag whenever possible. Also consider using limitToList attribute when reRendering.
    • Do not use multiple rich:modalPanel components for each view consider using one single rich:modalPanel with dynamic view.You could use a4j:include or ui:include (facelets) to change the view inside a modal panel.

Apart from following the above practices here are some goodies which will speed up your JSF with Richfaces webapp.

Add the below snippets to your web.xml

  • Use a global queue . (This is not strictly required if you are already using queuing of ajax requests)
  • Use NEKO parser instead of the default. This will speed up things.
  • Change the way css and java script files are loaded.

    If you view the source of your page you will notice that by default richfaces will add some includes of css and scripts which lead to multiple calls to load.

    For example with our web app we had like 8 css files and 23 js scripts getting loaded separately.

    and with the below setting our pages had just 1 css include and 2 script includes.

    Using the above settings we had reduced the css and js files to be loaded:

  • For Facelets and JSF RI from Sun you can use the below settings:

    Only if you are running under JBoss AS

When tuning your seam application you can use the components.xml file to tweak some settings.

  • Cache images and style globally.
  • Also if you are using richfaces with Seam you could configure the richfaces filter  in components.xml itself

    without needing to declare the filter in web.xml

    Disable the forceparser and turn on caching.

So in the end after optimizing the webapp by using framework provided settings, you can expect a lot better performance from your app. In the end you get happy visitors. Hope this bit of information helps you guys.

– See more at: http://planet.jboss.org/post/performance_tuning_of_seam_jsf_richfaces_for_webapps#sthash.bCtnaXas.dpuf

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注