Source Hashing Scheduling

From LVSKB
Jump to: navigation, search

The source hashing scheduling algorithm assigns network connections to the servers through looking up a statically assigned hash table by their source IP addresses.

Maybe, it would be nice to put this in the HOWTO, a lot of people, me too, don't understand why SH seems to lose connections. It's not a bug but a misconfiguration due to a lack of documentation. (The manpage of ipvsadm doesn't mention the following)

But, careful, the weight of a realserver with the SH scheduler means the maximum number of connections, multiplied by 2, allowed on this realserver. The meaning of the weight argument is very different in SH and DH than RR, LC and others.

Just read this thread in lvs-users : Persistence vs SH scheduler. Thanks to Martijn Grendelman to pointing this out.

The sh algorithm is to select server by the hash key of source IP
address. The pseudo code is as follows:

      n <- servernode[src_ip];
      if (n is dead) OR
         (n is overloaded, such as n.conns>2*n.weight) then
                return NULL;

      return n;

Notes that servernode is a 256-bucket hash table that maps the hash
index derived from packet source IP address to the current server
array.