]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stick-table: store a per-table hash seed and use it
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Nov 2022 17:53:06 +0000 (18:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Nov 2022 17:58:06 +0000 (18:58 +0100)
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.

include/haproxy/stick_table-t.h
src/stick_table.c

index 176771225f46385b5ec48e0b9a7f9e6b29188dff..55267eecbc3dea8eba9487483b80640ab124097f 100644 (file)
@@ -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;
index 85c4a1bb6d10f4702315ae590dda0cfd7fdc8ba8..57c8c15d4797a4e1688f5d96b0ae201eb5f24492 100644 (file)
@@ -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> */
-       buf = get_trash_chunk();
-       memcpy(b_tail(buf), t->id, t->idlen);
-       b_add(buf, t->idlen);
-       /* Copy the key into <buf> */
        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));