]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: stick-table: calculate the on-wire size of each key
authorWilly Tarreau <w@1wt.eu>
Tue, 29 Sep 2026 14:21:10 +0000 (16:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 29 Sep 2026 15:06:36 +0000 (17:06 +0200)
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.

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

index f1784ba50ec62c409cfa82340a4ca83c31a9efe7..04fa0507277b37250e4cf3a337a5eb584a60ce0e 100644 (file)
@@ -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 */
index bf5e4fc6938ddff2b5bd3846bce15731809a212f..fa9bee4571587a18d50fb9f204f1445ee937a4e0 100644 (file)
@@ -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;
 }