Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Is my iRule effecient?

So, first off I'm cutting over from version 4 BigIPs newer version 9 BigIPs.

We have a conglomerate of stuff that is all over the board so I'll be using the iRule functionality to keep me somewhat sane
Our sites can be fairly fast moving at times so I'm wondering if my iRules are completely out of whack and will have a performance hit or if they seem reasonable. Can anyone verify that they look okay, or maybe have some suggestions that would make them more efficient? I see that there is an "exclude" list in the caching portion of the profile but this seems to be somewhat unreliable and unpredictable (from my testing anyway) so I'd rather keep everything in iRules at this point.


when HTTP_REQUEST {
set method [HTTP::method]
set host [string tolower [HTTP::host]]
set uri [string tolower [HTTP::uri]]
<snip>
elseif { [matchclass $uri starts_with $::nocache_iis_startswith] or [matchclass $uri contains $::nocache_iis_contains] or [matchclass $uri ends_with $::nocache_iis_endswith] } {
CACHE::disable
log local0.iis.nocache
pool iis_pool
}
elseif { [matchclass $uri starts_with $::cache_iis_startswith] or [matchclass $uri contains $::cache_iis_contains] or [matchclass $uri ends_with $::cache_iis_endswith] } {
CACHE::enable
log local0.iis.cache
pool iis_pool
}
elseif { [matchclass $uri starts_with $::nocache_apache_startswith] or [matchclass $uri contains $::nocache_apache_contains] or [matchclass $uri ends_with $::nocache_apache_endswith] } {
CACHE::disable
log local0.apache.nocache
pool apache_pool
}
elseif { [matchclass $uri starts_with $::cache_apache_startswith] or [matchclass $uri contains $::cache_apache_contains] or [matchclass $uri ends_with $::cache_apache_endswith] } {
CACHE::enable
log local0.apache.cache
pool apache_pool
}
elseif { [matchclass $uri starts_with $::nocache_tomcat_startswith] or [matchclass $uri contains $::nocache_tomcat_contains] or [matchclass $uri ends_with $::nocache_tomcat_endswith] } {
CACHE::disable
log local0.tomcat.nocache
pool tomcat_pool
}
elseif { $uri starts_with "/" } {
CACHE::enable
log local0.tomcat.cache
pool tomcat_pool
}
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
That's a lot of matchclass calls! It's hard to tell if your iRule is optimal without knowing the size and contents of your various data groups. If they are fairly small, you could make a pretty straightforward switch statement with character globbing that would replace all the matchclass calls. If you have hundreds of entries in each class, that might not be a good solution though...

If your classes are fairly small, then you could do something like this with a switch statement that would be a bit speedier.

when HTTP_REQUEST {
set method [HTTP::method]
set host [string tolower [HTTP::host]]
set uri [string tolower [HTTP::uri]]
switch -glob [string tolower [HTTP::uri]] {
"/nocache_iis_start_path_1*" -
"/nocache_iis_start_path_2*" -
"/nocache_iis_start_path_3*" -
"*/nocache_iis_contains_1*" -
"*/nocache_iis_contains_2*" -
"*/nocache_iis_contains_3*" -
"*/nocache_iis_endswith_1" -
"*/nocache_iis_endswith_2" -
"*/nocache_iis_endswith_3" {
CACHE::disable
log local0. iis.nocache
pool iis_pool
}
"/cache_iis_start_path_1*" -
"/cache_iis_start_path_2*" -
"/cache_iis_start_path_3*" -
"*/cache_iis_contains_1*" -
"*/cache_iis_contains_2*" -
"*/cache_iis_contains_3*" -
"*/cache_iis_endswith_1" -
"*/cache_iis_endswith_2" -
"*/cache_iis_endswith_3" {
CACHE::enable
log local0. iis.cache
pool iis_pool
}
}
}


Just continue on with your other sections...

It has been shown that for small data groups, a switch with globbing is faster. The downside is that you have to manage the paths within the iRule and not within separate data groups.

You can always turn on performance timing (see the wiki page for "timing"). When you run traffic through your iRule it will keep track of the number of clock cycles your iRule is using. This can tell you by how much one rule is faster than another.

-Joe
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
It looks like there are some nice advantages to using the "switch" command, I take it that it is not possible to use classes within the switch command.

i.e., or something similar

when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
$::nocache_iis_startswith"*"
"*"$::nocache_iis_contains"*"
"*"$::nocache_iis_endswith {
CACHE::disable
log local0.iis.nocache
pool iis_pool
}


I have anywhere from 5 to 15 different statements in each matchclass so the iRule could get quite long, not unmanageable but long. I can time it to see if the speed is worth sacrificing the management.

Will 'matchclass' take a regex, like [matchclass -regex in $::myexcludes], instead of me having to specify "'starts_with' or 'contains' or 'equals' or 'ends_with'"?
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
FYI, I've changed everything to switch and things seem very reasonable. iRule is a couple pages long but not unmanageable.

Thanks for the suggestion!
0