Forum Discussion

Absarkhan_15403's avatar
Absarkhan_15403
Icon for Nimbostratus rankNimbostratus
Jul 31, 2014

iRule adding 10% CPU overhead

Hi All,

 

Need some guidance from you good people.

 

I have created the below iRule for a waiting room page display when the website is catering for high load. However when I tested it in production today we saw 10% increase in CPU utilisation as compared to the load without the iRule. Is this something normal as top managers were expecting about 2-3% increment in CPU utilisation? The test used to hit the iRule is [ec2-user@waitingroom-tests]$ ./250EGC-h.sh -n 20000 -c 4 -k. This means 4 users generating 20000 requests. Without the iRule this test generated 33% CPU and with iRule 43%. Any recommendations on how to decrease the CPU utilisation or is this something expected? The iRule is given below;

 

when HTTP_REQUEST priority 1 { set static::maxActiveClients "[class search -all -value datagroup_selfridges_waitingroom starts_with "max_active_clients"]" set subtableName "sessionLimit" set sessionCookieName "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_cookie_prefix"]" set holdingPage "[class search -all -value datagroup_selfridges_waitingroom starts_with "holding_page_url"]" set static::sessionTimeout "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_timeout"]" set need_cookie 0 if {[HTTP::cookie exists $sessionCookieName]} { set client_id [HTTP::cookie $sessionCookieName] set sessiondata [table lookup -subtable $subtableName $client_id] if { $sessiondata != "" } {

 

log local0. "Valid session $client_id - continuing"

return } }

 

log local0. "No session. Checking for free slot (Max $static::maxActiveClients)"

set sessionCount [table keys -subtable $subtableName -count]

 

log local0. "No session. Checking for free slot (Current $sessionCount)"

if {$sessionCount < $static::maxActiveClients} { set need_cookie 1 set client_id [format "%08d" [expr { int(1000000000 * rand()) }]] set sessionValue [IP::client_addr] table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout

 

log local0. "New Session ($client_id) added value $sessionValue Timeout $static::sessionTimeout"

} else { HTTP::redirect $holdingPage } } when HTTP_RESPONSE priority 1 { if {$need_cookie == 1} { HTTP::cookie insert name $sessionCookieName value $client_id path "/" } }

 

Lastly as you can notice the iRule takes the variables from a data group that have different values. I wanted the iRule to work on connections however it is working on sessions. Does anyone know what is the variable I can use for it to trigger for connections rather than sessions?

 

Thanks in advance.

 

3 Replies

  • I have formatted the iRule so that it is readable.

     

    when HTTP_REQUEST priority 1 {

     

    set static::maxActiveClients "[class search -all -value datagroup_selfridges_waitingroom starts_with "max_active_clients"]"

     

    set subtableName "sessionLimit"

     

    set sessionCookieName "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_cookie_prefix"]"

     

    set holdingPage "[class search -all -value datagroup_selfridges_waitingroom starts_with "holding_page_url"]"

     

    set static::sessionTimeout "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_timeout"]"

     

    set need_cookie 0

     

    if {[HTTP::cookie exists $sessionCookieName]} {

     

    set client_id [HTTP::cookie $sessionCookieName]

     

    set sessiondata [table lookup -subtable $subtableName $client_id]

     

    if { $sessiondata != "" } {

     

    log local0. "Valid session $client_id - continuing"

    return

     

    }

     

    }

     

    log local0. "No session. Checking for free slot (Max $static::maxActiveClients)"

    set sessionCount [table keys -subtable $subtableName -count]

     

    log local0. "No session. Checking for free slot (Current $sessionCount)"

    if {$sessionCount < $static::maxActiveClients} {

     

    set need_cookie 1

     

    set client_id [format "%08d" [expr { int(1000000000 * rand()) }]]

     

    set sessionValue [IP::client_addr]

     

    table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout

     

    log local0. "New Session ($client_id) added value $sessionValue Timeout static::sessionTimeout"

    } else {

     

    HTTP::redirect $holdingPage

     

    }

     

    }

     

    when HTTP_RESPONSE priority 1 {

     

    if {$need_cookie == 1} {

     

    HTTP::cookie insert name $sessionCookieName value $client_id path "/"

     

    }

     

    }

     

  • when HTTP_REQUEST priority 1 {
      set static::maxActiveClients "[class search -all -value datagroup_selfridges_waitingroom starts_with "max_active_clients"]"
      set subtableName "sessionLimit"
      set sessionCookieName "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_cookie_prefix"]"
      set holdingPage "[class search -all -value datagroup_selfridges_waitingroom starts_with "holding_page_url"]"
      set static::sessionTimeout "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_timeout"]"
    
      set need_cookie 0
      if {[HTTP::cookie exists $sessionCookieName]} { 
        set client_id [HTTP::cookie $sessionCookieName]
        set sessiondata [table lookup -subtable $subtableName $client_id]
        if { $sessiondata != "" } {
          log local0. "Valid session $client_id - continuing"
          return
        }
      }
    
      log local0. "No session. Checking for free slot (Max $static::maxActiveClients)"
      set sessionCount [table keys -subtable $subtableName -count]
    
      log local0. "No session. Checking for free slot (Current $sessionCount)"
      if {$sessionCount < $static::maxActiveClients} {
        set need_cookie 1
        set client_id [format "%08d" [expr { int(1000000000 * rand()) }]]
        set sessionValue [IP::client_addr]
    
        table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout
        log local0. "New Session ($client_id) added value $sessionValue Timeout static::sessionTimeout"
      } else {
        HTTP::redirect $holdingPage
      }
    }
    
    when HTTP_RESPONSE priority 1 {
      if {$need_cookie == 1} {
        HTTP::cookie insert name $sessionCookieName value $client_id path "/"
      }
    }