Forum Discussion
Help with iRule to route by host header to pool
Looks good to me, there is very little to optimize here.
Reading directly from a variable like [HTTP::host] is faster than setting the value in a variable and read that variable after. However, in this case, you are also using the string tolower twice, so not sure if there will be any improvement.
when HTTP_REQUEST {
test_dg is a string data-group where the entries are name:value pairs
name is the requested HTTP host header, value is the associated pool-name
check the requested HTTP host header against entries in data-group
set host [string tolower [HTTP::host]]
if { [class match $host equals test_dg ] } {
if the HTTP host header is in datagroup
send the request to the pool associated with the datagroup entry
pool [class match -value $host equals test_dg ]
} else {
drop the request if the host header is not in datagroup
drop
}
}
Have a look in this link about testing the speed of the iRule.
https://devcentral.f5.com/articles/irules-optimization-101-05-evaluating-irule-performance
If you want to read the full article:
https://devcentral.f5.com/articles/irules-optimization-101-01-if-elseif-and-switch
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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