Forum Discussion

Shay_Ben-David1's avatar
Shay_Ben-David1
Icon for Nimbostratus rankNimbostratus
Mar 25, 2007

HTTP limit does not reduce sessions

Hi, i used the HTTP session limit on my web, but i can't figure why the total connection of the hhtp does not reduce, but only increased and after few minutes the site can not serve, and i have to remove the irule ?

 

 

rule HTTP_session_limit {

 

when RULE_INIT {

 

set ::total_active_clients 0

 

set ::max_active_clients 100

 

log local0. "rule session_limit initialized: total/max: $::total_active_clients/$::max_active_clients"

 

}

 

when HTTP_REQUEST {

 

; test cookie presence

 

if {[HTTP::cookie exists "ClientID"]} {

 

set need_cookie 0

 

set client_id [HTTP::cookie "ClientID"]

 

; if cookie not present & connection limit not reached, set up client_id

 

} else {

 

if {$::total_active_clients < $::max_active_clients} {

 

set need_cookie 1

 

set client_id [format "%08d" [expr { int(100000000 * rand()) }]]

 

incr ::total_active_clients

 

; otherwise redirect

 

} else {

 

HTTP::redirect "http://sorry.domain.com/"

 

return

 

}

 

}

 

}

 

when HTTP_RESPONSE {

 

; insert cookie if needed

 

if {$need_cookie == 1} {

 

HTTP::cookie insert name "ClientID" value $client_id

 

}

 

}

 

when CLIENT_CLOSED {

 

; decrement current connection counter for this client_id

 

if {$::total_active_clients > 0} {

 

incr ::total_active_clients -1

 

}

 

}

 

}

 

3 Replies

  • Hi

     

     

    I have also had a few problems with this rule (strangely I was having the opposite problem) and have found it more reliable to increment and decrement the total_active_clients using the "when CLIENT_ACCEPTED" and "when CLIENT_CLOSED" events.

     

     

    Hope that helps, I did get end up with a rule that works pretty well eventually.

     

     

    Dave
  • mlick2's avatar
    mlick2
    Icon for Nimbostratus rankNimbostratus
    What actually triggers the CLIENT_CLOSED event? I am using this same iRule and I am seeing that within 5 - 20 seconds of the HTTP_REQUEST, the CLIENT_CLOSED event is triggered and my user count is decremented by 1. Therefore I am not keeping an accurate count of how many active sessions there are because my count is back down to 0 and within a few seconds another round of users are allowed to get a cookie and pass through.
  • I encountered exactly the same problem, I not sure what triggers the event myself, it does seem to vary according to serveral factors (client browser, traffic level, etc.). I got around it by using CLIENT_ACCEPTED to increment and CLIENT_CLOSED to decrement, this is not 100% reliable but is good enough, I just reset my count every so often (couple of times a month) using the count in the statistics page to keep it accurate.