It has been 3 weeks since I started developing jobBoard, a web application for online recruitment/jobs database. Time now for some performance numbers!
How do you accurately measure the processing time it takes for each request on your web application? An example,
- User clicks on a link on a page
- Request goes through a couple of servlet filters, e.g acegi, sitemesh filters
- The corresponding controllers/actions process the request, calls DAOs
- DAOs/ORMs queries the native database system and returns results to controller
- Controller gets results from DAOs and puts request attributes to JSP/Velocity etc. page template
- Page served up by the web server.
There's a good article on servlet filters with an example just to do the above. However, I needed to present the process time on the requested web page but once the filter chain is executed, I can't put the execution time as a request attribute to be used by the page template. But here's a neat trick.
Put the 'before' time into the request attribute,
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { long before = System.currentTimeMillis(); request.setAttribute("before", before); // add here chain.doFilter(request, response); long after = System.currentTimeMillis();
Then in my JSP page,
Request processed in <%= System.currentTimeMillis() - Long.valueOf(pageContext.getRequest().getAttribute("before").toString()) %> ms
The values are the same as when using the example TimeFilter as it is
.