Forum Discussion
bob_rao_7722
Mar 14, 2006Historic F5 Account
iRule that will limit connections
I am trying to write an irule that will do the following:
1) limit the web servers to 50 connections each.
2) any connection after 50 will be redirected to another site.
3) Clients are...
Deb_Allen_18
Mar 15, 2006Historic F5 Account
Make sure I have the logic straight first:
if cookie exists
load balance to default pool w/persistence
(session already exists, so don't increment counter)
if no cookie exists
if uristring exists
redirect to "nocookies" page
if connection limit not yet reached
load balance to default pool
increment counter
else if connection limit already reached
redirect to "server busy" page
By re-ordering your original conditions a bit, eliminating one unused array, and incrementing a bit differently, we get:
rule session_limit {
when RULE_INIT {
set ::total_active_clients 0
set ::max_active_clients 50
}
when HTTP_REQUEST {
; If persistence cookie already exists,
; allow persistent connection without incrementing counter
if { [HTTP::cookie exists "BIGipServerhalifax"] } {
pool halifax
return
; If no cookie, check for URI link parameter
; & redirect if present
} else {
if { [HTTP::uri] contains "linkID=halifax" } {
HTTP::redirect "http://pleasehold.evenue.net/bigip/nocookies.html"
return
}
; Still no cookie
; Check limit vs. active
; Allow in if there's room, and incr counter for this new cnx
if { $::total_active_clients < $::max_active_clients } {
incr ::total_active_clients
pool halifax
return
; otherwise redirect
} else {
HTTP::redirect "http://www.yahoo.com/"
return
}
}
}
when CLIENT_CLOSED {
incr ::total_active_clients -1
}
}
This will enforce a connection limit of 50 total concurrent users on the VS. If you use "least connections" load balancing, you will get the most even distribution of connections across the server pool. I'm not sure how nicely node connection limits will play with the rule limits, so I'm going to recommend you leave off the node limits until you have the rule logic working the way you want, and then I'll leave the question of node limits open for your experimentation.
HTH
/d
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