cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Use of static keyword in iRules

Akshay_SK
Nimbostratus
Nimbostratus

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 :

  1. Are static variables implementation same across all irules?
  2. Or are static variables same across multiple instances of same iRule?
3 REPLIES 3

James_Thomson
F5 Employee
F5 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

Yes I am referencing it as $static::windowSec. Will this trigger a CMP demonition?

Simon_Blakely
F5 Employee
F5 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 :

  1. Are static variables implementation same across all irules?
  2. 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.