Forum Discussion
Paul_Michals_10
Jan 21, 2011Nimbostratus
"if" verses "elseif" - performance question
Hello F5 DevCentral,
This comming Sunday I am to perform some minor maintenance on some of our existing F5 BIG-IP Virtual Servers when I will be modifing their iRules.
The question I have is: is it beter, from a performance perspective, to use "elseif" statements instead of sequential "if" statements give that there is no default "else" no matter what way the iRule is written?
Here is (with actual information removed) the proposed iRule:
when HTTP_REQUEST {
if { [HTTP::uri] equals "/" } {
HTTP::redirect https://website.company.com/complicated_url
}
if { [matchclass [HTTP::uri] starts_with $::list1] } {
if { not [matchclass [IP::client_addr] equals $::internal_network] } {
reject
}
}
if { [matchclass [HTTP::uri] starts_with $::list2] } {
if { not (([matchclass [IP::client_addr] equals $::allowed_addressses])
or ([matchclass [IP::client_addr] equals $::internal_network])) } {
reject
}
}
}
Instead of the three outer "if"s would a set of "if", "elseif", "elseif" statements be faster?
Or are the diffferences insignificant?
Thanks in advance.
- Chris_MillerAltostratusHere's a good article on optimizing iRules which covers if, elseif, and switch. I'd go with elseif here.
- hooleylistCirrostratusIf those three checks are all mutually exclusive, I'd change the iRule so as few of checks are performed as possible. ie, if it's a request for / and you don't need to check for the IP addresses, either chain the checks in an if/elseif/elseif/else chain or use the return command to exit that iRule event in that iRule.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects