# irule performance question

**URL:** <https://community.f5.com/t/irule-performance-question/32129>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [November 15, 2011, 3:16pm UTC](https://community.f5.com/t/irule-performance-question/32129 "2011-11-15T15:16:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romel\_77740](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@Romel\_77740](https://community.f5.com/u/Romel_77740)\
**Post date:** [November 15, 2011, 3:16pm UTC](https://community.f5.com/t/irule-performance-question/32129/1 "2011-11-15T15:16:38Z")

</div>

Is it better to have 10 different irules applied to the same virtual server that do similar thing or is it better to combine in one script? Or either way doesn’t matter? Eg pseudo scripts with 26 irules:::

irule A: if (src ip 10.1.1.1) then pool A

irule B: if (src ip 10.1.1.2) then pool B

..

irule Z: if (src ip 10.1.1.26) then pool Z

~~Or is it better to do~~ :

just 1 irule:: if (src ip 10.1.1.1) then pool A else if src ip 10.1.1.2) then pool B… else pool Z ~~(or do a case statement for this in a single irule)~~

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [November 15, 2011, 3:47pm UTC](https://community.f5.com/t/irule-performance-question/32129/2 "2011-11-15T15:47:31Z")

</div>

if we code the irule something like this, will a number of irule reduce?

```tcl
[root@ve1023:Active] config b virtual bar list
virtual bar {
   snat automap
   pool foo
   destination 172.28.65.152:http
   ip protocol tcp
   rules myrule
}
[root@ve1023:Active] config b rule myrule list
rule myrule {
   when CLIENT_ACCEPTED {
        if {[class match -- [IP::client_addr] equals xyz]} {
                log local0. "client is [IP::client_addr]:[TCP::client_port], action is [class match -value [IP::client_addr] equals xyz]"
        }
}
}
[root@ve1023:Active] config b class xyz list
class xyz {
   {
      network 172.28.19.0/24 { "action2" }
      host 192.168.204.7 { "action1" }
   }
}

[root@ve1023:Active] config tail -f /var/log/ltm
Nov 15 08:48:30 local/tmm info tmm[4766]: Rule myrule : client is 192.168.204.7:54379, action is action1
Nov 15 08:48:38 local/tmm info tmm[4766]: Rule myrule : client is 172.28.19.253:59039, action is action2

```

---

<div class="post-metadata">

**Author:** ![Michael\_Yates](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@Michael\_Yates](https://community.f5.com/u/Michael_Yates)\
**Post date:** [November 16, 2011, 7:05pm UTC](https://community.f5.com/t/irule-performance-question/32129/3 "2011-11-16T19:05:43Z")

</div>

Hi Romel,

If multiple iRules are applied to a Virtual Server the iRules are “combined” at runtime by the [iRule Priority](http://devcentral.f5.com/wiki/iRules.priority.ashx) assigned to the iRule.

If no priority is set then the iRules per event are added in the order that the iRules are applied to the Virtual Server.

iRules with no Priority Applied -

iRule 1:

when HTTP\_REQUEST {

do something…

}

iRule 2:

when HTTP\_REQUEST {

do something else…

}

They would be processed as:

when HTTP\_REQUEST {

do something…

do something else…

}

The same holds true for other events. So it is a matter of what works best for you.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Hamish](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hamish](https://community.f5.com/u/Hamish)\
**Post date:** [November 16, 2011, 9:18pm UTC](https://community.f5.com/t/irule-performance-question/32129/4 "2011-11-16T21:18:31Z")

</div>

Also, when the iRUles are combined, the namespace is shared. So a variable called $MyVar in iRule1 will be the SAME variable in iRule2…

e.g. If you init to 1 in CLIENT\_CONNECT in both iRule1, then to 2 in CLIENT\_CONNECT in iRule2, when HTTP\_REQUEST fires in iRUle 1, the variable will have the value of 2… Not 1…

H

---

<div class="post-metadata">

**Author:** ![Michael\_Yates](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@Michael\_Yates](https://community.f5.com/u/Michael_Yates)\
**Post date:** [November 16, 2011, 10:18pm UTC](https://community.f5.com/t/irule-performance-question/32129/5 "2011-11-16T22:18:41Z")

</div>

Excellent Point Hamish.

I have seen instances where the first iRule contains nothing but the variable settings used in all of the other attached iRules (so that if there was a Variable Change it only had to be made in a single iRule instead of every iRule attached to a Virtual Server.
