Forum Discussion
Andy_Herrman_22
Nimbostratus
Jul 16, 2007Local var performance
Quick performance question. I'm looking back at the iRules I worked on a year ago for our F5 evaluation and noticed something odd. At the top of the iRule the URI and Host values are stored in variables, but later on the iRule looks up the values again.
For example:
when HTTP_REQUEST {
set fulluri [HTTP::uri]
set host [HTTP::host]
if { [HTTP::uri] starts_with "/servletPath" } {
set hcid [findstr [HTTP::uri] "?id=" 4 "&"]
}
}
Now, I vaguely remember this being done because I read that doing [HTTP::uri] was actually faster than doing the variable lookup, but this seems odd to me. Is there any truth to that, or should I change it to just use the variables I declared (and maybe submit my original code to the daily WTF)?
- David_Remington
Employee
You read it here, probably: - Colin_Walker_12Historic F5 AccountThe reason it's faster to us HTTP::uri later on is because this value is already cached. You're not performing another lookup, the data has been cached via TMM, and is available to the iRules interpreter as necessary. So all you're doing is pointing to that value in memory, not performing a lookup.
- Mike_62629
Nimbostratus
Posted By Colin on 07/18/2007 2:50 PM
.[HTTP::cookie xyz]
- Nicolas_Menant
Employee
Hi, - hoolio
Cirrostratus
A quick way to verify whether a command is cached or not is to log the current value, change it and then try to log it again. If the same value is logged the second time, then the command output is cached. This caching seems to only be maintained in the same event in the same priority. I think (almost?) all of the HTTP:: commands are cached. Maybe someone with definitive knowledge could add more detail (Click here)?when HTTP_REQUEST { log local0. "\[HTTP::uri\]: [HTTP::uri]" HTTP::uri "/modified" log local0. "\[HTTP::uri\]: [HTTP::uri]" log local0. "\[HTTP::cookie value test_cookie\]: [HTTP::cookie value test_cookie]" HTTP::cookie test_cookie "modified" log local0. "after modification: \[HTTP::cookie value test_cookie\]: [HTTP::cookie value test_cookie]" } when HTTP_REQUEST priority 501 { log local0. "priority 501 \[HTTP::uri\]: [HTTP::uri]" log local0. "priority 501 \[HTTP::cookie value test_cookie\]: [HTTP::cookie value test_cookie]" }
- Mike_62629
Nimbostratus
Thanks, and Aaron that's a great tip. I didn't think to test like that, though I'm a bit suprized that modification doesn't update the cache. I imagine there could be several who run into that like a brick wall. - hoolio
Cirrostratus
Hi Colin,
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