开发者

Measuring the Size of HttpSession object

Is there a clean and开发者_如何学C easy way to measure it other than programatically measuring the size of each data type (that each object is composed of) stored in session?


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.


There's a SessionSize class here that has a function to return the size of an HttpSession object passed to it, a part of the Java Web Parts lib.


Session content must be Serializable. So serialize it and see the size of the resulting byte array.

It's not equal to the in-memory size, but can be used as a rough representation of it.

P.S. Note that transient fields, if any, will be excluded.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜