Forum Discussion

Richard_Kim_270's avatar
Richard_Kim_270
Icon for Nimbostratus rankNimbostratus
Jan 17, 2007

Two iRules one Virtual server

Ok so I have a iRule that does the following:

 

 

when CLIENT_ACCEPTED {

 

set default_pool [LB::server pool]

 

}

 

when HTTP_REQUEST {

 

if{ [matchclass [string tolower [HTTP::uri]] starts_with $::Report_strings_matchclass] } {

 

pool custom_pool

 

}

 

else {

 

pool $default_pool

 

}

 

}

 

 

 

this works great but now I have to add another rule where the following strings match exactly then send it to another node otherwise send it to pool custom_pool

 

 

/company/SmartImaging/ProcessRequest.aspx?MethodName=UploadImages

 

/company/SmartImaging/ProcessRequest.aspx?MethodName=SaveImages

 

 

Is it more efficient to seperate these as two seperate iRules and bind them to a virtual server or combine these two into on iRule? Would switch globbing be more efficient for the second requirement or should I stick with Data Groups?

2 Replies

  •  

    This is what I have so far:

     

     

    when CLIENT_ACCEPTED {

     

    set default_pool [LB::server pool]

     

    }

     

    when HTTP_REQUEST {

     

    if{ [matchclass [string tolower [HTTP::uri]] starts_with $::Report_strings_matchclass] } {

     

    pool custom_pool

     

    } elseif { [matchclass [string tolower [HTTP::uri]] contains $::image_strings] } {

     

    pool image_pool

     

    }

     

    else {

     

    pool $default_pool

     

    }

     

    }
  • In my opinion, it's best to make a single purpose iRule unless you have common logic that you need to apply across multiple virtual servers. When you have more than one iRule associated with a single virtual, unless you set the priority, it's you'll likely have to worry about the order the iRules were processed and that could in some situations cause logic errors.

    As for the question about switch globbing -vs- Data Groups, I'll refer to the "How To Write Fast iRules" topic in the wiki

    3) It's better to use "switch" (even with -glob) instead of "matchclass" for comparisons of 100 elements or less (and of course only if your data does not need to be dynamic); (this is likely due to matchclass using md5 as it's hash)

    http://devcentral.f5.com/wiki/default.aspx/iRules/HowToWriteFastRules.html

    Click here

    It really depends on the size of your classes. If they are only a few elements, it will be faster with a swtich. Personally I like switch statements for small (less than 20 or so) comparisons and unless you don't need to change the values in the comparison list regularly. Also, with globbing, you can use wildcard characters to emulate the starts_with, ends_with, contains, and equals operators.

    Your iRule with a switch would look something like this:

     when CLIENT_ACCEPTED {
      set default_pool [LB::server pool]
    }
    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::uri]] {
        "report_string_1*" -
        "report_string_2*" -
        "report_string_n*" {
          pool custom_pool
        }
        "*image_string_1*" -
        "*image_string_2*" -
        "*image_string_n*" {
          pool image_pool
        }
        default {
          pool $default_pool
        }
      }
    }

    Just replace the report_string_n's and image_string_n's with the values from your data groups.

    -Joe