Forum Discussion
MR_RJ
Cirrus
Dec 20, 2008iRule gets to many hits because of bad code?
Hi,
I noticed that my iRule gets a lot of hits according to the statistics. Now I understand why. The purpose of the iRule is if no members are available in the webfarm then show a "houston we have a problem"-page.
The rule is executed each time a "http get" arrives. This causes the iRule hits to go through the roof, like 10 hits / sec or more.
Any suggestions how I should rewrite this part?
//Robert
Here is the rule:
when RULE_INIT {
set maint_prefix "/maintenancepage"
set maint_len [string length $maint_prefix]
}
when HTTP_REQUEST {
set uri [HTTP::uri]
if { $uri equals ${::maint_prefix} } {
HTTP::respond 301 "Location" "${::maint_prefix}/"
return
}
if { $uri starts_with "${::maint_prefix}/" } {
set uri [string range $uri $::maint_len end]
switch $uri {
"/" -
"/index.html" { HTTP::respond 200 content [lindex $::something_something_Maintenance_index_page 0] "Content-Type" "text/html" }
"/logo.png" { HTTP::respond 200 content [b64decode [lindex $::something_something_Maintenance_png 0]] "Content-Type" "image/png" }
"/problems.html" { HTTP::respond 200 content [lindex $::something_something_driftstorningar_index_html 0] "Content-Type" "text/html" }
"/probs.png" { HTTP::respond 200 content [b64decode [lindex $::something_something_driftstorningar 0]] "Content-Type" "image/png" }
default { HTTP::respond 404 }
}
return
}
if { [active_members something_something_Online_Win2003_HTTP] == 0 } {
set current_time [clock seconds]
set ::time_min [clock scan {06:00}]
set ::time_max [clock scan {22:00}]
if {($current_time < $::time_min) or ($current_time > $::time_max)} {
HTTP::redirect "${::maint_prefix}/index.html"
log "No members in pool something_something_Online_Win2003_HTTP, redirecting to maintenancepage"
return
}
log local0. "No members in pool something_something_Online_Win2003_HTTP, redirecting to the critical state page"
HTTP::redirect "${::maint_prefix}/problems.html"
return
}
}
- hoolio
Cirrostratus
If you add an iRule with code in an HTTP_REQUEST, it will be executed every time an HTTP request is made to the VIP and the HTTP headers are parsed. Can you explain what the issue is?when RULE_INIT { set ::maint_prefix "/maintenancepage" set ::maint_len [string length $maint_prefix] set ::time_min [clock scan {06:00}] set ::time_max [clock scan {22:00}] } when HTTP_REQUEST { if { [HTTP::path] starts_with "${::maint_prefix}" } { set uri [string range [HTTP::uri] $::maint_len end] switch $uri { "" {HTTP::respond 301 "Location" "${::maint_prefix}/"} "/" - "/index.html" { HTTP::respond 200 content [lindex $::something_something_Maintenance_index_page 0] "Content-Type" "text/html" } "/logo.png" { HTTP::respond 200 content [b64decode [lindex $::something_something_Maintenance_png 0]] "Content-Type" "image/png" } "/problems.html" { HTTP::respond 200 content [lindex $::something_something_driftstorningar_index_html 0] "Content-Type" "text/html" } "/probs.png" { HTTP::respond 200 content [b64decode [lindex $::something_something_driftstorningar 0]] "Content-Type" "image/png" } default { HTTP::respond 404 } } return } if { [active_members something_something_Online_Win2003_HTTP] == 0 } { set current_time [clock seconds] if {($current_time < $::time_min) or ($current_time > $::time_max)} { HTTP::redirect "${::maint_prefix}/index.html" log "No members in pool something_something_Online_Win2003_HTTP, redirecting to maintenancepage" return } log local0. "No members in pool something_something_Online_Win2003_HTTP, redirecting to the critical state page" HTTP::redirect "${::maint_prefix}/problems.html" return } }
- MR_RJ
Cirrus
Hi, - hoolio
Cirrostratus
It's expected that the iRule would trigger on every request. This is necessary in order to use the iRule. Are you seeing a spike in CPU or memory usage, or in latency in accessing the application? - MR_RJ
Cirrus
No not at all, it has become faster then ever since I configured this nice LB environment =)
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