Forum Discussion
Jack_H_39707
Nimbostratus
Apr 30, 2010Is there an IRules to control active connections?
Dear all, I am very new to F5 and would really appreciate if any of the members here could help me.
Is there an IRules which allow F5 to control the active connections? Meaning, If I allowed 20 connections at one time, the 21 connections will be redirected to an error page? Something like it can only let the next connections comes in when the current connections dropped below the allowed limit. I have tried with a help of few examples posted, most of it works on the preventing active concurrent connection.
- The_Bhattman
Nimbostratus
Hi Jack, - Jack_H_39707
Nimbostratus
Dear Bhattman, thanks for yoru advise. The code works fine in rejecting. I have replaced the reject command with HTTP::redirect "http://mydomain.com/error.page" but it says HTTP::redirect does not applies to this event. Is there any thing else I need to define in the code? - The_Bhattman
Nimbostratus
You are right.rule session_limit { when RULE_INIT { array set ::active_sessions { } set ::total_active_clients 0 set ::max_active_clients 20 } when HTTP_REQUEST { if { not [info exists client_id] } { if { [HTTP::cookie exists "ClientID"] } { set client_id [HTTP::cookie "ClientID"] set need_cookie 0 } else { set client_id [string range [AES::key 128] 8 end] set need_cookie 1 } if { not [info exists ::active_sessions($client_id)] } { if { $::total_active_clients >= $::max_active_clients } { HTTP::redirect "http://mydomain.com/error.page" return } incr ::total_active_clients set ::active_sessions($client_id) 1 } else { incr ::active_sessions($client_id) } } } when HTTP_RESPONSE { if { $need_cookie } { HTTP::cookie insert name "ClientID" value $client_id set need_cookie 0 } } when CLIENT_CLOSED { if { [info exists client_id] and [info exists ::active_sessions($client_id)] } { incr ::active_sessions($client_id) -1 if { $::active_sessions($client_id) <= 0 } { unset ::active_sessions($client_id) incr ::total_active_clients -1 } } } }
- Jack_H_39707
Nimbostratus
Dear Bhattman, pardon me for asking again, if i set > "set ::max_active_clients 2" for testing. I am still able to access the url with 3 different pc on top of 2 pc. Is it suppose to work in this way or there is something that I need to re-fine in the code? - anthony_102289
Nimbostratus
That looks great Bhattman! I am wondering what ways there are to remotely modify the global variable max_active_clients. I've worked out two ways but not sure if there is a better way, - hoolio
Cirrostratus
Either option should work fine. You could also change the iRule to read the datagroup directly instead of a global variable and then use iControl to update the datagroup entry.
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