Hi All, I am having some doubts about keeping the data in the session. Just want to get your inputs. My question is , when will be the performance of the j2ee application better if we keep the all the data in the session or we keep it in request scope.
Somehow i feel that if say in struts we keep the form bean in the session scope it will effect the response time and overall performance of the application as compared to if we keep form bean is request scope.
But i am not sure I am right or not. May be you guys can help me out in understanding this.
Thanks for your reply in advance.
Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
The more you load up your sessions, the more memory your app will require to run. This can greatly affect your scalability. If you're clustering sessions, adding more servers won't necessarily help.
On the other hand, if keeping commonly used objects in session can help to reduce object creation and destruction it may cut down both CPU usage and reduce the number of times garbage collection is run (expensive). Cutting down database calls by caching commonly used data in session can greatly improve the speed.
There are tradeoffs and there is no one, set rule for achieving the right balance. If you're expecting ten million users a day, keeping session data in memory for every user is not a good idea. For an intranet or low volume site where users log in and stay in for a long time, caching the right data instead of reading from disk every time can make your app scream.
Build your app for clarity, profile it to find the bottlnecks, and optimize where you can make the biggest improvments. [ January 04, 2005: Message edited by: Ben Souther ]
I'd like to add that when thinking of storing an attribute in one of the scopes (i.e. request, session, context or page scopes) one needs to take into the count how long the attribute is to live.
Eg, when storing a bean in order to pass it JSP so that it can extract required values from this bean and create html, one would store such bean in a request because the web app does not need to know about this bean once it serviced the request (i.e. created an html and sent to the client).
On the other hand, when storing a bean that holds information collected over several pages (eg, shopping cart application), one could store such bean in a session.