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.
This commit is contained in:
Willy Tarreau 2022-11-28 18:53:06 +01:00
parent 63b5b33ba8
commit 56460ee52a
2 changed files with 5 additions and 9 deletions

View 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;

View 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));