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.
This commit is contained in:
Willy Tarreau 2021-09-08 15:51:06 +02:00
parent 3b78f2aa5d
commit 55f8a830dc

View File

@ -67,14 +67,15 @@ void var_accounting_diff(struct vars *vars, struct session *sess, struct stream
switch (vars->scope) { switch (vars->scope) {
case SCOPE_REQ: case SCOPE_REQ:
case SCOPE_RES: case SCOPE_RES:
if (strm) if (var_reqres_limit && strm)
_HA_ATOMIC_ADD(&strm->vars_reqres.size, size); _HA_ATOMIC_ADD(&strm->vars_reqres.size, size);
/* fall through */ /* fall through */
case SCOPE_TXN: case SCOPE_TXN:
if (strm) if (var_txn_limit && strm)
_HA_ATOMIC_ADD(&strm->vars_txn.size, size); _HA_ATOMIC_ADD(&strm->vars_txn.size, size);
goto scope_sess; goto scope_sess;
case SCOPE_CHECK: { case SCOPE_CHECK:
if (var_check_limit) {
struct check *check = objt_check(sess->origin); struct check *check = objt_check(sess->origin);
if (check) if (check)
@ -83,9 +84,11 @@ void var_accounting_diff(struct vars *vars, struct session *sess, struct stream
/* fall through */ /* fall through */
scope_sess: scope_sess:
case SCOPE_SESS: case SCOPE_SESS:
if (var_sess_limit)
_HA_ATOMIC_ADD(&sess->vars.size, size); _HA_ATOMIC_ADD(&sess->vars.size, size);
/* fall through */ /* fall through */
case SCOPE_PROC: case SCOPE_PROC:
if (var_proc_limit || var_global_limit)
_HA_ATOMIC_ADD(&proc_vars.size, size); _HA_ATOMIC_ADD(&proc_vars.size, size);
} }
} }
@ -191,7 +194,9 @@ void vars_prune_per_sess(struct vars *vars)
} }
vars_wrunlock(vars); vars_wrunlock(vars);
if (var_sess_limit)
_HA_ATOMIC_SUB(&vars->size, size); _HA_ATOMIC_SUB(&vars->size, size);
if (var_proc_limit || var_global_limit)
_HA_ATOMIC_SUB(&proc_vars.size, size); _HA_ATOMIC_SUB(&proc_vars.size, size);
} }