Jump to content
Welcome to our new Citrix community!

Rule based persistance question

Recommended Posts

Hi all,

I´m  using Citrix ADM 13.0.67. I want to set persistece on a service based on x-user-id  http header but only when there isn´t another header present: The expression to filter the traffic would be something like this:


(HTTP.REQ.HEADER("x-client-id").CONTAINS("somestring").NOT) && (HTTP.REQ.HEADER("x-user-id").EXISTS)


To create the response expression in the persistence rule, the value considered is a field in the server´s response. In my case I guess it would be HTTP.RES.HEADER("x-user-id"), but my doubt is, how the load balancer sets persistence based on this value? it checks for the requests' headers that matches the values selected in the previous expression?


Thanks in advance!




Link to comment
Share on other sites

I think you would want to use content switching.

cs pol 1:  If header is present, send to lb_vsrv_A with the rule-based persistence.

cs pol 2: If header is not present, send to lb_vsrv_B with the no persistence value.


But you switch from request to response.  And the persistence would have to be set/based on a request time header.

OR we might need to use the server id string as well.






Link to comment
Share on other sites

Thanks Rhonda for your suggestion.

But maybe I'm not getting how persistence rule works.

If I set the "expression" field in the persistence rule configuration as follows:  HTTP.REQ.HEADER("MyHeader"), the load balancer will create a different persistence session for every value it receives in "MyHeader"?

And if I set a condition, something like HTTP.REQ.HEADER("MyHeader").EXISTS, it will send all the traffic that has  "MyHeader" to the same service?


Thanks again!

Link to comment
Share on other sites

You originally mentioned, you only wanted to track persistence if a certain header is present. If I misinterpreted what you meant, than content switching isn't needed.


Regular persistence, such as sourceip:

request comes from IP1 and when the first lb decision is made, system remembers IP1. Next request from IP1 is sent to same persistent destination as first request.

Next request comes from IP2 which does not match IP1 and so a new load balancing persistence decision is made. 


When using Rule based persistence, you usually look for a value to base persistence on that is present in every request.

So, if we look at http.req.header("myheader") for rule based persistence:

Request 1 with value1 will be sent to a lb destnation and persistence will be based on value1 of header.

Request 2 with value1 will follow request1 because of matching persistence.

Request 3 with value2 will be a new lb decision with new persistence for new value of header.


You wouldn't use the .exists header in persistence rule at all.

https://docs.citrix.com/en-us/citrix-adc/current-release/load-balancing/load-balancing-persistence/rule-persistence.html#:~:text=When rule based persistence is,rule to the same service.


IF the header isn't present, then backup persistence method is used, which is either NONE (no persistence until a header is present) OR alternate persistence method.


If only some of your traffic will have the header and the backup persistence alone isn't sufficient, then content switching would allow for two separate lb persistence decisions. Backup persistence should be enough.


Therefore your rule should be:


only  (and not header exists and not header contains one value, usually)

And then specify appropriate backup persistence if header isn't present. None or other.


If you want to sort traffic based on a specific header present, then that's not usually persistence but content switching depending on the exact details of what you are doing.


Does this help at all?






Link to comment
Share on other sites

Thanks Rhonda, that was a great explanation!

You didn´t misunderstood, I need to do CS, but I used the one header example just to understand how rule based persistance works (I will need it to define the CS pol1)


My confusion comes from the very link you sent to me, they don´t use the EXIST command but the CONTAINS (HTTP.REQ.HEADER(“User-Agent”).CONTAINS (“MyBrowser”))



Link to comment
Share on other sites

Well, that kind of confused me to. I was just using the link for the backup persistence example to be honest :)

But I *think* that example was more about syntax and not a persistence example at the bottom.  Because otherwise all values "MyBrowser" are then sent the same way...which is not what we want.


Usually, lb method and persistence are related in this case, so token-based load balancing with rule based persistence.

If your traffic without the header is not being handled correctly, we can look at adjustments.  Do the transactions without the header, never have the header or only get it later in the transaction flow?


High level:


Option 1: Without content switching:

1x load balancing vserver, with lb method (token or other) and persistence set to rule-based with http.req.header("<customerheader>"); backup persistence set to none (if not needed when header is missing OR set to sourceip or other mechanism if it is needed.)


Option 2: With content switching:

lb_vsrv_1:  lbmethod: token or <Other> and persistence: rule: http.req.header("<customerheader>")  (and none for backup persistence)

lb_vsrv_2: lbmethod: other / persistence: none or alternate method when header is missing


cs_vserver_demo on VIP:Protocol:Port

cs_pol_wHeader:  http.req.header("<customheader>").exists

Default destination: lb_vsrv_2


NOTE:  Depending on traffic you will likely want the content switching vserver persistence setting off too. 


IF this doesn't do what you want we might also need a server id setting at the service/service member level. 

Might need to take a step back to understand the traffic scenarios and see if there's a better way to address it if you end up with issues with either of these implementations.



Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...