Forum Discussion

Juerg_Wiesmann's avatar
Juerg_Wiesmann
Icon for Nimbostratus rankNimbostratus
Jun 04, 2007

Waiting Room

Hi Experts

 

 

Have got a difficult Question.

 

 

We want to have to send 1000 Sessions to our pool Ticket.

 

Users 1001-2000 should be redirected to a Waiting Room to get somthing like a Cookie and wait, until one of the first 1000 Users leaves the Shop.

 

 

After Sessions are available on the Ticket Pool the Redirected Users should be connected to the Ticket Pool and this in the order they have got there cookie from Waiting Room Server.

 

 

Any Ideas of how to achive this ?

 

 

Many thanks

 

 

Juerg

5 Replies

  • Good Idea,

     

     

    The only problem on that is, the timeliness. The first User who was sent to the sorry page should get the next available session.

     

     

    I wrote an iRule which should achive a simular thing, Users who have sessions in the shop get a Cookie called(Client_ID). As soon as the connection limit is reached the next user gets a cookie called ticket with value 1. Next available session is then given to the User with the lower ticket number than the value of the next_please value, and gets the second ticket.

     

     

    Somehow the rule dosn´t work (Syntax is ok, but have problems with variables..) Any Ideas on that ?

     

     

    when RULE_INIT {

     

    set ::total_active_clients 0

     

    set ::max_active_clients 100

     

    set ticket_number 0

     

    set ::next_please 1

     

    set client_id 1

     

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

     

    }

     

    when HTTP_REQUEST {

     

    test client-ID Cookie availability

     

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

     

    Client-ID Cookie exists (don't need one )

     

    set need_cookie 0

     

    set client_id [HTTP::cookie "ClientID"]

     

    log local0. "Cookie ClientID Exists = $::total_active_clients/$::max_active_clients/$ticket_number"

     

    }

     

    elseif {[HTTP::cookie exists "ticket"]} {

     

    ticket Cookie exists --don't need one-- log local0. "this is the $ticket_number"

     

    set need_cookie 2

     

    log local0. "Cookie ticket Exists = $ticket_number" }

     

    if {$ticket_number <= $::next_please} {

     

    If ticket_number is lower than next_please

     

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

     

    set need_cookie 1

     

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

     

    incr ::total_active_clients 1

     

    log local0. "Ask for new ClientID Cookie $::total_active_clients/$::max_active_clients"

     

    }}

     

    else {

     

    set need_cookie 2

     

    set ticket_number [HTTP::cookie "ticket"]

     

    log local0. "Cookie ticket Needed = $ticket_number"}

     

    }

     

     

    when HTTP_RESPONSE {

     

    if {$need_cookie == 1} {

     

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

     

    log local0. "need cookie is.. $need_cookie"

     

    }

     

    elseif {$need_cookie ==2} {

     

    log local0. "need cookie is2.. $need_cookie"

     

    HTTP::cookie insert name "ticket" value $ticket_number

     

    }

     

    }

     

     

     

    when CLIENT_CLOSED {

     

    ; decrement current connection counter for this client_id

     

    if {$::total_active_clients > 0} {

     

    incr ::total_active_clients -1

     

    }

     

    else {

     

    set ticket_number 0

     

    set ::next_please 1

     

    log local0. "ticketReset= $ticket_number/$::next_please" }}
  • I updated my Waiting iRule. The only Problem still exists is that the client close appears also when browser was not closed.

    Any help appreciated.

    Jürg

    when RULE_INIT {  
     set ::total_active_clients 0  
     set static::max_active_clients 3  
     set ::ticket_number 0  
     set ::next_please 3  
     set ::howlong 3     
     log local0. "rule session_limit initialized: total/max: $::total_active_clients/$static::max_active_clients/$::ticket_number"  
     }  
     when HTTP_REQUEST {  
      test client-ID Cookie availability  
     if {[HTTP::cookie exists "ClientID"]} {  
      Client-ID Cookie exists (don't need one )  
      if ClientID cookie is in the request the client is directly sent to the TicketServer  
     set need_cookie 0  
     set client_id [HTTP::cookie "ClientID"]  
     log local0. "ClientID Exists = $::total_active_clients/$static::max_active_clients/$::ticket_number"  
     log local0. "We have a ClientID and the need cookie value is....$need_cookie and we will return now"  
     return  
     }  
     if {[HTTP::cookie exists "ticket"]} {  
     HTTP::cookie decrypt ticket DEQREddarehf "256"  
      ticket Cookie exists --don't need one--  
      log local0. "We have a Cookie named ticket and the ticket number is: $::ticket_number"  
     log local0. "Cookie ticket Exists = $::ticket_number / $::next_please"   
     if {$::ticket_number <= $::next_please} {  
      If ticket_number is lower than next_please  
     if  {$::total_active_clients < $static::max_active_clients} {  
     set need_cookie 1  
     set client_id [string range [AES::key 128] 8 end]   
     incr ::total_active_clients 1  
     log local0. "Ask for new ClientID Cookie $::total_active_clients/$static::max_active_clients/$::ticket_number"   
     }}  
     else {  
     HTTP::respond 200 content {  
       
       
     Sorry  
       
       
     The System was closed due to high demand. Please wait a few seconds we will try to connect you shortly 
       
      }  
     }}  
     if {not [HTTP::cookie exists "ticket"]} {  
     incr ::ticket_number 1       
     set ticket_number [HTTP::cookie "ticket"]  
     log local0. "Cookie ticket Needed = $::ticket_number"  
     HTTP::respond 302 Location "http://[HTTP::host][HTTP::uri]" "Set-Cookie" ticket=$::ticket_number  
     }}  
     when HTTP_RESPONSE {  
     if {$need_cookie == 1} {  
     HTTP::cookie insert name "ClientID" value $client_id  
     log local0. "We insert the ClientID Cookie"  
     }  
      else {  
      log local0. "need cookie is.. $need_cookie"  
      HTTP::cookie insert name "ticket" value $::ticket_number  
      HTTP::cookie encrypt ticket DEQREddarehf "256"  
         }  
     }   
     when CLIENT_CLOSED {  
     decrement current connection counter for this client_id  
     if {$::total_active_clients > 0} {  
     incr ::total_active_clients -1  
     log local0. "ClientClosed $::total_active_clients"  
     }  
     else {  
     set ::ticket_number 0  
     set ::next_please 3  
     log local0. "ticketReset= $::ticket_number/$::next_please" }}
  • The CLIENT_CLOSED event is triggered when the client to VIP TCP connection is closed--not only when the client closes their browser.

     

     

    Aaron
  • Hi Aaron,

     

    Yes I agree, have you got an idea how we can maintain the connection so it dosn't close.

     

    We use HTTP 1.1 and Keepalive should keep connection open.

     

     

    Since HTTP is a stateless Protocol. Do you see any chance maintaining the session ?

     

    Many thanks

     

     

    Jürg
  • Hi Jürg,

     

     

    By default LTM doesn't restrict the number of HTTP requests that a client can make over a TCP connection. The default TCP idle timeout is 300 seconds. It's probably down to the client for how long they use the same TCP connection. I wouldn't expect/depend on a client using a single TCP connection for an HTTP "session". Maintaining state across multiple TCP connections and HTTP requests is the primary function of HTTP cookies though. So use the cookie to track the client.

     

     

    Aaron