Forum Discussion
abeny_894
Nimbostratus
Dec 01, 2008Session can't release
Dears,
I have got the iRules for session control the HTTP request from customer. However I found that the counter sometimes can't release after OVER the said limit even the iRules contains "set total_active_clients to 0" in CLIENT_CLOSED. As the iRules is so critical for my client also i am not so professional as you guys in iRules, I would like to seek you guys help for take a look on it? Moreover, any suggestion or modification for this iRules?
**********************************************************when RULE_INIT {
set ::total_active_clients_a 0
set ::max_active_clients_a 10
set ::total_active_clients_b 0
set ::max_active_clients_b 10
}
when HTTP_REQUEST {
switch [HTTP::host] {
abc.com {
log local0. "Access to abc.com"
set site a
incr ::total_active_clients_a
log local0. "total requests are $::total_active_clients_a"
set cur_time_a [clock seconds]
set start_time_a $cur_time_a
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a <= $::max_active_clients_a } {
HTTP::redirect "http://www.yahoo.com.hk"
return
}
}
}
xyz.com {
log local0. "Access to xyz.com"
set site b
set cur_time_b [clock seconds]
incr ::total_active_clients_b
log local0. "total requests are $::total_active_clients_b"
set cur_time_b [clock seconds]
set start_time_b $cur_time_b
if { $cur_time_b == $start_time_b } {
if { $::total_active_clients_b >= $::max_active_clients_b } {
HTTP::redirect "http://www.google.com/"
return
}
}
}
}
}
when HTTP_RESPONSE {
log local0. "site is $site"
if { $site == "a" } {
log local0. "site a is true"
set cur_time_for_cookie [clock seconds]
log local0. "cookie value for site a is $cur_time_for_cookie"
set cookie_value_crc [crc32 $cur_time_for_cookie]
log local0. "crc32 is $cookie_value_crc"
HTTP::cookie insert name "site_a_cookie" value "$cookie_value_crc" domain "a.com"
HTTP::cookie encrypt "site_a_cookie" password
HTTP::cookie expires "site_a_cookie" 50000 relative
} elseif { $site == "b" } {
log local0. "site b is true"
set cur_time_for_cookie [clock seconds]
log local0. "cookie value for site b is $cur_time_for_cookie"
set cookie_value_crc [crc32 $cur_time_for_cookie]
log local0. "crc32 is $cookie_value_crc"
HTTP::cookie insert name "site_b_cookie" value "$cur_time_for_cookie" domain "b.com"
HTTP::cookie encrypt "site_b_cookie" password
HTTP::cookie expires "site_b_cookie" 50000 relative
}
}
when CLIENT_CLOSED {
log local0. "site $site request closed"
if { $site == "a" } {
incr ::total_active_clients_a -1
if { $::total_active_clients_a <= 0 } {
set ::total_active_clients_a 0
}
} elseif { $site == "b" } {
incr ::total_active_clients_b -1
if { $::total_active_clients_b <= 0 } {
set ::total_active_clients_b 0
}
}
}
**********************************************************
- Colin_Walker_12Historic F5 AccountIt looks like you're only conditionally setting the active_clients to 0. Are you sure those conditions are being met when you expect them to be? Have you tried adding logging inside those if/elseif sections?
- abeny_894
Nimbostratus
Thanks Colin, I observed that the log will show the accumulate value and it will decrease normally to 0 when CLIENT CLOSE the session. It is the normal expected result. - hoolio
Cirrostratus
Hi Abeny, - abeny_894
Nimbostratus
Thanks Aaron and your suggestion. By the way, I know what you means but sorry that i have no idea on how to make this iRules "decrement the total count by the number of HTTP requests on the TCP connection in CLIENT_CLOSED" - Colin_Walker_12Historic F5 AccountTo decrement by the total number of requests made you would simply increment a counter on every HTTP_REQUEST event in that given connection. Then in the CONNECTION_CLOSED event you'd decrement the connection count by that number, rather than just by one. This way it would decrement the count by the same number that it was incremented, as it's being incremented once per HTTP_REQUEST.
- abeny_894
Nimbostratus
Thanks Colin. It sounds great. Um...For iRules, is it means that i need add CONNECTION_CLOSED event under [HTTP::host] for each domain and create a new counter on every HTTP_REQUEST?? - Colin_Walker_12Historic F5 AccountIt would look almost identical to what you have now. You'd just add a counter value under the HTTP_REQUEST section that's used and then emptied in the CLIENT_CLOSED event.
when HTTP_REQUEST { incr requestCount -1 ...
when CLIENT_CLOSED { log local0. "site $site request closed" if { $site == "a" } { incr ::total_active_clients_a $requestCount set requestCount 0 if { $::total_active_clients_a <= 0 } { set ::total_active_clients_a 0 } ...
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