]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: backend: add the crc32 hash algorithm for load balancing
authorWilly Tarreau <w@1wt.eu>
Tue, 20 Jan 2015 18:44:50 +0000 (19:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 20 Jan 2015 18:48:14 +0000 (19:48 +0100)
Since we have it available, let's make it usable for load balancing,
it comes at no cost except 3 lines of documentation.

doc/configuration.txt
include/types/backend.h
src/backend.c
src/cfgparse.c

index 13f1f724f90e0594cd5fad3177c07e99bf463212..cd0172475961fb02468857c4584597fb75dd355b 100644 (file)
@@ -2794,6 +2794,11 @@ hash-type <method> <function> <modifier>
               data such as a source IP address or a visitor identifier in a URL
               parameter.
 
+       crc32  this is the most common CRC32 implementation as used in Ethernet,
+              gzip, PNG, etc. It is slower than the other ones but may provide
+              a better distribution or less predictable results especially when
+              used on strings.
+
     <modifier> indicates an optional method applied after hashing the key :
 
        avalanche   This directive indicates that the result from the hash
index 6325be2bf4445421aff9c4f6a90261db161ff167..446ac2af13dc949d356a9ee91f7e0a878e5c99c5 100644 (file)
 #define BE_LB_HFCN_SDBM   0x000000 /* sdbm hash */
 #define BE_LB_HFCN_DJB2   0x400000 /* djb2 hash */
 #define BE_LB_HFCN_WT6    0x800000 /* wt6 hash */
+#define BE_LB_HFCN_CRC32  0xC00000 /* crc32 hash */
 #define BE_LB_HASH_FUNC   0xC00000 /* get/clear hash function */
 
 
index 35edf75041422d680941d96447b4ff18d448fcec..721c12ad8332d9c12d6e88fc181a6ca73ebdf953 100644 (file)
@@ -75,6 +75,9 @@ static unsigned int gen_hash(const struct proxy* px, const char* key, unsigned l
        case BE_LB_HFCN_WT6:
                hash = hash_wt6(key, len);
                break;
+       case BE_LB_HFCN_CRC32:
+               hash = hash_crc32(key, len);
+               break;
        case BE_LB_HFCN_SDBM:
                /* this is the default hash function */
        default:
index fe5d24ae2f5c724796a695b407d291c848ccd431..8a5dfe505f3c5aff52dcac7f48d5144166a521b7 100644 (file)
@@ -4835,11 +4835,15 @@ stats_error_parsing:
                        }
                        else if (!strcmp(args[2], "djb2")) {
                                curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
-                       } else if (!strcmp(args[2], "wt6")) {
+                       }
+                       else if (!strcmp(args[2], "wt6")) {
                                curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
                        }
+                       else if (!strcmp(args[2], "crc32")) {
+                               curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
+                       }
                        else {
-                               Alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2' or 'wt6' hash functions.\n", file, linenum, args[0]);
+                               Alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
                                err_code |= ERR_ALERT | ERR_FATAL;
                                goto out;
                        }