From 3b78f2aa5ded32126fe20093d63d37d39d468e1a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 8 Sep 2021 15:40:58 +0200 Subject: [PATCH] OPTIM: vars: remove internal bookkeeping for vars_global_size 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vars.c b/src/vars.c index 0eaa4c9e9..c658f5adf 100644 --- a/src/vars.c +++ b/src/vars.c @@ -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 */