From: Willy Tarreau Date: Mon, 28 Nov 2022 17:53:06 +0000 (+0100) Subject: MINOR: stick-table: store a per-table hash seed and use it X-Git-Tag: v2.7.0~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=56460ee52a1624bb68717afabb0644b5aec7a88d;p=thirdparty%2Fhaproxy.git MINOR: stick-table: store a per-table hash seed and use it Instead of using memcpy() to concatenate the table's name to the key when allocating an stksess, let's compute once for all a per-table seed at boot time and use it to calculate the key's hash. This saves two memcpy() and the usage of a chunk, it's always nice in a fast path. When tested under extreme conditions with a 80-byte long table name, it showed a 1% performance increase. --- diff --git a/include/haproxy/stick_table-t.h b/include/haproxy/stick_table-t.h index 176771225f..55267eecbc 100644 --- a/include/haproxy/stick_table-t.h +++ b/include/haproxy/stick_table-t.h @@ -174,6 +174,7 @@ struct stktable { pending for sync */ unsigned int refcnt; /* number of local peer over all peers sections attached to this table */ + uint64_t hash_seed; /* hash seed used by shards */ union { struct peers *p; /* sync peers */ char *name; diff --git a/src/stick_table.c b/src/stick_table.c index 85c4a1bb6d..57c8c15d47 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -164,22 +164,14 @@ static unsigned long long stksess_getkey_hash(struct stktable *t, struct stksess *ts, struct stktable_key *key) { - struct buffer *buf; size_t keylen; - /* Copy the stick-table id into */ - buf = get_trash_chunk(); - memcpy(b_tail(buf), t->id, t->idlen); - b_add(buf, t->idlen); - /* Copy the key into */ if (t->type == SMP_T_STR) keylen = key->key_len; else keylen = t->key_size; - memcpy(b_tail(buf), key->key, keylen); - b_add(buf, keylen); - return XXH64(b_head(buf), b_data(buf), 0); + return XXH64(key->key, keylen, t->hash_seed); } /* @@ -733,6 +725,9 @@ out_unlock: int stktable_init(struct stktable *t) { int peers_retval = 0; + + t->hash_seed = XXH64(t->id, t->idlen, 0); + if (t->size) { t->keys = EB_ROOT_UNIQUE; memset(&t->exps, 0, sizeof(t->exps));