]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stick-tables: Limit the number of old entries we remove
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 2 May 2025 12:05:37 +0000 (12:05 +0000)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 May 2025 13:27:55 +0000 (15:27 +0200)
Limit the number of old entries we remove in one call of
stktable_trash_oldest(), as we do so while holding the heavily contended
update write lock, so we'd rather not hold it for too long.
This helps getting stick tables perform better under heavy load.

src/stick_table.c

index 3be38d82789b0280b7a1529e01241f8c46e3a4e7..e4ac69847453d6e23e4157a29ab67ea56a62f8e9 100644 (file)
@@ -288,8 +288,8 @@ int stktable_trash_oldest(struct stktable *t, int to_batch)
 {
        struct stksess *ts;
        struct eb32_node *eb;
-       int max_search = to_batch * 2; // no more than 50% misses
-       int max_per_shard = (to_batch + CONFIG_HAP_TBL_BUCKETS - 1) / CONFIG_HAP_TBL_BUCKETS;
+       int max_search; // no more than 50% misses
+       int max_per_shard;
        int done_per_shard;
        int batched = 0;
        int updt_locked;
@@ -298,6 +298,12 @@ int stktable_trash_oldest(struct stktable *t, int to_batch)
 
        shard = 0;
 
+       if (to_batch > STKTABLE_MAX_UPDATES_AT_ONCE)
+               to_batch = STKTABLE_MAX_UPDATES_AT_ONCE;
+
+       max_search = to_batch * 2; // no more than 50% misses
+       max_per_shard = (to_batch + CONFIG_HAP_TBL_BUCKETS - 1) / CONFIG_HAP_TBL_BUCKETS;
+
        while (batched < to_batch) {
                done_per_shard = 0;
                looped = 0;