Forum Discussion
Routing based on URI
I need to create an iRule that would send all traffic to the root of website and and about 100 defined subfolders to the default pool. Any undefined subfolders should go to the market pool.
Here is the iRule that I created.
when HTTP_REQUEST timing on {
set uri [string tolower [HTTP::uri]]
switch -glob $uri {
"/*/*" {
switch -glob $uri {
"/uri1/*" - "/uri2/*" - "/url3/*" - "/uri99/*"
{ }
default {
pool market}
}
}
default {
if {!($uri contains ".") && !($uri eq "/")} {
pool market} else {
pool $default_pool}
}
}
}
}
Here is the problem,
test.com/uri1/ goes to the $default_pool
test.com/market1/ goes to the market pool
but if the url is changed back to test.com/uri1/ the request stays in the market pool but it should have gone to the $default_pool instead.
Oneconnect profile resolves the issue with routing but it breaks some other functionality with the application itself so we would rather not use it.
What am I missing from the iRule to make sure that the request goes to the proper pool?
Also, what can I do to optimize the iRule performance? Currently it's averaging about .065ms per request. Do I need to worry about optimizing or is this a decent performance for this iRule?
Thanks!
13 Replies
- nitass
Employee
Oneconnect profile resolves the issue with routing but it breaks some other functionality with the application itself so we would rather not use it.what is broken? have you tried oneconnect with 32 bit mask (i.e. 255.255.255.255)?
sol5911: Managing connection reuse using OneConnect source mask
http://support.f5.com/kb/en-us/solutions/public/5000/900/sol5911.html
what can I do to optimize the iRule performance?i think class command could have better performance comparing with switch glob. you may enable timing and see how many cpu cycle irule utilizes.
class wiki
https://devcentral.f5.com/wiki/iRules.class.ashx
iRules Optimization 101 - 05 - Evaluating iRule Performance by Deb Allen
https://devcentral.f5.com/tech-tips/articles/irules-optimization-101-05-evaluating-irule-performance.Ufh8nW0-ZQI - Kevin_Stewart
Employee
I would agree that a data group would be a better option. I think you'd be hard pressed to see any significant difference in performance with just 100 subfolder strings, but management of that data would be infinitely easier.
You should also look at the LB::detach command as an alternative to OneConnect:
http://support.f5.com/kb/en-us/solutions/public/7000/900/sol7964.html - Eugene_Reznik_1
Nimbostratus
Oneconnect profile resolves the issue with routing but it breaks some other functionality with the application itself so we would rather not use it. what is broken? have you tried oneconnect with 32 bit mask (i.e. 255.255.255.255)?
When one Connect is enabled our legacy application starts throwing errors.I think I found a way around it by adding ONECONNECT::reuse enable in the begining of the iRule and ONECONNECT::reuse disable before it goes to the market pool.
i think class command could have better performance comparing with switch globWould you be able to provide an example?
Thanks!
- nitass
Employee
Would you be able to provide an example?there is example in class wiki. anyway, this is mine.
e.g.[root@ve10:Active] config b virtual bar list virtual bar { snat automap destination 172.28.19.252:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] if { [class match -- $uri starts_with uri_class] } { pool foo } else { pool qux } } when HTTP_RESPONSE { log local0. "uri: $uri pool: [LB::server pool]" } } [root@ve10:Active] config b class uri_class list class uri_class { { "/uri1/" "/uri2/" "/uri3/" } } [root@ve10:Active] config cat /var/log/ltm Aug 1 11:55:34 local/tmm info tmm[5139]: Rule myrule : uri: /uri1/something pool: foo Aug 1 11:55:45 local/tmm info tmm[5139]: Rule myrule : uri: /somethingelse pool: qux - Eugene_Reznik_1
Nimbostratus
Thanks nitass this is great!
Is there a command or function to tell me if the URI is a subfolder or a root of the site?
- nitass
Employee
Is there a command or function to tell me if the URI is a subfolder or a root of the site?you mean you want to match subfolder (e.g. /*/uri1/*), don't you? if yes, you may have to create different data group and use "contains" instead of "starts_with" in class match command. in the data group, you just put /uri1/ (i.e. no asterisk). - Eugene_Reznik_1
Nimbostratus
I guess what I am after is how to tell if the difference between root and any other subfolder.
Root being / or /default.aspx and subfolder being /uri1/ or /uri1/default.aspx.
I am wondering if I can do something like this:
if {!($root) && !( [class match -- $uri starts_with uri_class] )} { pool foo } else { pool qux }Does that make sense?
- nitass
Employee
Root being / or /default.aspx and subfolder being /uri1/ or /uri1/default.aspx.root (/ or /default.aspx) won't match data group (i.e. it does not start with /uri1/), will it? so, why do you have to differentiate? - Eugene_Reznik_1
Nimbostratus
root (/ or /default.aspx) won't match data group (i.e. it does not start with /uri1/), will it? so, why do you have to differentiate?
That's true, but I need the subfolders that are not defined in the data group to be routed to a different pool.
The other way to look at what I need would be:if {$root || [class match -- $uri starts_with uri_class] } { pool foo } else { pool qux }
So if its root or a defined subfolder it would go to the default pool. And if is a subfolder but not defined in the data group it would go to a different pool. - nitass
Employee
So if its root or a defined subfolder it would go to the default pool. And if is a subfolder but not defined in the data group it would go to a different pool.is it something like this?
e.g.[root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] if { [HTTP::uri] equals "/" or [class match -- $uri starts_with uri_class] } { pool foo } else { pool qux } } when HTTP_RESPONSE { log local0. "uri: $uri pool: [LB::server pool]" } } [root@ve10:Active] config tail -f /var/log/ltm Aug 1 15:17:48 local/tmm info tmm[5139]: Rule myrule : uri: / pool: foo
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