Forum Discussion
swiss2000_13853
Nimbostratus
Jul 27, 2010Disable Persistence for Fallback Hosts
Hi all
I have a pool with 4 members, in which 2 members act as master servers (priority group 2) and the other 2 members are fallback hosts (priority group 1).
I'd now like to use ...
hoolio
Cirrostratus
Jul 28, 2010Hi Marc,
It's not exactly that you always need an else clause. When you call 'persist none' LTM disables persistence for the rest of the connection or until manually re-enabled using the persist command again. So with the existing iRule, if a client makes one HTTP request and gets sent to the lower priority pool members because all of the higher priority servers are done, persistence will be disabled for the rest of the connection. If they make a subsequent HTTP request on the same TCP connection and the higher priority pool members are again available, the client will be load balanced to the new pool member, but no persistence would be used to ensure they get back to the same pool member on subsequent requests.
Here is an example iRule which demonstrates selectively disabling and re-enabling persistence. I'm using curl to send three HTTP requests on the same TCP connection ('curl -v http://10.10.10.10/test[0-1]' to make requests to /test0, /test1 and /test2). The iRule disables persistence if for the second HTTP request on the TCP connection. For all other requests, it explicitly enables source address persistence.
when HTTP_REQUEST {
Log the URI and the count of HTTP requests on this TCP connection
log local0. " "
log local0. " [IP::client_addr]:[TCP::client_port]: URI: [HTTP::uri], Request: [HTTP::request_num]"
log local0. " [IP::client_addr]:[TCP::client_port]: persist lookup: \"[persist lookup source_addr [IP::client_addr]]\""
Check if this is the second HTTP request on the same TCP connection
if {[HTTP::request_num] == 2}{
Disable persistence for the second HTTP request
log local0. " [IP::client_addr]:[TCP::client_port]: disabling persistence"
persist none
} else {
Enable persistence for all other HTTP requests
log local0. " [IP::client_addr]:[TCP::client_port]: enabling source_addr persistence"
persist source_addr 255.255.255.255 10
}
}
when LB_SELECTED {
Log the selected server. This could differ from the persistence record if we've disables persistence
log local0. " [IP::client_addr]:[TCP::client_port]: selected: [LB::server]"
}
HTTP_REQUEST>:
HTTP_REQUEST>: 10.21.2.2:51912: URI: /test0, Request: 1
HTTP_REQUEST>: 10.21.2.2:51912: persist lookup: ""
HTTP_REQUEST>: 10.21.2.2:51912: enabling source_addr persistence
LB_SELECTED>: 10.21.2.2:51912: selected: hooleya_www1_http_pool 1.1.1.1 80
HTTP_REQUEST>:
HTTP_REQUEST>: 10.21.2.2:51912: URI: /test1, Request: 2
HTTP_REQUEST>: 10.21.2.2:51912: persist lookup: "hooleya_www1_http_pool 1.1.1.1 80"
HTTP_REQUEST>: 10.21.2.2:51912: disabling persistence
LB_SELECTED>: 10.21.2.2:51912: selected: hooleya_www1_http_pool 2.2.2.2 80
HTTP_REQUEST>:
HTTP_REQUEST>: 10.21.2.2:51912: URI: /test2, Request: 3
HTTP_REQUEST>: 10.21.2.2:51912: persist lookup: "hooleya_www1_http_pool 1.1.1.1 80"
HTTP_REQUEST>: 10.21.2.2:51912: enabling source_addr persistence
LB_SELECTED>: 10.21.2.2:51912: selected: hooleya_www1_http_pool 1.1.1.1 80
Also note that I needed to add a OneConnect profile to the VS to get this to work. Wihtout OneConnect, all requests went to the first selected server.
You'll probably want to add a OneConnect profile to the VS to ensure that a load balancing/persistence decision is honored for each HTTP request instead of once per clientside TCP connect. If you're using SNAT you can use the default 0.0.0.0 source mask OneConnect profile. If you're not using SNAT, you should create a custom 255.255.255.255 source mask OneConnect profile to keep the source IP address accurate on serverside connections. See these OneConnect articles for details:
OneConnect wiki page
http://devcentral.f5.com/wiki/default.aspx/AdvDesignConfig/oneconnect.html
OneConnect? For my iRule?
http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=114
Aaron
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