Measuring the Size of HttpSession object

Langali picture Langali · Oct 27, 2009 · Viewed 13.7k times · Source

Is there a clean and easy way to measure it other than programatically measuring the size of each data type (that each object is composed of) stored in session?

Answer

Vineet Reynolds picture Vineet Reynolds · Oct 28, 2009

MessAdmin allows you to compute the HttpSession size although it is unclear on how it calculates the size of transient objects.

It appears that getting an approximate size of the HttpSession object is an exercise in futility in production, and one is likely to get a more accurate size for a controlled environment.

One thing to note is that size of the serialized session object is bound to inaccurate due to changes in character encoding - Strings in Java are stored in the UTF-16 format whereas the output stream could be in a different encoding. More details on why calculating the size of an object in Java is a problem, can be found in this JavaWorld article.