Forum Discussion
sgoodliff_83611
Nimbostratus
Oct 31, 2007connection limit on virtual server
Hello,
I would like to have a irule that sends back content via
HTTP::respond 200 content $html_content
When a virtual server has hit its connection limit. I've seen examples of how to do it on a per member basis but not on a per virtual server but we only have limits set on a virtual server.
Is there a way to do this ?
Thanks
Steve Goodliff
- hoolio
Cirrostratus
I think something like this should work. It's untested though.when RULE_INIT { set ::active_connections 0 set ::max_connections 1000 set ::html_content "over limit" set ::debug 1 } when CLIENT_ACCEPTED { Initialize a variable to track whether we're over the limit and should send a response from the rule for this request set over_limit 0 Check if we're over the maximum allowed connections if {$::active_connections > $::max_connections } { set over_limit 1 } else { We're not over the max, so don't respond to the request incr ::active_connections 1 } } when HTTP_REQUEST { If we're over the limit for this connection, send a response if {$over_limit}{ Send a response HTTP::respond 200 content $::html_content Close the connection HTTP::close Log a message to /var/log/ltm if debug is enabled if {$::debug}{log local0. "Over limit (current/max: $::active_connections/$::max_connections). Sent response to [IP::client_addr]"} } } when CLIENT_CLOSED { A connection was closed, so decrement the global counter incr ::active_connections -1 }
- sgoodliff_83611
Nimbostratus
Hello, - hoolio
Cirrostratus
Per the wiki, HTTP::close should work in any HTTP event. What's the error you see? - sgoodliff_83611
Nimbostratus
Hello, - hoolio
Cirrostratus
Can you try TCP::close instead? Worst case, if you remove the close command altogether and the client makes additional HTTP requests on the same TCP connection after the connection limit is reached, the client will get redirected again. - sgoodliff_83611
Nimbostratus
TCP::close works fine. - pgroven_71837
Nimbostratus
How would you code the above script to send a 204 No content.
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