Forum Discussion

ingard's avatar
ingard
Icon for Nimbostratus rankNimbostratus
Sep 11, 2013

irule optimizing

Hey guys. I'm trying to improve the following irule. Any help is appreciated!

when CLIENT_ACCEPTED {
   when client_accepted
}
when HTTP_REQUEST priority 999 {
   Save request variables that are not accessible in HTTP_RESPONSE, like the URI, request method, etc
  set req_start [clock clicks -milliseconds]
  set cs_username [HTTP::username]
  set cs_uri_stem [HTTP::path]
  set cs_uri_query [HTTP::query]
  set cs_bytes [HTTP::header Content-Length]
  set user_agent [HTTP::header User-Agent]
  set cookies [HTTP::header values Cookie]
  set cs_host [HTTP::host]
  set referer [HTTP::header Referer]
  set method [HTTP::method]
  set contentrange [HTTP::header Content-Range]

  set secs [clock seconds] 
  set msec [clock clicks -milliseconds] 
  set base [expr { $secs * 1000 } ] 
  set fract [expr { $msec - $base }] 
  if { $fract >= 1000 } { 
    set diff [expr { $fract / 1000 }] 
    incr secs $diff 
    incr fract [expr { -1000 * $diff }] 
  }
  set trstart [clock format [clock seconds] -format "%d/%m/%Y-%H:%M:%S.$fract %z"] 

  set x_jfs_devicename [HTTP::header X-Jfs-DeviceName]
  set jsize [HTTP::header JSize]
  set jmd5 [HTTP::header JMd5]
}
when HTTP_RESPONSE {
  if { $method equals "POST" } {
    set LEN $cs_bytes
  } else {
    set LEN [HTTP::header Content-Length]
  }

  log 10.0.50.101 local5. "\t\
VER5:$method\t\
TIME:$trstart\t\
IP:[IP::client_addr]\t\
STATUS:[HTTP::status]\t\
LEN:$LEN\t\
CR:$contentrange\t\
JSZ:$jsize\t\
JMD:$jmd5\t\
JUST:[HTTP::header JUploadedStatus]\t\
JUSZ:[HTTP::header JUploadedSize]\t\
SPENT:[expr {[clock clicks -milliseconds] - $req_start}]\t\
HTTPVER:[HTTP::version]\t\
USER:$cs_username\t\
DEVICE:$x_jfs_devicename\t\
UAGENT:$user_agent\t\
QRY:$cs_uri_query\t\
NODE:[LB::server addr]\t\
$cs_host\t\
$cs_uri_stem\t\
"
}

2 Replies

  • Well, you're setting a lot of variables - some of which you're not using - for what appears to be a monster log statement. Are you just trying to log request and response time?

     

  • There's not much you can do to optimize this if you need to carry all the request info over. There are a couple of things that may help, but minutely.

     

    1. Try to build a partial log line in HTTP_REQUEST so that you only have to create one variable. Creation of variables does incur overhead (albeit a small amount). Then combine this single variable with the calculations and HTTP_RESPOSE specific variables into the log statement.

       

    2. Eliminate the variables that aren't used anywhere. I noticed that the cs_uri_query, cookies, and referer variables are not used elsewhere in the iRule. They can be commented out or removed.

       

    Hope this helps...

     

    -Joe