Forum Discussion
Mark_Moseley
Nimbostratus
Nov 14, 2005Predefining variables and how iRules work
Hi. This is a two-parter, neither of which I can find answers for but might be using the wrong search terms (in which case, my apologies).
1) Is it possible to pre-define variables in iRules? Just declaring them outside of a when {} context doesn't seem to work:
Gives this error:
line 1: [command is not valid in the current scope] [set hi hi]
I've got a hash map I'd like to use that could be upwards of a few hundred entries, so it'd be nice to not have to initialize the variable over and over. Is there another way to do this?
2) Related to 1, I'm curious how iRules are stored in memory. Is the script compiled to some sort of byte-code at first run and then run from byte-code (or something similar), or is run through the BigIP's implementation of a tcl interpreter from scratch each time? The upshot is I'm wondering if there are optimizations that the BigIP already does that would make it not as necessary for me to worry about 1.]
Thanks!
- JRahm
Admin
You can build string or address classes, and they can be stored in the bigip.conf file, or externally in the profile_base.conf file. See: - As citizen_elah mentioned, in most cases you can create data groups (string, address, etc). As long as the list is static, then this should work out for you. All code must exist within an event construct.
when RULE_INIT { set ::global_var "some value" }
- Mark_Moseley
Nimbostratus
1) Excellent, this is perfect. I hadn't looked at data groups for this, since they don't appear to allow for non-scalar datatypes. Am I wrong? I'm using a couple of arrays with names (extracted from the hostname) as keys, which looks to be beyond what you can put into a data group. But being able to put it into the INIT event is perfect. There's no terrible overhead there? The actual data is pretty small, probably no more than a 10K altogether. There's just a bunch of them. - unRuleY_95363Historic F5 AccountMany of our commands cache the result to improve performance for repeated calls. The performance of caching the result is similar to using a variable but it doesn't have the overhead of having to allocate a context frame to hold the variable.
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