aspose file tools*
The moose likes Servlets and the fly likes Serialised session size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Serialised session size" Watch "Serialised session size" New topic
Author

Serialised session size

Steve Granton
Ranch Hand

Joined: Jan 13, 2002
Posts: 200
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

Joined: Mar 22, 2000
Posts: 12825
    
    5
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

Joined: Jun 17, 2002
Posts: 38
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

Joined: Jun 17, 2002
Posts: 38
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

Joined: Jan 13, 2002
Posts: 200
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

Joined: Sep 17, 2004
Posts: 22
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


SCJP (Java 2)<br />SCJD<br />SCWCD
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialised session size