Forum Discussion
Use of static keyword in iRules
I had used the static keyword in my iRule some days ago in RULE_INIT event since I wanted certain variables to be globally declared as follows :
when RULE_INIT {
set static::windowSec 60
set static::queryCount 600
}
This use of static keyword caused a massive load on only one of the cores of F5 due to which I had to detach the iRule. Being a newbie I was unable to understand the root cause of this issue. Also I would like to know the following :
- Are static variables implementation same across all irules?
- Or are static variables same across multiple instances of same iRule?
- James_Thomson
Employee
Based on this I think you're setting it correctly. Maybe you're using it in such a way in the irule that makes it "demote CMP".
Check this article out which explains what that means
https://devcentral.f5.com/s/articles/the101-irules-101-variables
Are you referencing it as $static::windowSec
- Akshay_SK
Nimbostratus
Yes I am referencing it as $static::windowSec. Will this trigger a CMP demonition?
- Simon_Blakely
Employee
> This use of static keyword caused a massive load on only one of the cores of F5 due to which I had to detach the iRule. Being a newbie I was unable to understand the root cause of this issue.
This would be due to CMP demotion - If something in the virtual server config or the irule means that there will be issues with multithreading the traffic across multiple tmms (the default), then the virtual will be demoted from CMP and all the traffic will be processed on one core. This can be extremely detrimental to performance.
Just the use of the static:: keyword should not trigger CMP demotion - in fact, it is intended to be a CMP-safe way to share non-changing variables across tmm instances in a safe manner.
There may have been something else within the irule that caused CMP demotion for your irule.
> Also I would like to know the following :
- Are static variables implementation same across all irules?
- Or are static variables same across multiple instances of same iRule?
The static:: namespace is shared across all irules - so every irule will see all the static variables.
If you try to change a static:: variable within an irule, it will only change on the particular tmm, producing inconsistent results.
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