How to know what all objects are stored in session at any point of time


You might want to know at any point of time that how many objects are stored in session along with their size. This would be most useful when you are analyzing application performance or working on performance tuning area.
This would also be useful in debugging when your application is throwing java.io.NotSerializableException.


There is a servlet called com.ibm.ws.webcontainer.httpsession.SessionInspectServlet that ships with WAS located in com.ibm.ws.webcontainer.jar. This jar is placed under <WPS_ROOT>/AppServer/plugins/.   
SessionInspectorServlet  can be used to list down what all objects are stored in session along with size of the objects.



In order to use SessionInspectServlet, you would need to enable “Serving servlets by class name”, you can set this value in the ibm-web-ext.xmi
By default this value is true, you can see sample ibm-web-ext.xmi file below and can see that serveServletsByClassnameEnabled value is true.

<?xml version="1.0" encoding="UTF-8"?>
<webappext:WebAppExtension xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappext="webappext.xmi" xmi:id="WebAppExtension_1320397630802" reloadInterval="3" reloadingEnabled="true" additionalClassPath="" fileServingEnabled="true" directoryBrowsingEnabled="false" serveServletsByClassnameEnabled="true">
  <webApp href="WEB-INF/web.xml#WebApp_ID"/>
</webappext:WebAppExtension>


To list down session objects stored in session, you would required to hit below URL
 
http://localhost:10039/wps/<context-root>/SessionInspector/servlet/com.ibm.ws.webcontainer.httpsession.SessionInspectServlet

here, context root would be context root of your application. You can specify this while installing your WAR through portal admin console OR you can also find out this value inside application.xml located under <WPS_ROOT>/wp_profile/installedApps/<NODE>/<EAR NAME>/META-INF/
 
You would see list of your session objects and their size as shown in the screen shot.


No comments: