Tuesday, October 14, 2008

[Java] How to calculate the size of a Session running in Tomcat 6

If you want to be able to see the size of the sessions running in Tomcat, here's how...

Start out by downloading sizeofag.jar and place it in "/lib/". Then add "-javaagent:sizeofag.jar" to the "JAVA_OPTS" environment variable.

Now change the two manager ("/webapps/manager/") jsp files "sessionDetail.jsp" and "sessionsList.jsp" to show the size of the sessions.
Here's an example of the two files in Tomcat 6.

sessionDetail.jsp

sessionsList.jsp

See more info on calculating size of Java HTTP Sessions in this great article.

Update:There seems to be a problem with this approach. The Session size shown by sizeofag.jar is not the actual Session size as the Session contains a number of references to Tomcat and other classes that should not be considered when calculating the Session size. Thus, if you want to use this approach you should look at the difference in the size before and after you add attributes to the Session.

No comments: