File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Session Size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Session Size" Watch "Session Size" New topic
Author

Session Size

Vinod Kumar
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
Hi,

My domain object model says a User can have 0 or many books. So I designed a User object containing object array of Book object. Each user can have up to a maximum of 250 books. He should be able to see any of the book details any time when he is logged in to the system. Since User object has to be in session , is it a good idea to have 250 book objects inside User objects or have a String[] of bookId and retrieve details (datbase call) when User requests to see the book detail.? Will the session size affect the performance if say 10 users log in and it might go up to 2500 objects in server memory (different sessions).

Please suggest other ideas to implement this.

Thanks,
VINU
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518

So I designed a User object containing object array of Book object. Each user can have up to a maximum of 250 books.



Why not use an ArrayList object instead of an object array? ArrayLists are resizable but arrays are not. This would eliminate the arbitrary limit of 250 books.


is it a good idea to have 250 book objects inside User objects or have a String[] of bookId and retrieve details (datbase call) when User requests to see the book detail.?


Have you tried retrieving the details on each request? Is it fast? I think you'll find it faster than you think. I find programmers try to optimize too early which results in slow and hard-to-maintain code.

This may sound counter intuitive until you've experienced it first hand, but the chances are that any bottlenecks you think you've identified at coding time aren't really the slowest part of your code.

It's better to design your application using proper OO techniques, code, do performance testing and then optimize the code to eliminate the identified bottlenecks.

In this case, it's possible that retrieving book data will not be a bottleneck. If after testing you find that it is, I'll be simple to add a few lines to cache the object or query results.


Will the session size affect the performance if say 10 users log in and it might go up to 2500 objects in server memory (different sessions).


Storing a large number of objects in Session objects can use a large amount of memory and impact performance. This is an example of where premature optimization can cause problems. You could cache the book data to solve a non-existent problem and in the process cause a different problem.

I recommend not caching anything for now. Just pull the data directly from the database. Once you've written the application, run the application and monitor it using a profiler (hprof for example). If you determine too much time is spent retrieving data, you can implement some sort of optimization (query cache, object cache, etc.)
[ August 11, 2006: Message edited by: Scott Johnson ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Session Size
 
Similar Threads
How to track all sessions?
avoiding initialization of hibernate objects
****ServletContext and WebApplication confusion****
JspWriter in tomcat
Spring DAO Session refresh