Ulf_Wätterstam
Feb 11, 2011Nimbostratus
Using election hash to load balance memCached
Hi,
I read the old tread http://devcentral.f5.com/Forums/tabid/1082223/asg/50/showtab/groupforums/aff/5/aft/19155/afv/topic/Default.aspx followed by the explanation articles http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/135/Hash-Load-Balancing-and-Persistence-on-BIG-IP-LTM.aspx and http://devcentral.f5.com/wiki/default.aspx/iRules/ElectionHashLoadBalancingAndPersistence.html .
Have anyone done this? I thought I made it to work but, same node do not always win….
My iRule
when RULE_INIT {
set ::mem_debug 1
}
when CLIENT_ACCEPTED {
if {$::mem_debug}{log local0.debug "[IP::remote_addr]:[TCP::remote_port] > [IP::local_addr]:[TCP::local_port] @ [virtual]"}
TCP::collect
}
when CLIENT_DATA {
set S ""
set cdata [TCP::payload]
if {$::mem_debug}{log local0.debug "Client Data: $cdata"}
set key [getfield $cdata " " 2]
if {$::mem_debug}{log local0.debug "Found key: $key"}
foreach N [active_members -list ftest-memCached] {
log local0.debug "Node to be evaluated: $N"
if { [md5 $N$key] > $S } {
set S [md5 $N$key]
set W $N
if {$::mem_debug}{log local0.debug "Node now in lead: $W"}
}
}
if {$::mem_debug}{log local0.debug "Node that won: $W for $key"}
pool ftest-memCached member [lindex $W 0] [lindex $W 1]
TCP::release
TCP::collect
}
Give me this in the log.
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : 10.22.6.101:56779 > 10.22.6.60:11211 @ virt-lab-memCached_SipLblNet
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Client Data: set testKey 0 60 14 testingTesting
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Found key: testKey
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node to be evaluated: 10.22.9.61 11211
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node now in lead: 10.22.9.61 11211
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node to be evaluated: 10.22.9.60 11211
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node that won: 10.22.9.61 11211 for testKey
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : 10.22.6.101:56780 > 10.22.6.60:11211 @ virt-lab-memCached_SipLblNet
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Client Data: get testKey
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Found key: testKey
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node to be evaluated: 10.22.9.61 11211
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node now in lead: 10.22.9.61 11211
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node to be evaluated: 10.22.9.60 11211
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node now in lead: 10.22.9.60 11211
Feb 11 14:17:27 tmm tmm[1711]: Rule ElectionHashForMemCached : Node that won: 10.22.9.60 11211 for testKey
As you see two different node wins even though the key is the same. What do I do wrong?
Thanks Ulf
P.S I'm using 9.4.8 HF4 D.S