Sunday, January 11, 2009

EGL: Performance Optimization

There are many factors which directly or indirectly affects the performance of EGL/Java Web Application. Performance tunning can be done at various ends. Mainly Application Level, Database Level and Server Level.

A few thoughts mentioned below:

Application level:
1) If you are displaying huge chunk of data in the UI (say more than 25 rows in a page) then programmatic pagination is must. That is segregate the resultset into different pages (may be 20-25 rows per page). And load data for each page on demand.
2) Give a look at the UI components for the page you are getting less performance and see if it can be simplified with lesser components. I know it is not easy and advisable to redesign at the point when delivery date is close.
3) You can use "Ajax" whenever and wherever possible. It will definitely increase the performance.
4) If you are using session variable make sure you remove it once it is done. DONOT wait till user logoff.
A topic of debate:
1) Hand written java code by professional is always better than generated java code. Hand written java code can always be fined tunned and pin-point using optimization tools like Optimizeit etc.
2) Now million dollar question (or may be some cents) is why jsf is defaulted to session scope and why not defaulted to request scope? How it is removed from the session on page transition? How and when the memory is reclaimed by JVM? As we all know we cannot force JVM to garbage collected.
Server Level:
It is one of the several important steps that needs to be performed in order to get maximum output. It is NOT very difficult and scary to make changes to server setting then sticking onto the default setting. Refer below links to get an insite of it http://www.ibm.com/developerworks/websphere/library/techarticles/0602_lurie/0602_lurie.html
http://whitepapers.techrepublic.com.com/abstract.aspx?docid=325396
http://rifers.org/blogs/gbevin/2005/4/21/get_rid_of_outofmemoryerror

Database Level:
This is under discussion and will be posted shortly.

Debate and discussions are always wel-come.

Regards
Monu

Thursday, January 8, 2009

JSF: Displaying "Loading....Please Wait!" message during ajax call

AJAX is becoming a specification in present day web application. Web 2 already infected and spread all across internet application. Web 3 is knocking at the doop step. more...

A very common requirement in ajax based web page is to convey the user that some server-side process is going on and the page/portion of the page is reloading. The best way to do this is displaying a suitable message like "Loading.....Please Wait!". Java Server Faces (JSF) is very impressive in implementing AJAX behavior in a page. It has provided well abstracted and easy to implement steps. Now coming back to message displaying use case; it requires just 4 additional changes:
  1. Download a ajax activity image and store in images folder under WebContent folder. You can refer to this site to generate a gif image http://www.ajaxload.info/
  2. Copy the below code anywhere in the page. Preferrably immediately after <body>
    <div id="loading"><p>Loading... Please wait!</p><img src="${pageContext.request.contextPath}/images/activity.gif" /></div>
  3. Add two javascript function as mentioned below:

    <script language="JavaScript">function startProgressBar(){ document.all.loading.style.visibility="visible";}function stopProgressBar(){ document.all.loading.style.visibility="hidden";}</script>
  4. Change the ajax tag in your jsf page
    <hx:ajaxRefreshRequest target="ajaxGroup" onstart="startProgressBar()" oncomplete="stopProgressBar()" id="ajaxRefreshRequest1"></hx:ajaxRefreshRequest>

Regards

Monu