Forum Discussion

sgoodliff_83611's avatar
sgoodliff_83611
Icon for Nimbostratus rankNimbostratus
Oct 31, 2007

connection 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

 

 

 

7 Replies

  • 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
    }

    Aaron
  • Hello,

     

     

    It nearly works perfectly but the HTTP:close causes a error. maybe its not available in the HTTP_REQUEST part ?
  • Per the wiki, HTTP::close should work in any HTTP event. What's the error you see?

     

     

    Aaron
  • Hello,

     

     

    From the ltm log I get a load of these messages:

     

     

    TCL error: rule_connection_limit - Operation not supported (line 15) invoked from within "HTTP::close"

     

     

     

    But when you click on the update irule button on the GUI it applies fine.

     

     

    Thanks

     

     

    Steve Goodliff
  • 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.

     

     

    Aaron
  • How would you code the above script to send a 204 No content.

     

    something like this

     

    when HTTP_REQUEST {

     

    HTTP::respond 204

     

    }

     

    Does this script pull the status for the active connections from F5 itself?