# HTTP Request Throttle iRule help

**URL:** <https://community.f5.com/t/http-request-throttle-irule-help/40362>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [October 12, 2011, 7:24pm UTC](https://community.f5.com/t/http-request-throttle-irule-help/40362 "2011-10-12T19:24:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MSD\_64294](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@MSD\_64294](https://community.f5.com/u/MSD_64294)\
**Post date:** [October 12, 2011, 7:24pm UTC](https://community.f5.com/t/http-request-throttle-irule-help/40362/1 "2011-10-12T19:24:15Z")

</div>

Can anyone help me to understand how the 2nd iRule in the below page works

> **[DevCentral - An F5 Technical Community](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

will that iRule only work for the ips in RequestLimit\_Whitelist and RequestLimit\_Blacklist data groups, if so how does it work for a new client ip thats not in those 2 data groups.Do we have to update those 2 data groups manually or does the iRule update them dynamically as it gets the new requests.

---

<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:** [October 15, 2011, 10:45am UTC](https://community.f5.com/t/http-request-throttle-irule-help/40362/2 "2011-10-15T10:45:26Z")

</div>

will that iRule only work for the ips in RequestLimit\_Whitelist and RequestLimit\_Blacklist data groupsi don’t think so.

Otherwise, the client will be tracked. If they hit URLs that match the RequestLimit\_URLlist data group then these requests are counted. Once the request rate hits throttle\_activate\_rate, the client is throttled down to throttle\_limit\_rate. Once they slow down enough they will be un-throttled.

---

<div class="post-metadata">

**Author:** ![John\_Alam\_45640](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@John\_Alam\_45640](https://community.f5.com/u/John_Alam_45640)\
**Post date:** [October 15, 2011, 2:09pm UTC](https://community.f5.com/t/http-request-throttle-irule-help/40362/3 "2011-10-15T14:09:54Z")

</div>

In reference to the second irule at this link: [http://devcentral.f5.com/wiki/iRules.HTTPRequestThrottle.ashx](http://devcentral.f5.com/wiki/iRules.HTTPRequestThrottle.ashx)

IPs in the white list are never throttled.

IPs in the black list are always throttled.

IPs in neither list are throttled only if the send a request to a URI in the RequestLimit\_URL datagroups.

These datagroups are maintained by you. They are not updated dynamically.

You do not have to use the IP white/black lists, although you must define them otherwise you get an error.

You should use The RequestLimit\_URL list. Otherwise nothing is throttled.

This irule is not CMP compatible as is, this means that if you are on version 9.4 or above and using a bigip appliance with multiple CPUs, your virtual will be handled by only one CPU.

This irule also has old commands which will not survive an upgrade to the latest versions (v10.x or v11.x)

As to the first irule at that link: It is simpler and CMP compatible and will survive an upgrade. I wrote it for those reasons although it is not as feature rich as irule 2.

IRule 1 throttles POSTS only, if you want it to throttle GETs instead, just change the POST to a GET in the if statement.

If you need the features of the 2 irule, let us know, we will try to update it.

HTH.

---

<div class="post-metadata">

**Author:** ![MSD\_64443](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@MSD\_64443](https://community.f5.com/u/MSD_64443)\
**Post date:** [October 17, 2011, 10:54pm UTC](https://community.f5.com/t/http-request-throttle-irule-help/40362/4 "2011-10-17T22:54:56Z")

</div>

Thanks for the Reply

"These datagroups are maintained by you. They are not updated dynamically

You do not have to use the IP white/black lists, although you must define them otherwise you get an error."

So if I don’t list any IPs in the datagroups can this rule still allow and block IPs based on number of requests per sec.

“You should use The RequestLimit\_URL list. Otherwise nothing is throttled”

We don’t want to throttle the IPs based on the URL list, we want to do this based on number of requests per second.

---

<div class="post-metadata">

**Author:** ![John\_Alam\_45640](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@John\_Alam\_45640](https://community.f5.com/u/John_Alam_45640)\
**Post date:** [October 18, 2011, 2:40am UTC](https://community.f5.com/t/http-request-throttle-irule-help/40362/5 "2011-10-18T02:40:14Z")

</div>

Your best bet is i-Rule 1.

Her is a version of i-Rule 1 that throttles all requests:

This is a complete rewrite that is CMP-friendly, see older TMOS v9 code below.

Request Throttling

This I-Rule allows only “maxRate” HTTP requests within “windowSecs” interval.

This version defaults to limiting POSTs. If you need to limit GETs and/or POSTs

See notes below.

It is possible to limit on a user basis. See notes below.

CMP compatible: Yes

This rule requires:

A default pool so that the session table can be used

05/20/2010, Irule revised to use CMP compatible commands.

- “static” is added to global variable names.

- arrays replaced with subtables.

This rule developed on:

TMOS v10.1.0 build 3341.0

LTM

when RULE\_INIT {

set static::maxRate 5

set static::windowSecs 2

set static::timeout 30

}

when HTTP\_REQUEST {

This I-Rule limits “POST” requests, if you want to limit GETs instead, replace

“POST” with “GET” in if statement below.

If you want to limit all types or requests, remove this “if” statement below as well as its

Corresponding curly bracket ‘\}’ on or around line 67 clearly maked with a comment.

set myUserID “user”

set currentTime [clock seconds]

set windowStart [expr {$currentTime - $static::windowSecs}]

set postCount 0

PH stands for posthistory, a term from the original irule.

log -noname local0. “Table Keys [table keys -subtable ‘PH:${myUserID}.${AES\_key}’]”

foreach { requestTime } [table keys -subtable “PH:${myUserID}”] {

count POSTs with start time \> $windowStart, delete the rest

if { $requestTime \> $windowStart } {

incr postCount 1

} else {

table delete -subtable “PH:${myUserID}” $requestTime

}

}

if { $postCount \< $static::maxRate } {

add new record to array w/myUserID.rand + currentTime

set requestID “PH:${myUserID}”

table set -subtable $requestID $currentTime “ignored” $static::timeout

} else {

log -noname local0. “POST Rejected: current postCount for ${myUserID}: $postCount”

HTTP::respond 501 content “Request blockedExceeded requests/sec limit.”

return

}

}
