Forum Discussion

dragonflymr's avatar
dragonflymr
Icon for Cirrostratus rankCirrostratus
Feb 13, 2015

Hash based persistence - how it works

Hi,

 

I did read every document and discussion about it and still don't get the idea how it works. Probably that is so obvious for pros that nobody cared to explain it in plain English.

 

What I figured out - but maybe I am wrong is:

 

  1. Hash algorithm is used create - quite a discovery :-) - hash from some value passed to it.

     

  2. For given value hash is always the same

     

  3. Hash persistence is most often used to load balance cache or proxy farms

     

  4. From article "The solution is to intelligently load balance requests and 'persist' them to a specific cache not based on who the client is, but based on the content requested"

     

And then I am lost how it's in fact working. My wild guess it's something like that:

 

  1. iRule is used to set value that should be used for first hash

     

  2. Hash is calculated for each pool member based on ip:port or name?

     

  3. Hash from point 1 is combined with pool member hash for each pool member creating "score"

     

  4. In case of ratio is assigned to pool members combined hash (score) for given member is multiplied by ratio value

     

  5. Request is sent to member whit highest score

     

Is above correct?

 

If so assuming that hash for the same value is always identical and hash for given member is as well constant request for given value will always be directed to the same member because always score will be the same and highest for the same member.

 

What will happen when given member is down? Second highest score is winning? Then when member is back I assume that it will again be winning because again its score is highest?

 

I think above will be true as long as both value extracted from request and id of member is the same. When id for member will change persistence will be broken?

 

Again if all above is more or less correct what values from request are most often usefull for real life implementations? Client IP, User-Agent...

 

Piotr

 

5 Replies

  • Hi Piotr,

     

    what you are describing is the CARP option (Cache Array Routing Protocol).

     

    Yes, hash based score will be calculated for each pool member. Highest one wins.

     

    If it goes down, second best will be selected and so on.

     

    With CARP no persistence table will be used. So it scales pretty well if you need to persist i.e. on millions of keys.

     

    But it takes more CPU cycles to calculate.

     

    Traditional hash just calculates a modulus. A change in number of pool members will cause complete redistribution.

     

    CARP based method will result in very little redistribution if a pool members are added or removed.

     

    Thanks, Stephan

     

  • F5's CARP implementation does incorporate the member ratios when calculating the scores. This was introduced relatively recently, maybe around version 11.5.

     

  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus

    F5's CARP implementation does incorporate the member ratios when calculating the scores. This was introduced relatively recently, maybe around version 11.5.