Forum Discussion
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
- Jeff_43264NimbostratusOne update already, I need to change the first line to use HTTP_REQUEST. When I was writing this, I was confusing this application with another one I've been working on that balances Windows RDP traffic (port 3389). But this rule is absolutely for HTTP traffic.
- hooleylistCirrostratusHi Jeff,
Check if the active_members command returns an entry which can be split on a space into two variables if {[active_members app_http_pool]}{ if {[scan [lindex [active_members –list app_http_pool] [expr {[md5 $tcip_header] % [active_members app_http_pool]}]] {%s %s} ip port] == 2}{ Select the pool member IP and port pool app_http_pool member $ip $port Exit from this event in this rule return } Take some default action if the pool is down or scan didn't parse the output? }
- Jeff_43264NimbostratusAh! I was working under the assumption that I would need a hash persistence profile as described here:
- hooleylistCirrostratusHi Jeff,
- Jeff_43264NimbostratusUnderstood, Aaron. I'm not worried in the short term because the pool will only contain 2 nodes; in that scenario, dropping a node will not effect half of the active users, and the other half will get redistributed to the only other possible node. If we decide to scale up to three or more nodes, I may have to think about using the election style algorithm from the article I linked above.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects