# iRule optimization

**URL:** <https://community.f5.com/t/irule-optimization/42550>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [September 11, 2006, 6:37pm UTC](https://community.f5.com/t/irule-optimization/42550 "2006-09-11T18:37:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Geddes\_295](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@John\_Geddes\_295](https://community.f5.com/u/John_Geddes_295)\
**Post date:** [September 11, 2006, 6:37pm UTC](https://community.f5.com/t/irule-optimization/42550/1 "2006-09-11T18:37:36Z")

</div>

The iRule below was created by a former employee, and after reading the manual and some posts in this forum, I read that this rule is not really optimized, and will still be processed (due to the HTTP\_REQUEST) for every consecutive hit after the first one, including images.

I basically want to rule out bot traffic to another pool, then let the rest come in to the primary pool. Any suggestions

when HTTP\_REQUEST { if { [matchclass [IP::remote\_addr] equals $::blacklisted\_clients] } { pool Bots} elseif { [matchclass [HTTP::header User-Agent] contains $::blacklisted\_useragents] } { pool Bots } elseif { [string first -nocase “bot” [HTTP::header User-Agent]] \>= 0 } { pool Bots } else { pool MainPool } }

---

<div class="post-metadata">

**Author:** ![Deb\_Allen\_18](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Deb\_Allen\_18](https://community.f5.com/u/Deb_Allen_18)\
**Post date:** [September 11, 2006, 7:04pm UTC](https://community.f5.com/t/irule-optimization/42550/2 "2006-09-11T19:04:43Z")

</div>

It seems this rule will accomplish your goal by filtering off 3 suspicious groups of traffic while allowing other traffic through to the main pool.

Each request coming to the virtual server where the iRule is applied will be evaluated within the HTTP\_REQUEST event before the iRule can determine where to send the request.

You could optimize slightly by catching the IP address match when the client first connects:

```tcl
when CLIENT_ACCEPTED {
  if { [matchclass [IP::remote_addr] equals $::blacklisted_clients] } { 
    pool Bots
    event disable all
  }
 }
 when HTTP_REQUEST {
  if { [matchclass [HTTP::header User-Agent] contains $::blacklisted_useragents] } { 
    pool Bots
  } elseif { [string first -nocase "bot" [HTTP::header User-Agent]] >= 0 } { 
    pool Bots
  } else { 
    pool MainPool
  }
 }

```

HTH

/deb
