Forum Discussion

Dayton_Gray_103's avatar
Dayton_Gray_103
Icon for Nimbostratus rankNimbostratus
Aug 21, 2006

Help with optimization of this iRule

I have been asked by F5 to post this iRule to see if there are any ways to optimize it as to lower the total CPU usage on the machine. This rule seems pretty straight-forward, but I'm open to suggestions.

 

 

Thanks in advance!

 

 

 

when HTTP_REQUEST {

 

if { (

 

([HTTP::header User-Agent] matches_regex ".*(\[sS\]lurp|msnbot|\[Ff\]\[Aa\]\[Ss\]\[Tt\]-|/\[Tt\]eoma).*")

 

or ([HTTP::header User-Agent] matches_regex ".*(\[Gg\]ooglebot/).*")

 

)

 

and ([HTTP::header host] eq "www.demodomain.com")

 

} {

 

use pool bots.80

 

}

 

else {

 

use pool demo_192.168.1.195.80

 

}

 

}

3 Replies

  • I would build a class with all the various incarnations. In fact, there is a great example here on DevCentral for your purposes:

     

     

    http://devcentral.f5.com/Default.aspx?tabid=29&ArticleType=ArticleView&ArticleID=40&PageID=47 Click here

     

     

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Depending on whether or not you actually want case insensitive matches, the switch statement is probably your best bet. Also, avoiding any variables will also help get the absolute best performance from the rule.

    Here are two examples, the first one with case sensitivity and the second one without:
    when HTTP_REQUEST {
       pool demo_192.168.1.195.80
       if { [HTTP::host] eq "www.demodomain.com" } {
          switch -glob [HTTP::header User-Agent] {
             *[sS]lurp* -
             *msnbot* -
             *[Ff][Aa][Ss][Tt]-* -
             *[Tt]eoma* -
             *[Gg]ooglebot* {
                   pool bots.80   Override to new pool
                }
             default {
                   pool demo_192.168.1.195.80
                }
          }
       } else {
          pool demo_192.168.1.195.80
       }
    }
    when HTTP_REQUEST {
       pool demo_192.168.1.195.80
       if { [HTTP::host] eq "www.demodomain.com" } {
          switch -glob -nocase [HTTP::header User-Agent] {
             *slurp* -
             *msnbot* -
             *fast-* -
             *teoma* -
             *googlebot* {
                   pool bots.80   Override to new pool
                }
             default {
                   pool demo_192.168.1.195.80
                }
          }
       } else {
          pool demo_192.168.1.195.80
       }
    }

  • I was able to use Joe's rule and it works great!

     

     

    I also tried removing the variable with unRuleY's suggestion, but it doesn't seem to be working. First off the -nocase switch isn't valid (at least I get errors) and that rule always seems to default to the non-bot pool.

     

     

    Any suggestions on how to get rid of the variables? I agree with unRuleY that it would probably speed things up even more.

     

     

    Thanks!