Forum Discussion

MR_RJ's avatar
MR_RJ
Icon for Cirrus rankCirrus
Dec 20, 2008

iRule 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

 

}

 

}

4 Replies

  • 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?

     

     

    You could streamline that iRule a bit more by removing the check for the URI equaling the maintenance prefix. You could also set the time_min and time_max variables once in RULE_INIT instead of on every request where there aren't any active pool members.

     

     

     
     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 
        } 
     } 
     

     

     

    Aaron
  • Hi,

     

     

    Thanks for the reply. I will modify it a bit according to your suggestions.

     

    The "issue" is that it gets executed a lot, im a bit afraid that it will have negativ impact/overhead on the LTM. Noticed that the iRule-hit-statistics shows something like 20+ executions / second during normal hours.

     

     

    ...or shouldnt I be worried about it?

     

     

    //Robert
  • 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?

     

     

    Aaron
  • No not at all, it has become faster then ever since I configured this nice LB environment =)

     

     

    Just got me a bit worried when i saw how many hits the iRule gets... didnt think of that it would be accessed each time a visitor does a GET ...which is a lot.

     

     

    //Robert