What is JSF state saving?
A fundamental concept of JSF is server side UI component tree. It represents what is presented to the user in the browser. It is constructed when a page is accessed and it is restored during the post back processing. JSF client state saving method saves the component tree state in the client browser as hidden fields. JSF server state saving method saves the component tree state in the server side object, such as http session.
Pros and cons of each state saving method
When client saving method is used, the system has to use extra bandwidth to transfer the state information to the client. Also the system needs to transfer the state information back to the server when users make a request. When server side state saving is used, the system saves the information in the server. Therefore, it uses less bandwidth. However it uses more memory to store the state information.
Real World Application
Triptimes.ca is application that is similar to Google map. It allows users in Toronto to find the fastest route from point A to point B. The routes in triptimes.ca are different from Google routes. Our routes are real time traffic based. The application is built using JBoss Seam 2.1, JSF 1.2 and Richfaces 3.2 and it is deployed on Glassfish 2.1.
Triptimes.ca is application that is similar to Google map. It allows users in Toronto to find the fastest route from point A to point B. The routes in triptimes.ca are different from Google routes. Our routes are real time traffic based. The application is built using JBoss Seam 2.1, JSF 1.2 and Richfaces 3.2 and it is deployed on Glassfish 2.1.
The impact on memory usage and bandwidth
MessAdmin (http://messadmin.sourceforge.net/) is a tool to monitor java HttpSession including its size. I used this tool to monitor the HttpSession size and bandwidth used for our triptimes.ca application.
Figure 1, Figure 2, Figure 3 and Figure 4 show the session size, response size and objects in the session when users make the initial request to triptimes.ca. We can see from the diagram below that the Http session size is about 62k when server side state saving method is used, and the http session size is only 2.21 k bytes when client saving method is used. About 60k bytes memory is used to save the component tree state when server side state saving method is used. However, the application has to transfer extra 12k bytes information to the browser when client side saving method is used.
The impact on Scalability
JConsole is the Java monitor and management console to monitor java application. JMeter is a tool to do load test. Figure 5, Figure 6 and Figure 7 show the application server memory usage. We can see the diagram below that client side state saving method uses less memory and it is very scalable when you have to serve a large number of concurrent users.
Conclusion
There is both advantage and disadvantage about client state saving method and server state saving method. To choose the right method for your application, you need to analysis the http session size in your application and you need to do some load test to see if it meets your requirements.