Forum Discussion

BaltoStar_12467's avatar
Jun 03, 2013

iRule optimization

My iRule needs to exact-match on host and wild-card match on path.

 

 

when HTTP_REQUEST {

 

switch [string tolower [HTTP::host]] {

 

"internal.mycompany.com" {

 

switch -glob [string tolower [HTTP::path]] {

 

"/api1/*" {

 

 

 

Is this optimized as it is ? Would re-structuring as a single iRule provide further optimization ?

 

 

set $host [string tolower [HTTP::host]]

 

set $path [string tolower [HTTP::path]]

 

set $host-uri = "$host/$path"

 

when HTTP_REQUEST {

 

switch -glob [$host-uri] {

 

"internal.mycompany.com/api1/*" {

 

 

2 Replies

  • i think the 1st one is better.

    1st

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       timing on
    when HTTP_REQUEST {
      switch [string tolower [HTTP::host]] {
        "internal.mycompany.com" {
          switch -glob [string tolower [HTTP::path]] {
            "/api1/*" { }
            "/api2/*" { }
            "/api3/*" { }
          }
        }
      }
    }
    }
    
     ab -n 1000 http://internal.mycompany.com/api3/something
    
    [root@ve10:Active] config  b rule myrule show all
    RULE myrule
    +-> HTTP_REQUEST   1000 total   0 fail   0 abort
        |     Cycles (min, avg, max) = (40248, 54421, 442966)
    
  • 2nd

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       timing on
    when HTTP_REQUEST {
      set host [string tolower [HTTP::host]]
      set path [string tolower [HTTP::path]]
      set host-uri "$host/$path"
      switch -glob $host-uri {
        "internal.mycompany.com/api1/*" { }
        "internal.mycompany.com/api2/*" { }
        "internal.mycompany.com/api3/*" { }
      }
    }
    }
    
     ab -n 1000 http://internal.mycompany.com/api3/something
    
    [root@ve10:Active] config  b rule myrule show all
    RULE myrule
    +-> HTTP_REQUEST   1000 total   0 fail   0 abort
        |     Cycles (min, avg, max) = (34883, 69650, 510200)