Forum Discussion
Hi Oscarnet,
the use of global $::variables is since TMOS v10 not recommended and will degrade the CMP-operation mode of your Virtual Server to Single-CPU mode and may therefor cause a performance bottleneck.
https://devcentral.f5.com/wiki/iRules.CMPCompatibility.ashx
The recommended approach would be to migrate the usage of $::variables to $static::variables (aka. Static Namespace Variables). The required iRule code change is in your specific scenario pretty simple...
ltm data-group internal /Common/redirect_dg {
textrecords {
0 {
data www00.abc.com
}
1 {
data www01.abc.com
}
2 {
data www02.abc.com
}
3 {
data www03.abc.com
}
4 {
data www04.abc.com
}
5 {
data www05.abc.com
}
}
type string
}
when RULE_INIT {
set static::whichone 0
}
when HTTP_REQUEST {
set REDIRECT [class match -value -- $static::whichone equals redirect_dg]
if { $REDIRECT ne "" } {
if { $static::whichone == 5 } {
set static::whichone 0
} else {
incr static::whichone
}
HTTP::redirect "http://$REDIRECT"
}
}
Note: Keep in mind when CMP-operation is active, each CPU core will maintain an independent copy of the $static::variables value and will therefor have its own round robin decission. If this is a problem for you, then take a look to the [table] command to maintain a single counter across the individual CPU-cores.
Beside of the impact on the CMP-operation, I think that using a rather simple "Random-Robin" algorythm instead of using a strict "Round-Robin" algorythm may be also a good idea. It will simplyfy the iRule logic pretty much for you...
when RULE_INIT {
set static::nodelist {
www00.abc.com
www01.abc.com
www02.abc.com
www03.abc.com
www04.abc.com
www05.abc.com
}
}
when HTTP_REQUEST {
HTTP::redirect "http://[lindex $static::nodelist [expr { int(rand()*[llength $static::nodelist])}]]"
}
Note: $static::nodelist defines the [list] of possible HOSTNAMES. The [lindex $static::nodelist ] command is used to parse the $static::nodelist and to extract a given a element by specifying a absolute position in the [list]. The [expr { int(rand()*[llength $static::nodelist])}] command generates a random number between 0 and the maximum number of entries in your $static::nodelist (e.g. = 0-5 in your case). The random value is then passed back to [lindex] to finally extract the value of the selected [list] item (aka. the HOSTNAME).
Cheers, Kai