Thursday, December 4, 2008

Response Time Tracking Method

The method described below records the server latency only i.e. the time spent in the server after a request is been received and response is sent back. It does not includes the network latency, browser rendering time, etc. The average time can also be printed in the logs (responseTime.log)

ResponseTimeTrackingValve

Apache Tomcat has a component valve which can be used to track down the response time for each page. A Valve element represents a component that will be inserted into the request processing pipeline for the associated Catalina container (Engine, Host, or Context). Each request passes through the enabled valves to the web container and response follows the same path.

The code can be downloaded from https://svn.terracotta.org/repo/forge/projects/exam-perf-test/ResponseTimeTrackingValve

The purpose of Customized Valve (ResponseTimeTrackingValve) is to record the response time for the pages and store the response time statistics for the page. ResponseTimeTrackingValve uses the AccessLogValve code as the base.

ResponseTimeTrackingValve needs to extend org.apache.catalina.valves.ValveBase located in Catalina.jar file. The main method to override is
invoke (org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)
request is passed to next valve by
getNext().invoke(request, response);
The time taken by the server is calculated and saved in a hashtable. Key to the hashtable remains the URI of the request and following stats are being stored in it -

1. Average of all requests
2. Minimum Response Time
3. Maximum Response Time
4. Standard Deviation
5. Total Count of each Page Request made to that server

To calculate standard deviation, the sum of squares of the values is being stored, as we get a new value, square of the value gets added to it. Thus, standard deviation is calculated using these values. Same algo applies to other metrics. The response time for each page is not being stored, only the required metrics are being stored.


Where does valve stand in the HTTP request stack?


Installing the valve

To install the customized valve, deploy it as a JAR file and place it inside the Tomcats server/lib directory.

Register the Valve. Insert the following statement into Tomcat's server.xml file, right before the closing tag:

<Valve classname="org.tc.performance.ResponseTimeTrackingValve" exclude="*.png,*.css,*.js,*.gif,*.ico,/,index.html" prnCount="1000" suffix=".log" prefix="responseTime" lastPageToken="e1s31"/>

The valve keeps track of each and every request that has been made including the js, gifs, css, etc.

  1. We can specify the extensions of the files which we don't want to keep track of in the exclude parameter.
  2. prnCount is set to 1000, i.e. the average time will be printed each 1000 request.
  3. lastPageToken is the executionId of the page at which the users finish exams (this can be checked at the time of JMeter test creation). As in the test created by us, has url "/examinator/flow/takeexam.do?execution=e1s31". This will print each request response time. We can disable it by removing the token.

ResponseTime Tracking Servlet

This servlet serves the current data from the hashtable to the browser in the form of JSON. The data is shown on a web page which updates the tables with new data after specified interval. Servlet provides the method to reset the values in the hashtable. The statistics are shown in a table for each Request URI. This provides more detailed response time page-wise breakup.

2 comments:

Anonymous said... Best Blogger Tips[Reply to comment]Best Blogger Templates

What license is this code released under (if any)?

Unknown said... Best Blogger Tips[Reply to comment]Best Blogger Templates

@Anonymous

Its under http://www.terracotta.org/legal/terracotta-public-license