Hi Lizunjjg,
I think if you refer this codeshare, you can achieve your requirement.
Let me know how it goes, so it would be something like below,
when RULE_INIT {
set static::max_active_clients 2000
}
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 {not ([table keys -subtable httplimit] > $static::max_active_clients)} {
set need_cookie 1
set client_id [format "%08d" [expr { int(100000000 * rand()) }]]
Only count this request if it's the first on the TCP connection
if {[HTTP::request_num] == 1}{
table set -subtable httplimit [IP::client_addr]:[TCP::client_port] "blocked"
set timer [after 60000 -periodic { table lookup -subtable httplimit [IP::client_addr]:[TCP::client_port] }
}
} else {
Selecting pool2 as the 1st pool reached connection limit
pool pool2
}
}
}
when HTTP_RESPONSE {
insert cookie if needed
if {$need_cookie == 1} {
HTTP::cookie insert name "ClientID" value $client_id path "/"
}
}
when CLIENT_CLOSED {
decrement current connection counter for this client_id
after cancel $timer
table delete -subtable httplimit [IP::client_addr]:[TCP::client_port]
}