• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialised session size

 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If I serialise a http session to obtain the size in bytes how accurate is it? Is the true size of the session in the app server likely to be much different to the size seen when serialised?
Cheers,
Steve
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The size of the serialized object should be indicative of the in-memory object, but note that if there are a lot of Strings in the session, the memory will be taking 2 bytes per character.
Bill
 
Erick Jones
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the how to determine the size of your persistent http session. Place this code in the doGet/doPost:
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream stream = new ObjectOutputStream(out);
stream.writeObject(request.getSession());
stream.flush();
System.out.println("Total Size: " + out.size + "bytes");
Erick
 
Erick Jones
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may have misunderstood the question. Are you trying to figure out the peristent size, or the in-memory size? They are not the same. The persistent size of an object is much larger than the memory it consumes.
My previous post assumes you are interested in the persistent size. If you want to know the in memory size it is not quite that simple, but here is an article that I found that will allow you to figure it out.
http://www.webgain.com/communities/developers/resources/articles/newsletter_1.html
Cheers
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We've been experiencing Out of Memory errors with Websphere 4.0 and I am trying to establish the size of the session at various points in the application - so I guess I'm interested in the in memory session size - I was hoping that the serialised session size will be indicative of the in memory size but it appears not. I'll take a look at the article you suggested.
Thanks for the help,
Steve
 
Stuart Bell
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this is an old topic, but the link to the article cannot be found now. Does anyone have any information on how to calculate the in-memory session size?

Thanks.


Stuart
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't that easy to do because several sessions could hold references to the same object.

One approach would be to use a profiler such as JProbe, or Optimizeit and measure the overall memory footprint as sessions are added.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic