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

Storing large chunks of data in sessions

 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

I am in need of some suggestions. The app I am working on is going to really strain the DB server, so to lower the load on the server I decided to use sessions. What happens is the servlet gets the data from the server, it is placed into a session and the customer will access the sessions rather than data constantly being requested from the DB. Is this a good method of dealing with the problem ? Or are there better ways of handling such a problem ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do the math.

How many simultaneous users do you expect at peak? How much data are you storing in the session? Multiply.

Can your server handle the memory load?
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Potentially hundreds, the requests can be large too. The best comparison I can give is like an email webapp. When the user wants to view his inbox, it'll load around 50 emails, with title, 20 words from beginning of email, date sent, receipient etc. So its either between memory (session) or hdd (DB). Sessions are quicker than DB too so thats another reason. I don't think hardware will be too much of an issue. We'll get more servers if needed, but considering you can get servers now with 128GB ram.. What do you guys think ?
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will there be any overlap in the data you're considering storing in the session? In other words, will users A and B both end up storing some of the same data in the session? If so, you might consider storing some common data types at the application level.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not that I can think of. Im really stuck between the two. If I do use sessions then its going to be alot more work too.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi shaf,


if the data is need to the everypage of the particular user(example, like user id,role id,name,..),then you can put into session,otherwise dont use session,use request.

commonly, if you dump the datas into session, then it make your application slow according to the number of user
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:otherwise dont use session,use request.
He's talking about caching data so that he doesn't have to hit the DB on every request. Request scope is not an option here.
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While saving the data in the session may work, it's hard to manage, especially if someone just closes their browser without signing off and you have to wait for the session to time out.

Have you looked at various Java caching libraries to reduce the database load? A distributed cache like memcached (search for java memcached) would make things better if you need to run on multiple boxes in the future, too.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider serializing the data to a disk file with a unique name that can be associated with a user.

I do this with on-line test servlets using a custom object to hold everything associated with a test session.

Serialization can be surprisingly fast, and with a little effort you can permit a user to resume a session after losing the connection and re-entering the application. Naturally you will need a mechanism to remove old serialized data to keep from filling up your disk.

Bill
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would stick to what Dave said. I didn't understand your reply shaf to Deve's question. Is your date user specific?? If not then just put the data in the ServletContext and then you can use it everytime you want. Also store the storing time with the data so that you can update it after a fixed period of time...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic