]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: vars: do not keep variables usage stats if no limit is set
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:51:06 +0000 (15:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:53:07 +0000 (15:53 +0200)
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

index c658f5adf64917a23807b81a3e5f2c90950ea71c..a4c6f4528803457dadac2964a0d677f55cfc7f4e 100644 (file)
@@ -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 */