From 324f07f6dddcf39d81bbb4e2f5c8445251dc8a95 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 20 Jan 2015 19:44:50 +0100 Subject: [PATCH] MEDIUM: backend: add the crc32 hash algorithm for load balancing 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 | 5 +++++ include/types/backend.h | 1 + src/backend.c | 3 +++ src/cfgparse.c | 8 ++++++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 13f1f724f..cd0172475 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -2794,6 +2794,11 @@ hash-type 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. + indicates an optional method applied after hashing the key : avalanche This directive indicates that the result from the hash diff --git a/include/types/backend.h b/include/types/backend.h index 6325be2bf..446ac2af1 100644 --- a/include/types/backend.h +++ b/include/types/backend.h @@ -115,6 +115,7 @@ #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 */ diff --git a/src/backend.c b/src/backend.c index 35edf7504..721c12ad8 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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: diff --git a/src/cfgparse.c b/src/cfgparse.c index fe5d24ae2..8a5dfe505 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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; }