Forum Discussion
Vincent_Power_9
Nimbostratus
Jul 03, 2007Performance Question in Large iRule
I run into this situation a lot, where an iRule will look like this (our business users want everything behind one hostname/port).
Historically we've been building them like this since it is quick and easy to maintain.
Pool One
if { [HTTP::uri] starts_with "/abc/" } {
pool one
} else if { [HTTP::uri] starts_with "/bcd/" } {
pool one
} else if { [HTTP::uri] starts_with "/cde/" } {
pool one
} else if { [HTTP::uri] starts_with "/def/" } {
pool one
} else if { [HTTP::uri] starts_with "/efg/" } {
pool one
} else if { [HTTP::uri] starts_with "/hij/" } {
pool one
} else if { [HTTP::uri] starts_with "/ijk/" } {
pool one
} else if { [HTTP::uri] starts_with "/jkl/" } {
pool one
}
Pool Two
if { [HTTP::uri] starts_with "/klm/" } {
pool two
} else if { [HTTP::uri] starts_with "/lmn/" } {
pool two
} else if { [HTTP::uri] starts_with "/mno/" } {
pool two
} else if { [HTTP::uri] starts_with "/nop/" } {
pool two
}
Pool Three
if { [HTTP::uri] starts_with "/opq/" } {
pool three
} else if { [HTTP::uri] starts_with "/pqr/" } {
pool three
} else if { [HTTP::uri] starts_with "/qrs/" } {
pool three
} else if { [HTTP::uri] starts_with "/rst/" } {
pool three
}
What would a better way be to make iRules like this more efficient? I don't think "switch -glob" meets my specific need.
3 Replies
- Deb_Allen_18Historic F5 AccountNot sure why switch -glob wouldn't do the trick:
switch -glob [string tolower [HTTP::uri]]{ /abc/* - /bcd/* - ... /jkl/* { pool one } /klm/* - /lmn/* - ... /nop/* { pool two } /opq/* - /pqr/* - ... /rst/* { pool three } }
switch [getfield [string tolower [HTTP::uri]] / 2] { abc - bcd - ... jkl { pool one } klm - lmn - ... nop { pool two } opq - pqr - ... rst { pool three } }
iRule snip:class VirtualHosts { abc one bcd one ... rst three }
set myPool [findclass [getfield [string tolower [HTTP::uri]] / 2] $::VirtualHosts " "] if {$myPool != "" }{ pool $myPool }
- Vincent_Power_9
Nimbostratus
Alright, I guess I didn't understand the switch command well enough. - Deb_Allen_18Historic F5 AccountNo problem, happy to help.
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