Forum Discussion

Sekou_Page_1118's avatar
Sekou_Page_1118
Icon for Nimbostratus rankNimbostratus
Apr 26, 2006

HTTP_Request URI performance question

I would like to know which type of request is more efficient as iRules get longer. We have a need to direct clients to specific pools of web servers depending on the URL they used. However, we have literally hundreds of URLS, which means very long iRules. We are looking into changing this (I have another post on this for suggestions).

Anyway, here are the two types of rules we can use... Keep in mind that the actual rules would be for several hundred URLS. So if anyone out there knows of a performance difference between these two types of rules, please let me know. Thanks!

Example1:


when HTTP_REQUEST {
  if { [HTTP::uri] contains "/c1/"} {
     pool WEB02
  }
  elseif { [HTTP::uri] contains "/c2/"} {
     pool WEB02
  }
  elseif { [HTTP::uri] contains "/d1/"} {
     pool WEB01
  }
  elseif { [HTTP::uri] contains "/d2/"} {
     pool WEB01
  }
} else {
     pool WEB03
 }
}

Example2:


when HTTP_REQUEST {
  if { [HTTP::uri] contains "/c1/" or [HTTP::uri] contains "/c2/"} {
     pool WEB02
  }
  elseif { [HTTP::uri] contains "/d1/" or [HTTP::uri] contains "/d2/"} {
     pool WEB01
  }
  else {
     pool WEB03
 }
}

2 Replies

  • Try this:

    
    class myURI {
      "c1 WEB02"
      "c2 WEB02"
      "d1 WEB01"
      "d2 WEB01"
    }
    when HTTP_REQUEST {
      set myPool [findclass [string tolower [HTTP::uri]] $::myURI " "]
      if { info exists $MyPool } {
        pool $MyPool
         Next 3 lines only necessary 
         if /[cd][12]/ needs to be trimmed from the URI
        set preURI [string trimleft [HTTP::uri] "/"]
        set finalURI [string trimleft $preURI "/"]
        HTTP::uri "/$finalURI"
      }
    }

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    You should also consider using a Tcl switch statement, which also has pretty good performance (much better than the if-then-else approach).

     

     

    There are also ways of measuring the performance of a particular rule. Search the forum for "timing on" and you should find some help about how to measure the average cycles a rule takes.