# Irule expaination

**URL:** <https://community.f5.com/t/irule-expaination/26846>\
**Category:** Technical Forums\
**Tags:** irules, application-delivery\
**Created:** [September 21, 2016, 1:47am UTC](https://community.f5.com/t/irule-expaination/26846 "2016-09-21T01:47:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KT\_271103](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@KT\_271103](https://community.f5.com/u/KT_271103)\
**Post date:** [September 21, 2016, 1:47am UTC](https://community.f5.com/t/irule-expaination/26846/1 "2016-09-21T01:47:44Z")

</div>

Hi,

Can anyone explain below irule code

when HTTP\_REQUEST { set pool\_nm “web\_8080\_” set key [expr {[crc32 [substr [HTTP::uri] 0 “?”]] % 3}] append pool\_nm $key if { [active\_members “$pool\_nm”] } { pool “$pool\_nm” } else { pool web\_proxy } }

---

<div class="post-metadata">

**Author:** ![Vijay\_E](https://avatars.discourse-cdn.com/v4/letter/v/4bbf92/32.png) [@Vijay\_E](https://community.f5.com/u/Vijay_E)\
**Post date:** [September 21, 2016, 2:52am UTC](https://community.f5.com/t/irule-expaination/26846/2 "2016-09-21T02:52:37Z")

</div>

**Gist:**

You should be having multiple pools that start with “web\_8080\_{some-value-here}”. Traffic is sent to the pool identified by “web\_8080\_{some-value-here}” if there are available members and if not, to the pool: web\_proxy

**A bit more detail:**

[substr [HTTP::uri] 0 “?”] - if you have a string like this in the URI:

```tcl
/index.jsp?user=test&login=check

```

-

```tcl
/index.jsp

```

will be the answer and this will be subjected to [crc32](https://devcentral.f5.com/wiki/iRules.crc32.ashx) and then the remainder of the value when divided by 3 is used as “key” which is then used as “{some-value-here}” in the pool name as noted in the 1st line of this comment.

```tcl
when HTTP_REQUEST { 
set pool_nm "web_8080_" 
set key [expr {[crc32 [substr [HTTP::uri] 0 "?"]] % 3}] 
append pool_nm $key 
if { [active_members "$pool_nm"] } { 
pool "$pool_nm" 
} else { pool web_proxy 
} 
}

```

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [September 21, 2016, 8:19am UTC](https://community.f5.com/t/irule-expaination/26846/3 "2016-09-21T08:19:31Z")

</div>

Hi KT,

the provided iRule provides a load balancing decission for your Web Proxy Servers based on a Euclidean division aka. Modulo operation on a CRC32 checksum of an URI value.

The line…

```tcl
set key [expr {[crc32 [substr [HTTP::uri] 0 "?"]] % 3}]

```

… is passing the requested URI (in the case of HTTP Web Proxy Traffic it will be a full URL like [http://www.domain.de/folder/file.ext](http://www.domain.de/folder/file.ext) or for HTTPS it will be just [www.domain.de:443](http://www.domain.de:443)) to a CRC32 function, which will result in a random but reproducable 32bit value for each given URI. The 32bit value is then passed to a Modulo of 3 calculation resulting in an $key value of either 0, 1, or 2.

The lines…

```tcl
set pool_nm "web_8080_" 
append pool_nm $key

```

… will contrust a pool name based on a fixed string and the previously calculated number (results are either web\_8080\_0, web\_8080\_1, web\_8080\_2 or web\_8080\_3).

The lines…

```tcl
if { [active_members "$pool_nm"] } { 
    pool "$pool_nm" 
} else { 
    pool web_proxy
}

```

… will then check the availability of the the constructed pool name and if it has online members, it will be selected. If the contrusted pool doesn’t have online members, the default pool “web\_proxy” will be selected.

Alternative Syntax:

The provided iRule is somewhat outdated. It can now safely be replace with a rather simple…

```tcl
when HTTP_REQUEST {
    pool web_proxy
    persist carp [URI::path [HTTP::path]]
}

```

Recommendation:

You have to keep in mind that a modulo(CRC32(HTTP::uri)) and also CARP Load Balancing decission does not work well for HTTP Proxy Traffic. Since it would require a OneConnect Profile or a manual LB::detach on every single request to allow subsequent LB decissions on a single TCP connection. This requirement will unfortunately break any “Session-Based-Authentication” (aka. NTLM, Kerberos, Negotiate Authentication).

Without OneConnect Profile or a manual LB::detach on every request, just the first HTTP request is getting balanced correctly and subsequent request send over the same Keep-Alive TCP connection will just stick to the initial selected node…

Personally I would rather then use a more traditional LB algorythm with session presistence (e.g. SOURCE\_IP) , to balance the HTTP Proxy Servers. Its far easier to implement, does result in almost the same results and has even less side effects…

Cheers, Kai
