Forum Discussion

Akshay_SK's avatar
Akshay_SK
Icon for Nimbostratus rankNimbostratus
Feb 17, 2020

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 :

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

3 Replies

  • > 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.

    • Akshay_SK's avatar
      Akshay_SK
      Icon for Nimbostratus rankNimbostratus

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