Forum Discussion

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    There is an iRule somewhere on codeshare that will rate limit connection rates.

     

     

    Hwoever be careful of applying that for HTTP. Rate limiting would be limited to all or nothing which means a browser being limited will get missing elements on their page... If that's a CSS or jscript, then the page might not render at all... Or illegibly. (It would be nice if you could slow up responses but I'm not sure how you'd implement that... It might be possible).

     

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    There are two methods used in Codeshare examples. Perhaps you could combine them to enforce the limiting you want? If you can provide more detail on what type of logic you want to implement, we can give you more detailed suggestions and/or examples.

     

     

    Rate limit HTTP POST requests per user

     

    http://devcentral.f5.com/Wiki/default.aspx/iRules/RateLimit_HTTPRequest.html

     

     

    Enforce a TCP connection limit for a VIP

     

    http://devcentral.f5.com/Wiki/default.aspx/iRules/virtual_server_connection_limit_with_HTTP_response.html

     

     

    Aaron
  • Below is the iRule which Rate limit based on HTTP method

     

    when RULE_INIT { set static::allowedRate 10 } when HTTP_REQUEST { set count [table loolkup -notouch [HTTP::method] ] if { $count eq "" } { Add entry into table with count as 1 for 1 second table add [HTTP::method] 1 1 } elseif { $count < $static::allowedRate } { Increment count table incr -notouch [HTTP::method] 1 } else { No of HTTP request exceeded per second do your action here HTTP::respond 503 } }

     

    Syed

     

  • when RULE_INIT {

    set static::allowedRate 10
    

    }

    when HTTP_REQUEST {

    set count [table loolkup -notouch [HTTP::method] ]
    if { $count  eq "" } {
       Add entry into table with count as 1 for 1 second
       table add [HTTP::method] 1 1
    } elseif { $count < $static::allowedRate } {
       Increment count
       table incr -notouch [HTTP::method] 1
    } else {
       No of HTTP request exceeded per second do your action here 
       HTTP::respond 503 
    }
    

    }

    --Formatted