Performance monitoring of portlet

One of the common requirement that i hear is how do i monitor performance of my portlets and get some useful information when the portlet is misbehaving. I used the concept of Global Filters to create a filter that will monitor all your portlets (render, resource, action and Event phase) and write a message in the log if one of the method takes more than the threshold time. You can download the performance filter code from here

This is how one of the doFilter() method of PerformanceFilter looks like

public void doFilter(RenderRequest request, RenderResponse response,FilterChain filterChain)
throws IOException, PortletException {
long beforeTime = System.currentTimeMillis();
filterChain.doFilter(request, response);
long afterTime = System.currentTimeMillis();
long executionTime = (afterTime - beforeTime)/100;
System.out.println("Time for execution " + executionTime);
if(executionTime > debugThreshold){
Map portletInfoMap = getCurrentPortletInfo(request.getWindowID(),
(ServletRequest)request, (ServletResponse)response);
portletInfoMap.put("PORTLET_METHOD", "render");
portletInfoMap.put("PORTLET_EXECUTIONTIME", Long.toString(executionTime));
printDebugInformation(request, response,portletInfoMap);
}
}


In the doFilter() method i am taking the time before and after i forwarded control up the chain and using that time to calculate execution time. If the execution time is more than threshold then i am printing debug information. In my simple filter i am only printing request parameter, but you can print all the information that you want ex. portlet prefrences, portlet session information...

Since this is a Global Filter i have a plugin.xml file which looks like this

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin id="com.webspherenotes.filter.performancemonitorfilter" name="WS_Server"
provider-name="IBM" version="2.0.0">
<extension point="com.ibm.ws.portletcontainer.portlet-filter-config">
<portlet-filter-config
class-name="com.webspherenotes.portlet.PerformanceMonitorFilter" order="99">
<description> Performance Filter, order = 102 </description>
<lifecycle>RENDER_PHASE</lifecycle>
<lifecycle>RESOURCE_PHASE</lifecycle>
<lifecycle>ACTION_PHASE</lifecycle>
<lifecycle>EVENT_PHASE</lifecycle>
<init-param>
<name>DEBUG_THRESHOLD</name>
<value>1</value>
</init-param>

</portlet-filter-config>
</extension>
</plugin>


I am reading value of DEBUG_THRESHOLD input parameter from plugin.xml and using it to decide when should i generate debug log. In my case if the portlet takes more than 1 second to respond then i am generating log. This is how a sample log looks like



****Problematic portlet found ****
Page -> wps.LoginPorltet Name -> wps.p.Login Method -> render Took 7

1 comment:

  1. Hi

    These days you are mostly writing for developers. I'm interested from Administration point of view. Your earlier posts were concentrated a lot on Admin but these days almost no posts.

    Srinivas

    ReplyDelete