This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

size of objects in session  RSS feed

 
kee chee
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to calculate the size of objects in the session
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since only references to objects are stored in the session, not the objects themselves, the size would be the number of objects times the size of a reference (which in Java is non-deterministic).
[ December 08, 2007: Message edited by: Bear Bibeault ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're trying to figure out how much memory each user session uses and how many users you can support or how much memory you need, Java is not very helpful. Primitive types are pretty straightforward but there's no API or helpful formula to figure out how much memory object x uses.

The common good advice is to minimize what you put in a session, but it's hard to know how much effort you should put into eliminating some particular bit of data.

All that said, the Java Specialist Newsletter has done some work on estimating object sizes. Dig back through the archives and see if that can help you out.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that a servlet container is allowed to manage sessions by serializing them to some other storage, such as disk files. Therefore the total number of sessions in memory may be considerably less than the number of "live" sessions. Thats why you should ensure that you make all custom objects used in sessions Serializable.

Bill
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!