Forum Discussion

amichai_246034's avatar
amichai_246034
Icon for Nimbostratus rankNimbostratus
Feb 14, 2016

Concern regarding calling active_members -list in an iRule for every call (performance and memory usage impact)

I have a concern regarding calling active_members -list in an iRule for every call (performance and memory usage impact)

 

iRule below. Motivation: instead of using F5 round robin + sticky by session, because I have millions of devices sending data and they should be sticky I want to contol the load balancing by my own and remove the need of F5 to save a map of millions so it can know to which server to route the traffic

 

the problem: I am creating every request a call to [active_members -list [LB::server pool]]. so it is creating a list or pointing to a list (I don't know how F5 implemented it). does this call (or anything else in the code) create any performance or memory usage impact?

 

Here is the iRule:

 

 when HTTP_REQUEST {
 get the ROUTEID last char and decide by it to which pool to go using modulo of the number of active servers. if no ROUTEID use regular round robin
 doing this we will achieve sticky by session (device) AND the F5 wont need to hold millions of devices in the routing table

 if { [HTTP::cookie exists "ROUTEID"] }{
 set routeId [HTTP::cookie value "ROUTEID"]        
 set lastChar  [string range $routeId 0 0]  

 make lastChar  an integer   
 switch $lastChar {
    "a" {
            set lastChar 10
        }
    "b" {
            set lastChar 11
        }
    "c" {
            set lastChar 12
        }
    "d" {
            set lastChar 13
        }
    "e" {
            set lastChar 14
        }
    "f" {
            set lastChar 15
        }
  }

  set numOfMembers [active_members [LB::server pool]]    
  index that should be used by modulo of the ROUTEID with the number of active servers
  set indx  [expr $lastChar % $numOfMembers]   
  get the array of active members 
  set lst [active_members -list [LB::server pool]]
  redirect to the relevant ip and port
  pool [LB::server pool] member [lindex [lindex $lst $indx] 0] [lindex [lindex $lst $indx] 1]
 }
 }

Will there be a problem to performance or memory calling the [active_members -list [LB::server pool]]?

 

Thanks

 

1 Reply

  • Hi Amichai,

     

    even the smalest iRule may cause performance problems, if you've have already maxed out the capacity of your hardware. But if you have some spare capacity leftover, then this iRule shouldn't be a big deal.

     

    Since performance seems to be a concern, you may try the syntax below. Its basically a carbon copy of your code, but performs ~45% faster...

     

    when RULE_INIT {
        array set static::hex2deci {
            0 0     1 1     2 2     3 3
            4 4     5 5     6 6     7 7
            8 8     9 9     a 10    b 11
            c 12    d 13    e 14    f 15
            A 10    B 11    C 12    D 13
            E 14    F 15
        }
    }
    when HTTP_REQUEST {
        if { [set hex [string range [HTTP::cookie value "ROUTEID"] 0 0]] ne "" } then {
            set member [lindex [active_members -list [LB::server pool]] [expr { $static::hex2deci($hex) % [active_members [LB::server pool]] }]]
            pool [LB::server pool] member [lindex $member 0] [lindex $member 1]
        } else {
            pool [LB::server pool]
        }
    }

    Cheers, Kai