]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: vars: remove internal bookkeeping for vars_global_size
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:40:58 +0000 (15:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:45:05 +0000 (15:45 +0200)
Right now we have a per-process max variable size and a per-scope one,
with the proc scope covering all others. As such, the per-process global
one is always exactly equal to the per-proc-scope one. And bookkeeping
on these process-wide variables is extremely expensive (up to 38% CPU
seen in var_accounting_diff() just for them).

Let's kill vars_global_size and only rely on the proc one. Doing this
increased the request rate from 770k to 1.06M in a config having only
12 variables on a 16-thread machine.

src/vars.c

index 0eaa4c9e91dbf37cc0f0951d666194fdc3af1bce..c658f5adf64917a23807b81a3e5f2c90950ea71c 100644 (file)
@@ -28,7 +28,6 @@ struct vars proc_vars THREAD_ALIGNED(64);
 
 /* This array of int contains the system limits per context. */
 static unsigned int var_global_limit = 0;
-static unsigned int var_global_size = 0;
 static unsigned int var_proc_limit = 0;
 static unsigned int var_sess_limit = 0;
 static unsigned int var_txn_limit = 0;
@@ -88,7 +87,6 @@ scope_sess:
                /* fall through */
        case SCOPE_PROC:
                _HA_ATOMIC_ADD(&proc_vars.size, size);
-               _HA_ATOMIC_ADD(&var_global_size, size);
        }
 }
 
@@ -124,9 +122,12 @@ scope_sess:
                        return 0;
                /* fall through */
        case SCOPE_PROC:
+               /* note: scope proc collects all others and is currently identical to the
+                * global limit.
+                */
                if (var_proc_limit && proc_vars.size + size > var_proc_limit)
                        return 0;
-               if (var_global_limit && var_global_size + size > var_global_limit)
+               if (var_global_limit && proc_vars.size + size > var_global_limit)
                        return 0;
        }
        var_accounting_diff(vars, sess, strm, size);
@@ -192,7 +193,6 @@ void vars_prune_per_sess(struct vars *vars)
 
        _HA_ATOMIC_SUB(&vars->size, size);
        _HA_ATOMIC_SUB(&proc_vars.size, size);
-       _HA_ATOMIC_SUB(&var_global_size, size);
 }
 
 /* This function initializes a variables list head */