Forum Discussion
smp_86112
Cirrostratus
Jun 24, 2010Optimizing If statement conditions
I see this examples like this all over the place:
when HTTP_REQUEST {
if { [HTTP::host] equals "www.myhost.com" and [HTTP::uri] equals "/myuri" } {
HTTP::redirect https://[HTTP::host][HTTP::...
smp_86112
Cirrostratus
Jun 24, 2010Thank you very much for weighing in on this Joe, adding double-quotes did indeed consolidate the conditions as I expected. Boy, TCL sure isn't Perl is it?
Since you were kind enough to provide valueable insight, I did some analysis. I used ApacheBench Version 2.0.41-dev <$Revision: 1.141 $>. I hit the VIP 100000 times with a maximum number of concurrent connections set to 25. And I ran the test three times for each method. The results are below.
Assuming my methodology is sound, it looks to me like the most effecient in terms of processing cycles is to consolidate the conditions like
if { "[HTTP::host][HTTP::uri]" equals "www.myhost.com/admin" }
The difference is small, but evident. Also, I wonder why the min-cycles is always zero??? I'm running 10.2.0.
timing on
when HTTP_REQUEST {
if { "[HTTP::host][HTTP::uri]" equals "www.myhost.com/admin" } {
HTTP::uri "/new_uri"
}
}
********************
ltm rule-event myrule:HTTP_REQUEST {
aborts 0
avg-cycles 11501
event-type HTTP_REQUEST
failures 0
max-cycles 121243
min-cycles 0
name myrule
priority 500
total-executions 100022
}
ltm rule-event myrule:HTTP_REQUEST {
aborts 0
avg-cycles 11536
event-type HTTP_REQUEST
failures 0
max-cycles 220940
min-cycles 0
name myrule
priority 500
total-executions 100016
}
ltm rule-event myrule:HTTP_REQUEST {
aborts 0
avg-cycles 11366
event-type HTTP_REQUEST
failures 0
max-cycles 105512
min-cycles 0
name myrule
priority 500
total-executions 100015
}
timing on
when HTTP_REQUEST {
if { [HTTP::host] equals "www.myhost.com" and [HTTP::uri] equals "/admin" } {
HTTP::uri "/new_uri"
}
}
********************
ltm rule-event myrule:HTTP_REQUEST {
aborts 0
avg-cycles 11877
event-type HTTP_REQUEST
failures 0
max-cycles 112904
min-cycles 0
name myrule
priority 500
total-executions 100015
}
ltm rule-event myrule:HTTP_REQUEST {
aborts 0
avg-cycles 11751
event-type HTTP_REQUEST
failures 0
max-cycles 148691
min-cycles 0
name myrule
priority 500
total-executions 100018
}
ltm rule-event myrule:HTTP_REQUEST {
aborts 0
avg-cycles 11810
event-type HTTP_REQUEST
failures 0
max-cycles 77001
min-cycles 0
name myrule
priority 500
total-executions 100014
}
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