From: Willy Tarreau Date: Tue, 29 Sep 2026 14:21:10 +0000 (+0200) Subject: MINOR: stick-table: calculate the on-wire size of each key X-Git-Tag: v3.5-dev8~94 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=8582635915d48966746cb3a7810771488a0eb9bb;p=haproxy.git MINOR: stick-table: calculate the on-wire size of each key In stick_table->proto_size, we now store the estimated worse case for the size of a key sent over the wire with all of its stored data. This includes the key itself when it's fixed, the upper bound for stored data, and some overhead (11 bytes measured). It will be used by next commit. --- diff --git a/include/haproxy/stick_table-t.h b/include/haproxy/stick_table-t.h index f1784ba50..04fa05072 100644 --- a/include/haproxy/stick_table-t.h +++ b/include/haproxy/stick_table-t.h @@ -189,6 +189,7 @@ struct stktable { unsigned int size; /* maximum number of sticky sessions in table */ int expire; /* time to live for sticky sessions (milliseconds) */ int data_size; /* the size of the data that is prepended *before* stksess */ + int proto_size; /* the rough size of the data+fixed key over the peers protocol */ int data_ofs[STKTABLE_DATA_TYPES]; /* negative offsets of present data types, or 0 if absent */ unsigned int data_nbelem[STKTABLE_DATA_TYPES]; /* to store nb_elem in case of array types */ unsigned int brates_factor; /* Factor used for IN/OUT bytes rates */ diff --git a/src/stick_table.c b/src/stick_table.c index bf5e4fc69..fa9bee457 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -1385,6 +1385,7 @@ int stktable_alloc_data_type(struct stktable *t, int type, const char *sa, const } t->data_size += t->data_nbelem[type] * stktable_type_size(stktable_data_types[type].std_type); + t->proto_size += t->data_nbelem[type] * stktable_type_proto_size(stktable_data_types[type].std_type); t->data_ofs[type] = -t->data_size; return PE_NONE; } @@ -1679,6 +1680,13 @@ int parse_stick_table(const char *file, int linenum, char **args, goto out; } + /* the key is sent as-is for most types (string is trimmed), and 11 + * extra bytes of encapsulation are added when sending (measured). + */ + t->proto_size += 11; + if (t->type != SMP_T_STR) + t->proto_size += t->key_size; + out: return err_code; }