Forum Discussion
mtobkes_64700
May 12, 2010Nimbostratus
Rate-Limiting Crawlers
Hi I found this iRule here that will limit requests to 1 request per n seconds. I would like to know how I'd be able to allow n requests per 1 second, e.g. allow 5 requests per 1 second.
when RULE_INIT {
array set ::active_crawlers { }
set ::min_interval 1
set ::rate_limit_message "You've been rate limited for sending more than 1 request every $::min_interval seconds."
}
when HTTP_REQUEST {
set user_agent [string tolower [HTTP::header "User-Agent"]]
if { [matchclass $user_agent contains $::Crawlers] } {
Throttle crawlers.
set curr_time [clock seconds]
if { [info exists ::active_crawlers($user_agent)] } {
if { [ $::active_crawlers($user_agent) < $curr_time ] } {
set ::active_crawlers($user_agent) [expr {$curr_time + $::min_interval}]
} else {
block it somehow
HTTP::respond 503 content $::rate_limit_message }
} else {
set ::active_crawlers($user_agent) [expr {$curr_time + $::min_interval}]
}
}
}
Thanks,
myles
- JRahmAdminFor cleaner, more accurate rate-limiting, check out the table command article series that covers this in depth:
- mtobkes_64700NimbostratusThanks for the link. However I'm only running v9.4.7. Can you tell me what options that leaves me?
- JRahmAdminCheck this version of the dns flood protection rule, the bones of the rate limiting are there:
- mtobkes_64700NimbostratusI've modified the iRule I found to limit crawlers. I want to allow ::max_req_count for every ::min_interval, but I am getting a TCL error in my logs. Was wondering if someone can help me figure out what the problem is. The error I'm getting is:
- hooleylistCirrostratusHi myles,
- mtobkes_64700NimbostratusThanks Aaron. I changed the line however I now get this TCL error in my logs:
- hooleylistCirrostratusDo you still have the parentheses around $user_agent and the less than sign in this line?
Recent Discussions
Related Content
Â
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects