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