How to measure HttpSession size accurately and efficiently

Is there a simple, efficient, and accurate way to measure session size in a servlet-based application? Preferably, the measurement method should be independent of the application server / container.
I tried to measure the size of the session using the lambda probe on Tomcat 7, but it seemed to me that I was inaccurate, inaccurate, slow and buggy. I think there should be a simple easy way, because almost every decent Java EE developer cares about session size.

I want to emphasize the test of my application and measure the bloat of the session.

+4
source share
1 answer

Here's how we calculate this session size in the application itself:

totalSize = 0; totalSerializable = 0; totalNumber = 0; HttpSession session = getSession(); Enumeration<String> attrs = session.getAttributeNames(); while (attrs.hasMoreElements()) { String attr = attrs.nextElement(); SessionObject sObj = new SessionObject(attr, session.getAttribute(attr)); sessionAttributes.add(sObj); if (sObj.isSerializable()) { totalSize += sObj.getSize(); totalSerializable++; } totalNumber++; } 
0
source

All Articles