From 55f8a830dc339175767ddc638a06dd377091f84f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 8 Sep 2021 15:51:06 +0200 Subject: [PATCH] OPTIM: vars: do not keep variables usage stats if no limit is set The sole purpose of the variable's usage accounting is to enforce limits at the session or process level, but very commonly these are not set, yet the bookkeeping (especially at the process level) is extremely expensive. Let's simply disable it when the limits are not set. This further increases the performance of 12 variables on 16-thread from 1.06M to 1.24M req/s. --- src/vars.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/vars.c b/src/vars.c index c658f5a..a4c6f45 100644 --- a/src/vars.c +++ b/src/vars.c @@ -67,14 +67,15 @@ void var_accounting_diff(struct vars *vars, struct session *sess, struct stream switch (vars->scope) { case SCOPE_REQ: case SCOPE_RES: - if (strm) + if (var_reqres_limit && strm) _HA_ATOMIC_ADD(&strm->vars_reqres.size, size); /* fall through */ case SCOPE_TXN: - if (strm) + if (var_txn_limit && strm) _HA_ATOMIC_ADD(&strm->vars_txn.size, size); goto scope_sess; - case SCOPE_CHECK: { + case SCOPE_CHECK: + if (var_check_limit) { struct check *check = objt_check(sess->origin); if (check) @@ -83,10 +84,12 @@ void var_accounting_diff(struct vars *vars, struct session *sess, struct stream /* fall through */ scope_sess: case SCOPE_SESS: - _HA_ATOMIC_ADD(&sess->vars.size, size); + if (var_sess_limit) + _HA_ATOMIC_ADD(&sess->vars.size, size); /* fall through */ case SCOPE_PROC: - _HA_ATOMIC_ADD(&proc_vars.size, size); + if (var_proc_limit || var_global_limit) + _HA_ATOMIC_ADD(&proc_vars.size, size); } } @@ -191,8 +194,10 @@ void vars_prune_per_sess(struct vars *vars) } vars_wrunlock(vars); - _HA_ATOMIC_SUB(&vars->size, size); - _HA_ATOMIC_SUB(&proc_vars.size, size); + if (var_sess_limit) + _HA_ATOMIC_SUB(&vars->size, size); + if (var_proc_limit || var_global_limit) + _HA_ATOMIC_SUB(&proc_vars.size, size); } /* This function initializes a variables list head */ -- 1.7.10.4