Jeff_43264
May 19, 2010Nimbostratus
Hash persistence based on true-client-IP
Greetings all,
I'm working on my first iRule, because of a unique requirement I have. I am setting up load balancing for a web-based application that is very sensitive to view state, and so persistence of user sessions is essential. The application is being delivered through Akamai, and I had originally set up persistence by injecting a cookie but Akamai is either caching or removing the cookie in some cases, so I'm working on alternatives. Right now, I want to use hash persistence based on the true-client-ip header that Akamai populates.
Here is what I have so far, but I'd like some help sanity-checking the logic and the syntax since the last time I touched TCL was in about 1997. I apologize for excessive commenting, they're for my own sanity:
===================================================
when CLIENT_ACCEPTED {
check for True Client IP header:
if { [HTTP::header exists "True-Client-IP"] } {
chuck the value into a variable
set tcip_header [HTTP::header "True-Client-IP"]
or throw in a default value, if the header isn't there
} else { set tcip_header "1.1.1.1"
}
}
select node by hashing True-client-IP value and pulling that item from the node list from the pool
set picked [lindex [active_members –list app_http_pool ] [expr [md5 [$tcip_header]] % [active_members app_http_pool]]]
send traffic to the selected pool member
pool app_http_pool member [lindex $picked 0] [lindex $picked 1] }
==================================================
Most of the code came from the simple hash example posted here:
http://devcentral.f5.com/Default.aspx?tabid=63&PageID=150&ArticleID=135&articleType=ArticleView
I admit I'm a little baffled by the lindex commands in the last line of functional code. As far as I can tell, the code above that sets the value of $picked to one pool member - namely, the member whose index value in the list of members equals the result of the modulo expression. Why does the example call the pool command with value 0 and value 1 in $picked?
In any case, if the rule above works, I should be able to add the iRule, set up a hash persistence profile for the virtual server and attach the iRule to it, and that will override whatever load balancing algorithm I set on the pool, I believe?
Thanks in advance for all of your help.
Jeff