Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session variables.

 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Build your app for clarity, profile it to find the bottlnecks, and optimize where you can make the biggest improvments


Engrave this on a plaque and hang it in every office.
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

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.

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Engrave this on a plaque and hang it in every office.

One couldn't ask for a better compliment than that. Thank you.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Thank you all very much. I got it.


Sawan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic