Forum Discussion
lizunjjg_280139
Nimbostratus
Feb 02, 2019i have a irules question
hi guys: I have a irules need:1.i have three pools;2.When the current total number of connections in pool1 is greater than 2000, the new connection is then load balance by pool2 and pool3.
- lizunjjg_280139
Nimbostratus
The three pool load balancing methods are based on the data content. I can write the rules of this requirement.
- jaikumar_f5
Noctilucent
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] }
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects