Logging slow connections

The request rule below captures the start time for each request and sets a connection data value called “start” for each request:-

$tm = sys.time();
connection.data.set("start", $tm);

The response rule below tests each response against a threshold, which is currently set to 6 seconds. A log entry is written to the event log for each response that takes longer to complete than the 6 second threshold. Each log entry will show the response time in seconds, the back-end node used and the full URI of the request.

$THRESHOLD = 6; # Response time in (integer) seconds above
# which requests are logged.
$start = connection.data.get("start");
$now = sys.time();
$diff = ($now - $start);
if ( $diff > $THRESHOLD ) {
$uri = http.getRawURL();
$node = connection.getNode();
log.info ("SLOW REQUEST (" . $diff . "s) " . $node . ":" . $uri );
}

The information in the event log will be useful to identify patterns in slow connections. For example, it might be that all log entries relate to RSS connections, indicating that there might be a problem with the RSS content.

Graham Moore [Zeus Systems Engineering] 07 June 2006 Bookmark with del.icio.us Post this article to Digg Post this article to reddit Post this article to Facebook Tweet this article 2 comments  

Comments:

This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.

Comment from: John Horton [Visitor]
This gives the time to first byte but what can you do to capture the time after the last byte.
Permalink 10 March 2008 @ 18:07
Comment from: Graham Moore [Visitor]
To capture the time after the last byte, this should work:-

$THRESHOLD = 1; # Response time in (integer) seconds above
# which requests are logged.

$start = connection.data.get("start");
$now = sys.time();
$diff = ($now - $start);

$uri = http.getRawURL();
$node = connection.getNode();

$body = http.getResponseBody();

$newnow = sys.time();
$toend = ($newnow - $now);

if ( $diff > $THRESHOLD || $toend > $THRESHOLD ) {
$uri = http.getRawURL();
$node = connection.getNode();
log.info ("SLOW REQUEST (" . $diff . "s)(" . $toend . "s) " . $node . ":" . $uri );
}
Permalink 08 May 2009 @ 15:01
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)

Recently...

Other Resources